Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions
CByteImage Class Reference

Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images using the data type unsigned char. More...

#include <ByteImage.h>

List of all members.

Classes

struct  myBITMAPFILEHEADER
struct  myBITMAPINFOHEADER

Public Types

enum  ImageType { eGrayScale, eRGB24, eRGB24Split }
 Enum specifying the supported image types. More...

Public Member Functions

 CByteImage ()
 The default constructor.
 CByteImage (int nImageWidth, int nImageHeight, ImageType imageType, bool bHeaderOnly=false)
 Constructor for creating an image of a specific size and type.
 CByteImage (const CByteImage *pImage, bool bHeaderOnly=false)
 Constructor for creating an image given a pointer to a CByteImage.
 CByteImage (const CByteImage &image, bool bHeaderOnly=false)
 Copy constructor.
bool IsCompatible (const CByteImage *pImage) const
 Checks whether two images are compatible or not.
bool LoadFromFile (const char *pFileName)
 Loads an image from a file.
bool SaveToFile (const char *pFileName) const
 Saves an image to a file.
void Set (int nImageWidth, int nImageHeight, ImageType imageType, bool bHeaderOnly=false)
 Changes size and type of an image.
 ~CByteImage ()
 The destructor.

Public Attributes

int bytesPerPixel
 The number of bytes used for encoding one pixel.
int height
 The height of the image in pixels.
bool m_bOwnMemory
 Flag signaling if memory is to be freed or not.
unsigned char * pixels
 The pointer to the the pixels.
ImageType type
 The type of the image.
int width
 The width of the image in pixels.

Private Member Functions

void FreeMemory ()
bool LoadFromFileBMP (const char *pFileName)
bool LoadFromFilePNM (const char *pFileName)
bool SaveToFileBMP (const char *pFileName) const
bool SaveToFilePNM (const char *pFileName) const

Detailed Description

Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images using the data type unsigned char.

CByteImage is the central class for the representation of grayscale and color images.

Images of type CByteImage can be directly loaded from or stored to files and visualized in GUIs. The image data is represented as a linear array of pixels, always starting from the top left corner and stored row wise.

In the case of grayscale images (CByteImage::eGraySclae), the grayscale value of each pixel is encoded in one byte (0: black, 255: white, nuances in between). In the case of 24-bit color images the color information of each pixel is encoded in three bytes (first: red, second: green, third: blue).

For 24-bit color images two variants are available: CByteImage::eRGB24 and CByteImage::eRGB24Split, the first encoding the three components of an RGB triple in three consecutive bytes, the latter encoding the three components in three separate channels (the first starting at CByteImage::pixels, the second at CByteImage::pixels + CByteImage::width * CByteImage::height, and the third starting at CByteImage::pixels + 2 * CByteImage::width * CByteImage::height.

Definition at line 80 of file ByteImage.h.


Member Enumeration Documentation

Enum specifying the supported image types.

Enumerator:
eGrayScale 

In the case of grayscale images the grayscale value of each pixel is encoded in one byte (0: black, 255: white).

eRGB24 

Each pixel is encoded in three consecutive bytes (first: red, second: green, third: blue).

eRGB24Split 

The RGB color information is storted in three separate channels (the first starting at CByteImage::pixels, the second at CByteImage::pixels + CByteImage::width * CByteImage::height, and the third starting atCByteImage:: pixels + 2 * CByteImage::width * CByteImage::height.

Definition at line 86 of file ByteImage.h.


Constructor & Destructor Documentation

The default constructor.

The default constructor sets all member variables to zero, i.e. after construction no valid image is represented.

This constructor is useful in case an image is to be loaded from a file at a later point, e.g. with the method LoadFromFile(const char *).

Definition at line 80 of file ByteImage.cpp.

CByteImage::CByteImage ( int  nImageWidth,
int  nImageHeight,
ImageType  imageType,
bool  bHeaderOnly = false 
)

Constructor for creating an image of a specific size and type.

With this constructor, an instance of CByteImage is created, given the desired image resolution and image type. The contents of the image are not initialized, i.e. are undefined after creation.

Parameters:
[in]nImageWidthThe desired width of the image in pixels. Must be > 0.
[in]nImageHeightThe desired height of the image in pixels. Must be > 0.
[in]imageTypeThe desired type of the image. See ImageType for further information.
[in]bHeaderOnlyIf set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case.

Definition at line 90 of file ByteImage.cpp.

CByteImage::CByteImage ( const CByteImage pImage,
bool  bHeaderOnly = false 
)

Constructor for creating an image given a pointer to a CByteImage.

This constructor creates a new instance with the same properties as the image provided by the parameter 'pImage'. Note that the contents of the image are not copied. Use ImageProcessor::CopyImage(const CByteImage*, CByteImage*, const MyRegion*, bool) for copying image contents.

Parameters:
[in]pImageThe template image.
[in]bHeaderOnlyIf set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case.

Definition at line 139 of file ByteImage.cpp.

CByteImage::CByteImage ( const CByteImage image,
bool  bHeaderOnly = false 
)

Copy constructor.

This copy constructor creates a new instance with the same properties as the image provided by the parameter 'image'. Note that the contents of the image are not copied. Use ImageProcessor::CopyImage(const CByteImage*, CByteImage*, const MyRegion*, bool) for copying image contents.

Parameters:
[in]imageThe template image.
[in]bHeaderOnlyIf set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case.

Definition at line 120 of file ByteImage.cpp.

The destructor.

Definition at line 158 of file ByteImage.cpp.


Member Function Documentation

Definition at line 200 of file ByteImage.cpp.

bool CByteImage::IsCompatible ( const CByteImage pImage) const

Checks whether two images are compatible or not.

Parameters:
[in]pImagePointer to the image to be checked compatibility with.
Returns:
true if the attributes width, height and type are equal, otherwise returns false.

Definition at line 212 of file ByteImage.cpp.

bool CByteImage::LoadFromFile ( const char *  pFileName)

Loads an image from a file.

Loads an image from a BMP, PGM, or PPM file. The image type is recognized by the file name ending (.bmp, .pgm, .ppm or .BMP, .PGM, .PPM).

If an image is already loaded, reinitialization is performed automatically.

Parameters:
[in]pFileNameThe path to the image file to be loaded.
Returns:
true on success and false on failure.

Definition at line 232 of file ByteImage.cpp.

bool CByteImage::LoadFromFileBMP ( const char *  pFileName) [private]

Definition at line 255 of file ByteImage.cpp.

bool CByteImage::LoadFromFilePNM ( const char *  pFileName) [private]

Definition at line 810 of file ByteImage.cpp.

bool CByteImage::SaveToFile ( const char *  pFileName) const

Saves an image to a file.

Saves the current image to a BMP, PGM, or PPM file. The desired image type is recognized by the file name ending (.bmp, .pgm, .ppm or .BMP, .PGM, .PPM).

Be careful to provide the correct file ending for PGM/PPM files: .PGM for grayscale images or .PPM for RGB images.

Parameters:
[in]pFileNameThe path to the destination file.
Returns:
true on success and false on failure.

Definition at line 243 of file ByteImage.cpp.

bool CByteImage::SaveToFileBMP ( const char *  pFileName) const [private]

Definition at line 600 of file ByteImage.cpp.

bool CByteImage::SaveToFilePNM ( const char *  pFileName) const [private]

Definition at line 933 of file ByteImage.cpp.

void CByteImage::Set ( int  nImageWidth,
int  nImageHeight,
ImageType  imageType,
bool  bHeaderOnly = false 
)

Changes size and type of an image.

With this method, an existing instance of CByteImage is changed, given the desired image resolution and image type. The contents of the image are not initialized after calling this method, i.e. are undefined.

Parameters:
[in]nImageWidthThe desired width of the image in pixels. Must be > 0.
[in]nImageHeightThe desired height of the image in pixels. Must be > 0.
[in]imageTypeThe desired type of the image. See ImageType for further information.
[in]bHeaderOnlyIf set to false (default value), memory is allocated for the pixels. If set to true, no memory is allocated for the pixels. The latter can be useful for assigning image data from other sources (see e.g. implementation of ImageAccessCV::LoadFromFile). Note that if bHeaderOnly is set to true, the member variable CByteImage::m_bOwnMemory is set to false so that memory assigned to the member variable CByteImage::pixels is not freed throughout re-initialization/destruction, i.e. freeing memory must be handled by the caller in this case.

Definition at line 168 of file ByteImage.cpp.


Member Data Documentation

The number of bytes used for encoding one pixel.

This information is redundant with the member type (ImageType::eGrayScale => 1; ImageType::eRGB24, ImageType::eRGB24Split => 3).

This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 273 of file ByteImage.h.

The height of the image in pixels.

This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 264 of file ByteImage.h.

Flag signaling if memory is to be freed or not.

This flag signals whether the image memory must be freed throughut re-initiallization/destruction or not.

This flag is usually for internal use only. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 301 of file ByteImage.h.

unsigned char* CByteImage::pixels

The pointer to the the pixels.

This is the pointer pointing to the memory area containing the pixels of the image, starting from the top left corner and stored row wise (see above for type dependent information).

This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 283 of file ByteImage.h.

The type of the image.

The type of the image specifies its encoding. See above for type dependent information.

This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 292 of file ByteImage.h.

The width of the image in pixels.

Padding is not implemented (on purpose).

This variable should only be read. It should only be modified by external image loaders (e.g. ImageAccessCV::LoadFromFile).

Definition at line 257 of file ByteImage.h.


The documentation for this class was generated from the following files:


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58