Main MRPT website > C++ reference
MRPT logo
Static Public Attributes | Protected Member Functions

mrpt::utils::CImage Class Reference


Detailed Description

A class for storing images as grayscale or RGB bitmaps.

File I/O is supported in two different ways:

How to create color/grayscale images:

    CImage  img1(width, height,  CH_GRAY );  // Grayscale image (8U1C)
    CImage  img2(width, height,  CH_RGB );  // RGB image (8U3C)

Additional notes:

For many computer vision functions that use CImage as its image data type, see mrpt::vision.

Note:
This class acts as a wrapper class to a small subset of OpenCV functions. IplImage is the internal storage structure.
See also:
mrpt::vision, mrpt::vision::CFeatureExtractor, CSerializable, CCanvas

Definition at line 108 of file CImage.h.

#include <mrpt/utils/CImage.h>

Inheritance diagram for mrpt::utils::CImage:
Inheritance graph
[legend]

List of all members.

Public Member Functions

Constructors & destructor
 CImage ()
 Default constructor: initialize an 1x1 RGB image.
 CImage (unsigned int width, unsigned int height, TImageChannels nChannels=CH_RGB, bool originTopLeft=true)
 Constructor for a given image size and type.
 CImage (const CImage &o)
 Copy constructor, makes a full copy of the original image contents (unless it was externally stored, in that case, this new image will just point to the same image file).
 CImage (TConstructorFlags_CImage constructor_flag)
 Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL).
 CImage (const CImage &other_img, TConstructorFlags_CImage constructor_flag)
 Fast constructor of a grayscale version of another image, making a reference to the original image if it already was in grayscale, or otherwise creating a new grayscale image and converting the original image into it.
 CImage (void *iplImage)
 Constructor from an IPLImage*, making a copy of the image.
template<typename Derived >
 CImage (const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized)
 Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false)
virtual ~CImage ()
 Destructor:
Manipulate the image contents or size, various computer-vision methods (image filters, undistortion, etc.)
void resize (unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
 Changes the size of the image, erasing previous contents (does NOT scale its current content, for that, see scaleImage).
void scaleImage (unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
 Scales this image to a new size, interpolating as needed.
void scaleImage (CImage &out_img, unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC) const
 Scales this image to a new size, interpolating as needed, saving the new image in a different output object.
void rotateImage (double angle_radians, unsigned int center_x, unsigned int center_y, double scale=1.0)
 Rotates the image by the given angle around the given center point, with an optional scale factor.
void setPixel (int x, int y, size_t color)
 Changes the value of the pixel (x,y).
void setOriginTopLeft (bool val)
 Changes the property of the image stating if the top-left corner (vs.
virtual void line (int x0, int y0, int x1, int y1, const mrpt::utils::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid)
 Draws a line.
void drawCircle (int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1)
 Draws a circle of a given radius.
void equalizeHistInPlace ()
 Equalize the image histogram, replacing the original image.
void equalizeHist (CImage &outImg) const
 Equalize the image histogram, saving the new image in the given output object.
CImage scaleHalf () const
 Returns a new image scaled down to half its original size.
CImage scaleDouble () const
 Returns a new image scaled up to double its original size.
void update_patch (const CImage &patch, const unsigned int col, const unsigned int row)
 Update a part of this image with the "patch" given as argument.
void extract_patch (CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const
 Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten).
float correlate (const CImage &img2int, int width_init=0, int height_init=0) const
 Computes the correlation coefficient (returned as val), between two images This function use grayscale images only img1, img2 must be same size (by AJOGD @ DEC-2006)
void cross_correlation (const CImage &patch_img, size_t &u_max, size_t &v_max, double &max_val, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, CImage *out_corr_image=NULL) const
 Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate.
void cross_correlation_FFT (const CImage &in_img, math::CMatrixFloat &out_corr, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, float biasThisImg=0, float biasInImg=0) const
 Computes the correlation matrix between this image and another one.
void normalize ()
 Optimize de brightness range of a image without using histogram Only for one channel images.
void flipVertical (bool also_swapRB=false)
 Flips vertically the image.
void swapRB ()
 Swaps red and blue channels.
void rectifyImage (CImage &out_img, const mrpt::utils::TCamera &cameraParams) const
 Rectify (un-distort) the image according to some camera parameters, and returns an output un-distorted image.
void rectifyImage (CImage &out_img, const math::CMatrixDouble33 &cameraMatrix, const vector_double &distCoeff) const
 Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.
void rectifyImageInPlace (const mrpt::utils::TCamera &cameraParams)
 Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.
void rectifyImageInPlace (const math::CMatrixDouble33 &cameraMatrix, const vector_double &distCoeff)
 Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.
void rectifyImageInPlace (void *mapX, void *mapY)
 Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed rectification maps.
void filterMedian (CImage &out_img, int W=3) const
 Filter the image with a Median filter with a window size WxW, returning the filtered image in out_img.
void filterMedianInPlace (int W=3)
 Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered one.
void filterGaussianInPlace (int W=3, int H=3)
 Filter the image with a Gaussian filter with a window size WxH, returning the filtered image in out_img.
void filterGaussian (CImage &out_img, int W=3, int H=3) const
 Filter the image with a Gaussian filter with a window size WxH, replacing "this" image by the filtered one.
bool drawChessboardCorners (std::vector< TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y)
 Draw onto this image the detected corners of a chessboard.
void joinImagesHorz (const CImage &im1, const CImage &im2)
 Joins two images side-by-side horizontally.
float KLT_response (const unsigned int x, const unsigned int y, const unsigned int half_window_size) const
 Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids converting to grayscale internally).
Copy, move & swap operations
CImageoperator= (const CImage &o)
 Copy operator (if the image is externally stored, the writen image will be such as well).
void copyFromForceLoad (const CImage &o)
 Copies from another image, and, if that one is externally stored, the image file will be actually loaded into memory in "this" object.
void copyFastFrom (CImage &o)
 Moves an image from another object, erasing the origin image in the process (this is much faster than copying)
void swap (CImage &o)
 Very efficient swap of two images (just swap the internal pointers)
Access to image contents (IplImage structure and raw pixels).
template<typename T >
const T * getAs () const
 Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
template<typename T >
T * getAs ()
 Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
void * getAsIplImage () const
 Returns a pointer to an OpenCV's IplImage struct containing the image, which is linked to this class: free neigther that pointer nor this class until they are not required anymore, since this class is in charge of freeing the memory buffers inside of the returned image.
unsigned char * get_unsafe (unsigned int col, unsigned int row, unsigned int channel=0) const
 Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates.
float getAsFloat (unsigned int col, unsigned int row, unsigned int channel) const
 Returns the contents of a given pixel at the desired channel, in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.
float getAsFloat (unsigned int col, unsigned int row) const
 Returns the contents of a given pixel (for gray-scale images, in color images the gray scale equivalent is computed for the pixel), in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.
unsigned char * operator() (unsigned int col, unsigned int row, unsigned int channel=0) const
 Returns a pointer to a given pixel information.
Query image properties
size_t getWidth () const
 Returns the width of the image in pixels.
size_t getHeight () const
 Returns the height of the image in pixels.
void getSize (TImageSize &s) const
 Return the size of the image.
TImageSize getSize () const
 Return the size of the image.
float getMaxAsFloat () const
 Return the maximum pixel value of the image, as a float value in the range [0,1].
bool isColor () const
 Returns true if the image is RGB, false if it is grayscale.
bool isOriginTopLeft () const
 Returns true if the coordinates origin is top-left, or false if it is bottom-left.
const char * getChannelsOrder () const
 Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
TImageChannels getChannelCount () const
 Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
void getAsMatrix (mrpt::math::CMatrixFloat &outMatrix, bool doResize=true, int x_min=0, int y_min=0, int x_max=-1, int y_max=-1) const
 Returns the image as a matrix with pixel grayscale values in the range [0,1].
void getAsMatrixTiled (math::CMatrix &outMatrix) const
 Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to fill the entire size of the matrix on input.
Set, load & save methods
void loadFromMemoryBuffer (unsigned int width, unsigned int height, bool color, unsigned char *rawpixels, bool swapRedBlue=false)
 Reads the image from raw pixels buffer in memory.
void loadFromMemoryBuffer (unsigned int width, unsigned int height, unsigned int bytesPerRow, unsigned char *red, unsigned char *green, unsigned char *blue)
 Reads a color image from three raw pixels buffers in memory.
void loadFromIplImage (void *iplImage)
 Reads the image from a OpenCV IplImage object (making a COPY).
void setFromIplImage (void *iplImage)
 Reads the image from a OpenCV IplImage object (WITHOUT making a copy).
void setFromIplImageReadOnly (void *iplImage)
 Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image cannot be modified, just read.
void setFromImageReadOnly (const CImage &other_img)
 Sets the internal IplImage pointer to that of another given image, WITHOUT making a copy, and from now on the image cannot be modified in this object (it will be neither freed, so the memory responsibility will still be of the original image object).
template<typename Derived >
void setFromMatrix (const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized=true)
 Set the image from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false)
void loadFromStreamAsJPEG (CStream &in)
 Reads the image from a binary stream containing a binary jpeg file.
bool loadFromFile (const std::string &fileName, int isColor=-1)
 Load image from a file, whose format is determined from the extension (internally uses OpenCV).
bool saveToFile (const std::string &fileName, int jpeg_quality=95) const
 Save the image to a file, whose format is determined from the extension (internally uses OpenCV).
void saveToStreamAsJPEG (CStream &out) const
 Save image to binary stream as a JPEG (.jpg) compresed format.
Color/Grayscale conversion
CImage grayscale () const
 Returns a grayscale version of the image, or itself if it is already a grayscale image.
void grayscale (CImage &ret) const
 Returns a grayscale version of the image, or itself if it is already a grayscale image.
void colorImage (CImage &ret) const
 Returns a RGB version of the grayscale image, or itself if it is already a RGB image.
void colorImageInPlace ()
 Replaces this grayscale image with a RGB version of it.
void grayscaleInPlace ()
 Replaces the image with a grayscale version of it.

Static Public Attributes

static bool DISABLE_ZIP_COMPRESSION
 By default, when storing images through the CSerializable interface, grayscale images will be ZIP compressed if they are larger than 16Kb: this flag can be turn on to disable ZIP compression and gain speed versus occupied space.

Protected Member Functions

void changeSize (unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
 Resize the buffers in "img" to accomodate a new image size and/or format.
void releaseIpl (bool thisIsExternalImgUnload=false) MRPT_NO_THROWS
 Release the internal IPL image, if not NULL or read-only.
void makeSureImageIsLoaded () const throw (std::exception,utils::CExceptionExternalImageNotFound )
 Checks if the image is of type "external storage", and if so and not loaded yet, load it.

Protected Attributes

Data members
void * img
 The internal IplImage pointer to the actual image content.
bool m_imgIsReadOnly
 Set to true only when using setFromIplImageReadOnly.
bool m_imgIsExternalStorage
 Set to true only when using setExternalStorage.
std::string m_externalFile
 The file name of a external storage image.

RTTI stuff

typedef CImagePtr SmartPtr
static mrpt::utils::CLASSINIT _init_CImage
static mrpt::utils::TRuntimeClassId classCImage
static const
mrpt::utils::TRuntimeClassId
classinfo
static const
mrpt::utils::TRuntimeClassId
_GetBaseClass ()
virtual const
mrpt::utils::TRuntimeClassId
GetRuntimeClass () const
 Returns information about the class of an object in runtime.
virtual mrpt::utils::CObjectduplicate () const
 Returns a copy of the object, indepently of its class.
static mrpt::utils::CObjectCreateObject ()
static CImagePtr Create ()

External storage-mode methods

static std::string IMAGES_PATH_BASE
 By default, ".".
void setExternalStorage (const std::string &fileName) MRPT_NO_THROWS
 By using this method the image is marked as referenced to an external file, which will be loaded only under demand.
bool isExternallyStored () const MRPT_NO_THROWS
 See setExternalStorage().
std::string getExternalStorageFile () const MRPT_NO_THROWS
 < Only if isExternallyStored() returns true.
void getExternalStorageFileAbsolutePath (std::string &out_path) const
 Only if isExternallyStored() returns true.
std::string getExternalStorageFileAbsolutePath () const
 Only if isExternallyStored() returns true.
void forceLoad ()
 For external storage image objects only, this method makes sure the image is loaded in memory.
void unload () MRPT_NO_THROWS
 For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded).

Member Typedef Documentation

A typedef for the associated smart pointer

Definition at line 110 of file CImage.h.


Constructor & Destructor Documentation

mrpt::utils::CImage::CImage (  )

Default constructor: initialize an 1x1 RGB image.

mrpt::utils::CImage::CImage ( unsigned int  width,
unsigned int  height,
TImageChannels  nChannels = CH_RGB,
bool  originTopLeft = true 
)

Constructor for a given image size and type.

Examples:

    CImage  img1(width, height,  CH_GRAY );  // Grayscale image (8U1C)
    CImage  img2(width, height,  CH_RGB );  // RGB image (8U3C)
mrpt::utils::CImage::CImage ( const CImage o )

Copy constructor, makes a full copy of the original image contents (unless it was externally stored, in that case, this new image will just point to the same image file).

mrpt::utils::CImage::CImage ( TConstructorFlags_CImage  constructor_flag ) [inline]

Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL).

Use only when you know the image will be soon be assigned another image. Example of usage:

Definition at line 143 of file CImage.h.

mrpt::utils::CImage::CImage ( const CImage other_img,
TConstructorFlags_CImage  constructor_flag 
) [inline]

Fast constructor of a grayscale version of another image, making a reference to the original image if it already was in grayscale, or otherwise creating a new grayscale image and converting the original image into it.

It's very important to keep in mind that the original image can't be destroyed before the new object being created with this constructor. Example of usage:

     void my_func(const CImage &in_img) {
        const CImage gray_img(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
        // We can now operate on "gray_img" being sure it's in grayscale.
     }

Definition at line 156 of file CImage.h.

References grayscale(), and isColor().

mrpt::utils::CImage::CImage ( void *  iplImage )

Constructor from an IPLImage*, making a copy of the image.

See also:
loadFromIplImage, setFromIplImage
template<typename Derived >
mrpt::utils::CImage::CImage ( const Eigen::MatrixBase< Derived > &  m,
bool  matrix_is_normalized 
) [inline, explicit]

Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false)

See also:
setFromMatrix

Definition at line 171 of file CImage.h.

virtual mrpt::utils::CImage::~CImage (  ) [virtual]

Destructor:


Member Function Documentation

static const mrpt::utils::TRuntimeClassId* mrpt::utils::CImage::_GetBaseClass (  ) [static, protected]

Reimplemented from mrpt::utils::CSerializable.

void mrpt::utils::CImage::changeSize ( unsigned int  width,
unsigned int  height,
TImageChannels  nChannels,
bool  originTopLeft 
) [protected]

Resize the buffers in "img" to accomodate a new image size and/or format.

void mrpt::utils::CImage::colorImage ( CImage ret ) const

Returns a RGB version of the grayscale image, or itself if it is already a RGB image.

See also:
grayscale

Referenced by mrpt::gui::CDisplayWindow::showImageAndPoints(), and mrpt::gui::CDisplayWindow::showTiledImageAndPoints().

void mrpt::utils::CImage::colorImageInPlace (  )

Replaces this grayscale image with a RGB version of it.

See also:
grayscaleInPlace
void mrpt::utils::CImage::copyFastFrom ( CImage o )

Moves an image from another object, erasing the origin image in the process (this is much faster than copying)

See also:
operator =
void mrpt::utils::CImage::copyFromForceLoad ( const CImage o )

Copies from another image, and, if that one is externally stored, the image file will be actually loaded into memory in "this" object.

See also:
operator =
float mrpt::utils::CImage::correlate ( const CImage img2int,
int  width_init = 0,
int  height_init = 0 
) const

Computes the correlation coefficient (returned as val), between two images This function use grayscale images only img1, img2 must be same size (by AJOGD @ DEC-2006)

static CImagePtr mrpt::utils::CImage::Create (  ) [static]
static mrpt::utils::CObject* mrpt::utils::CImage::CreateObject (  ) [static]
void mrpt::utils::CImage::cross_correlation ( const CImage patch_img,
size_t &  u_max,
size_t &  v_max,
double &  max_val,
int  u_search_ini = -1,
int  v_search_ini = -1,
int  u_search_size = -1,
int  v_search_size = -1,
CImage out_corr_image = NULL 
) const

Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate.

Parameters:
patch_imgThe "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images.
u_search_iniThe "x" coordinate of the search window.
v_search_iniThe "y" coordinate of the search window.
u_search_sizeThe width of the search window.
v_search_sizeThe height of the search window.
u_maxThe u coordinate where find the maximun cross correlation value.
v_maxThe v coordinate where find the maximun cross correlation value
max_valThe maximun value of cross correlation which we can find
out_corr_imageIf a !=NULL pointer is provided, it will be saved here the correlation image. The size of the output image is (this_width-patch_width+1, this_height-patch_height+1 ) Note: By default, the search area is the whole (this) image. (by AJOGD @ MAR-2007)
void mrpt::utils::CImage::cross_correlation_FFT ( const CImage in_img,
math::CMatrixFloat out_corr,
int  u_search_ini = -1,
int  v_search_ini = -1,
int  u_search_size = -1,
int  v_search_size = -1,
float  biasThisImg = 0,
float  biasInImg = 0 
) const

Computes the correlation matrix between this image and another one.

This implementation uses the 2D FFT for achieving reduced computation time.

Parameters:
in_imgThe "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images.
u_search_iniThe "x" coordinate of the search window.
v_search_iniThe "y" coordinate of the search window.
u_search_sizeThe width of the search window.
v_search_sizeThe height of the search window.
out_corrThe output for the correlation matrix, which will be "u_search_size" x "v_search_size"
biasThisImgThis optional parameter is a fixed "bias" value to be substracted to the pixels of "this" image before performing correlation.
biasInImgThis optional parameter is a fixed "bias" value to be substracted to the pixels of "in_img" image before performing correlation. Note: By default, the search area is the whole (this) image. (by JLBC @ JAN-2006)
See also:
cross_correlation
bool mrpt::utils::CImage::drawChessboardCorners ( std::vector< TPixelCoordf > &  cornerCoords,
unsigned int  check_size_x,
unsigned int  check_size_y 
)

Draw onto this image the detected corners of a chessboard.

The length of cornerCoords must be the product of the two check_sizes.

Parameters:
cornerCoords[IN] The pixel coordinates of all the corners.
check_size_x[IN] The number of squares, in the X direction
check_size_y[IN] The number of squares, in the Y direction
Returns:
false if the length of cornerCoords is inconsistent (nothing is drawn then).
See also:
mrpt::vision::findChessboardCorners
void mrpt::utils::CImage::drawCircle ( int  x,
int  y,
int  radius,
const mrpt::utils::TColor color = mrpt::utils::TColor(255, 255, 255),
unsigned int  width = 1 
)

Draws a circle of a given radius.

Parameters:
xThe center - x coordinate in pixels.
yThe center - y coordinate in pixels.
radiusThe radius - in pixels.
colorThe color of the circle.
widthThe desired width of the line
virtual mrpt::utils::CObject* mrpt::utils::CImage::duplicate (  ) const [virtual]

Returns a copy of the object, indepently of its class.

Implements mrpt::utils::CObject.

void mrpt::utils::CImage::equalizeHist ( CImage outImg ) const

Equalize the image histogram, saving the new image in the given output object.

void mrpt::utils::CImage::equalizeHistInPlace (  )

Equalize the image histogram, replacing the original image.

void mrpt::utils::CImage::extract_patch ( CImage patch,
const unsigned int  col = 0,
const unsigned int  row = 0,
const unsigned int  width = 1,
const unsigned int  height = 1 
) const

Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten).

The patch to extract starts at (col,row) and has the given dimensions.

See also:
update_patch
void mrpt::utils::CImage::filterGaussian ( CImage out_img,
int  W = 3,
int  H = 3 
) const

Filter the image with a Gaussian filter with a window size WxH, replacing "this" image by the filtered one.

void mrpt::utils::CImage::filterGaussianInPlace ( int  W = 3,
int  H = 3 
)

Filter the image with a Gaussian filter with a window size WxH, returning the filtered image in out_img.

void mrpt::utils::CImage::filterMedian ( CImage out_img,
int  W = 3 
) const

Filter the image with a Median filter with a window size WxW, returning the filtered image in out_img.

void mrpt::utils::CImage::filterMedianInPlace ( int  W = 3 )

Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered one.

void mrpt::utils::CImage::flipVertical ( bool  also_swapRB = false )

Flips vertically the image.

See also:
swapRB
void mrpt::utils::CImage::forceLoad (  ) [inline]

For external storage image objects only, this method makes sure the image is loaded in memory.

Note that usually images are loaded on-the-fly on first access and there's no need to call this.

Definition at line 668 of file CImage.h.

unsigned char* mrpt::utils::CImage::get_unsafe ( unsigned int  col,
unsigned int  row,
unsigned int  channel = 0 
) const

Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates.

See also:
CImage::operator()
template<typename T >
const T* mrpt::utils::CImage::getAs (  ) const [inline]

Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.

See also:
getAsIplImage

Definition at line 502 of file CImage.h.

template<typename T >
T* mrpt::utils::CImage::getAs (  ) [inline]

Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.

See also:
getAsIplImage

Definition at line 507 of file CImage.h.

float mrpt::utils::CImage::getAsFloat ( unsigned int  col,
unsigned int  row,
unsigned int  channel 
) const

Returns the contents of a given pixel at the desired channel, in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.

Exceptions:
std::exceptionOn pixel coordinates out of bounds
See also:
operator()
float mrpt::utils::CImage::getAsFloat ( unsigned int  col,
unsigned int  row 
) const

Returns the contents of a given pixel (for gray-scale images, in color images the gray scale equivalent is computed for the pixel), in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.

Exceptions:
std::exceptionOn pixel coordinates out of bounds
See also:
operator()
void* mrpt::utils::CImage::getAsIplImage (  ) const [inline]

Returns a pointer to an OpenCV's IplImage struct containing the image, which is linked to this class: free neigther that pointer nor this class until they are not required anymore, since this class is in charge of freeing the memory buffers inside of the returned image.

See also:
getAs

Definition at line 513 of file CImage.h.

void mrpt::utils::CImage::getAsMatrix ( mrpt::math::CMatrixFloat outMatrix,
bool  doResize = true,
int  x_min = 0,
int  y_min = 0,
int  x_max = -1,
int  y_max = -1 
) const

Returns the image as a matrix with pixel grayscale values in the range [0,1].

Parameters:
doResizeIf set to true (default), the output matrix will be always the size of the image at output. If set to false, the matrix will be enlarged to the size of the image, but it will not be cropped if it has room enough (useful for FFT2D,...)
x_minThe starting "x" coordinate to extract (default=0=the first column)
y_minThe starting "y" coordinate to extract (default=0=the first row)
x_maxThe final "x" coordinate (inclusive) to extract (default=-1=the last column)
y_maxThe final "y" coordinate (inclusive) to extract (default=-1=the last row)
See also:
setFromMatrix
void mrpt::utils::CImage::getAsMatrixTiled ( math::CMatrix outMatrix ) const

Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to fill the entire size of the matrix on input.

TImageChannels mrpt::utils::CImage::getChannelCount (  ) const

Returns the number of channels, typically 1 (GRAY) or 3 (RGB)

See also:
isColor
const char* mrpt::utils::CImage::getChannelsOrder (  ) const

Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.

std::string mrpt::utils::CImage::getExternalStorageFile (  ) const [inline]

< Only if isExternallyStored() returns true.

See also:
getExternalStorageFileAbsolutePath

Definition at line 650 of file CImage.h.

std::string mrpt::utils::CImage::getExternalStorageFileAbsolutePath (  ) const [inline]

Only if isExternallyStored() returns true.

See also:
getExternalStorageFile

Definition at line 659 of file CImage.h.

void mrpt::utils::CImage::getExternalStorageFileAbsolutePath ( std::string &  out_path ) const

Only if isExternallyStored() returns true.

See also:
getExternalStorageFile
size_t mrpt::utils::CImage::getHeight (  ) const [virtual]

Returns the height of the image in pixels.

See also:
getSize

Implements mrpt::utils::CCanvas.

float mrpt::utils::CImage::getMaxAsFloat (  ) const

Return the maximum pixel value of the image, as a float value in the range [0,1].

See also:
getAsFloat
virtual const mrpt::utils::TRuntimeClassId* mrpt::utils::CImage::GetRuntimeClass (  ) const [virtual]

Returns information about the class of an object in runtime.

Reimplemented from mrpt::utils::CSerializable.

void mrpt::utils::CImage::getSize ( TImageSize s ) const

Return the size of the image.

See also:
getWidth, getHeight
TImageSize mrpt::utils::CImage::getSize (  ) const [inline]

Return the size of the image.

See also:
getWidth, getHeight

Definition at line 573 of file CImage.h.

size_t mrpt::utils::CImage::getWidth (  ) const [virtual]

Returns the width of the image in pixels.

See also:
getSize

Implements mrpt::utils::CCanvas.

Referenced by mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints().

CImage mrpt::utils::CImage::grayscale (  ) const

Returns a grayscale version of the image, or itself if it is already a grayscale image.

Referenced by CImage().

void mrpt::utils::CImage::grayscale ( CImage ret ) const

Returns a grayscale version of the image, or itself if it is already a grayscale image.

See also:
colorImage
void mrpt::utils::CImage::grayscaleInPlace (  )

Replaces the image with a grayscale version of it.

See also:
colorImageInPlace
bool mrpt::utils::CImage::isColor (  ) const

Returns true if the image is RGB, false if it is grayscale.

Referenced by CImage().

bool mrpt::utils::CImage::isExternallyStored (  ) const [inline]

See setExternalStorage().

Definition at line 648 of file CImage.h.

bool mrpt::utils::CImage::isOriginTopLeft (  ) const

Returns true if the coordinates origin is top-left, or false if it is bottom-left.

void mrpt::utils::CImage::joinImagesHorz ( const CImage im1,
const CImage im2 
)

Joins two images side-by-side horizontally.

Both images must have the same number of rows and be of the same type (i.e. depth and color mode)

Parameters:
im1[IN] The first image.
im2[IN] The other image.

Referenced by mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints().

float mrpt::utils::CImage::KLT_response ( const unsigned int  x,
const unsigned int  y,
const unsigned int  half_window_size 
) const

Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids converting to grayscale internally).

virtual void mrpt::utils::CImage::line ( int  x0,
int  y0,
int  x1,
int  y1,
const mrpt::utils::TColor  color,
unsigned int  width = 1,
TPenStyle  penStyle = psSolid 
) [virtual]

Draws a line.

Parameters:
x0The starting point x coordinate
y0The starting point y coordinate
x1The end point x coordinate
y1The end point y coordinate
colorThe color of the line
widthThe desired width of the line (this is IGNORED in this virtual class) This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented from mrpt::utils::CCanvas.

bool mrpt::utils::CImage::loadFromFile ( const std::string &  fileName,
int  isColor = -1 
)

Load image from a file, whose format is determined from the extension (internally uses OpenCV).

Parameters:
fileNameThe file to read from.
isColorSpecifies colorness of the loaded image:

  • if >0, the loaded image is forced to be color 3-channel image;
  • if 0, the loaded image is forced to be grayscale;
  • if <0, the loaded image will be loaded as is (with number of channels depends on the file). The supported formats are:
  • Windows bitmaps - BMP, DIB;
  • JPEG files - JPEG, JPG, JPE;
  • Portable Network Graphics - PNG;
  • Portable image format - PBM, PGM, PPM;
  • Sun rasters - SR, RAS;
  • TIFF files - TIFF, TIF.
Returns:
False on any error
See also:
saveToFile, setExternalStorage
void mrpt::utils::CImage::loadFromIplImage ( void *  iplImage )

Reads the image from a OpenCV IplImage object (making a COPY).

void mrpt::utils::CImage::loadFromMemoryBuffer ( unsigned int  width,
unsigned int  height,
bool  color,
unsigned char *  rawpixels,
bool  swapRedBlue = false 
)

Reads the image from raw pixels buffer in memory.

void mrpt::utils::CImage::loadFromMemoryBuffer ( unsigned int  width,
unsigned int  height,
unsigned int  bytesPerRow,
unsigned char *  red,
unsigned char *  green,
unsigned char *  blue 
)

Reads a color image from three raw pixels buffers in memory.

bytesPerRow is the number of bytes per row per channel, i.e. the row increment.

void mrpt::utils::CImage::loadFromStreamAsJPEG ( CStream in )

Reads the image from a binary stream containing a binary jpeg file.

Exceptions:
std::exceptionOn pixel coordinates out of bounds
void mrpt::utils::CImage::makeSureImageIsLoaded (  ) const throw (std::exception,utils::CExceptionExternalImageNotFound ) [protected]

Checks if the image is of type "external storage", and if so and not loaded yet, load it.

void mrpt::utils::CImage::normalize (  )

Optimize de brightness range of a image without using histogram Only for one channel images.

unsigned char* mrpt::utils::CImage::operator() ( unsigned int  col,
unsigned int  row,
unsigned int  channel = 0 
) const

Returns a pointer to a given pixel information.

The coordinate origin is pixel(0,0)=top-left corner of the image.

Exceptions:
std::exceptionOn pixel coordinates out of bounds
CImage& mrpt::utils::CImage::operator= ( const CImage o )

Copy operator (if the image is externally stored, the writen image will be such as well).

See also:
copyFastFrom
void mrpt::utils::CImage::rectifyImage ( CImage out_img,
const mrpt::utils::TCamera cameraParams 
) const

Rectify (un-distort) the image according to some camera parameters, and returns an output un-distorted image.

Parameters:
out_imgThe output rectified image
cameraParamsThe input camera params (containing the intrinsic and distortion parameters of the camera)

Referenced by mrpt::vision::correctDistortion().

void mrpt::utils::CImage::rectifyImage ( CImage out_img,
const math::CMatrixDouble33 cameraMatrix,
const vector_double distCoeff 
) const [inline]

Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.

Parameters:
out_imgThe output rectified image
cameraMatrixThe input camera matrix (containing the intrinsic parameters of the camera): [fx 0 cx; 0 fy cy; 0 0 1]: (fx,fy) focal length and (cx,cy) principal point coordinates
distCoeffThe (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 393 of file CImage.h.

References mrpt::utils::TCamera::intrinsicParams, and mrpt::utils::TCamera::setDistortionParamsVector().

void mrpt::utils::CImage::rectifyImageInPlace ( void *  mapX,
void *  mapY 
)

Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed rectification maps.

Parameters:
mapX,mapY[IN] The pre-computed maps of the rectification (should be computed beforehand)
See also:
vision::computeStereoRectificationMaps
void mrpt::utils::CImage::rectifyImageInPlace ( const math::CMatrixDouble33 cameraMatrix,
const vector_double distCoeff 
) [inline]

Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.

Parameters:
cameraMatrixThe input camera matrix (containing the intrinsic parameters of the camera): [fx 0 cx; 0 fy cy; 0 0 1]: (fx,fy) focal length and (cx,cy) principal point coordinates
distCoeffThe (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 410 of file CImage.h.

References mrpt::utils::TCamera::intrinsicParams, and mrpt::utils::TCamera::setDistortionParamsVector().

void mrpt::utils::CImage::rectifyImageInPlace ( const mrpt::utils::TCamera cameraParams )

Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.

Parameters:
cameraParamsThe input camera params (containing the intrinsic and distortion parameters of the camera)
void mrpt::utils::CImage::releaseIpl ( bool  thisIsExternalImgUnload = false ) [protected]

Release the internal IPL image, if not NULL or read-only.

void mrpt::utils::CImage::resize ( unsigned int  width,
unsigned int  height,
TImageChannels  nChannels,
bool  originTopLeft 
) [inline]

Changes the size of the image, erasing previous contents (does NOT scale its current content, for that, see scaleImage).

  • nChannels: Can be 3 for RGB images or 1 for grayscale images.
  • originTopLeft: Is true if the top-left corner is (0,0). In other case, the reference is the bottom-left corner.
    See also:
    scaleImage

Definition at line 199 of file CImage.h.

References ASSERT_.

void mrpt::utils::CImage::rotateImage ( double  angle_radians,
unsigned int  center_x,
unsigned int  center_y,
double  scale = 1.0 
)

Rotates the image by the given angle around the given center point, with an optional scale factor.

See also:
resize, scaleImage
bool mrpt::utils::CImage::saveToFile ( const std::string &  fileName,
int  jpeg_quality = 95 
) const

Save the image to a file, whose format is determined from the extension (internally uses OpenCV).

Parameters:
fileNameThe file to write to.

The supported formats are:

  • Windows bitmaps - BMP, DIB;
  • JPEG files - JPEG, JPG, JPE;
  • Portable Network Graphics - PNG;
  • Portable image format - PBM, PGM, PPM;
  • Sun rasters - SR, RAS;
  • TIFF files - TIFF, TIF.
Parameters:
jpeg_qualityOnly for JPEG files, the quality of the compression in the range [0-100]. Larger is better quality but slower.
Note:
jpeg_quality is only effective if MRPT is compiled against OpenCV 1.1.0 or newer.
Returns:
False on any error
See also:
loadFromFile
void mrpt::utils::CImage::saveToStreamAsJPEG ( CStream out ) const

Save image to binary stream as a JPEG (.jpg) compresed format.

Exceptions:
std::exceptionOn number of rows or cols equal to zero, or other errors.
See also:
saveToJPEG
CImage mrpt::utils::CImage::scaleDouble (  ) const

Returns a new image scaled up to double its original size.

Exceptions:
std::exceptionOn odd size
See also:
scaleHalf, scaleImage
CImage mrpt::utils::CImage::scaleHalf (  ) const

Returns a new image scaled down to half its original size.

Exceptions:
std::exceptionOn odd size
See also:
scaleDouble, scaleImage
void mrpt::utils::CImage::scaleImage ( CImage out_img,
unsigned int  width,
unsigned int  height,
TInterpolationMethod  interp = IMG_INTERP_CUBIC 
) const

Scales this image to a new size, interpolating as needed, saving the new image in a different output object.

See also:
resize, rotateImage
void mrpt::utils::CImage::scaleImage ( unsigned int  width,
unsigned int  height,
TInterpolationMethod  interp = IMG_INTERP_CUBIC 
)

Scales this image to a new size, interpolating as needed.

See also:
resize, rotateImage
void mrpt::utils::CImage::setExternalStorage ( const std::string &  fileName )

By using this method the image is marked as referenced to an external file, which will be loaded only under demand.

A CImage with external storage does not consume memory until some method trying to access the image is invoked (e.g. getWidth(), isColor(),...) At any moment, the image can be unloaded from memory again by invoking unload. An image becomes of type "external storage" only through calling setExternalStorage. This property remains after serializing the object. File names can be absolute, or relative to the CImage::IMAGES_PATH_BASE directory. Filenames staring with "X:\" or "/" are considered absolute paths. By calling this method the current contents of the image are NOT saved to that file, because this method can be also called to let the object know where to load the image in case its contents are required. Thus, for saving images in this format (not when loading) the proper order of commands should be:

   img.saveToFile( fileName );
   img.setExternalStorage( fileName );
Note:
Modifications to the memory copy of the image are not automatically saved to disk.
See also:
unload, isExternallyStored
void mrpt::utils::CImage::setFromImageReadOnly ( const CImage other_img ) [inline]

Sets the internal IplImage pointer to that of another given image, WITHOUT making a copy, and from now on the image cannot be modified in this object (it will be neither freed, so the memory responsibility will still be of the original image object).

When assigning an IPLImage to this object with this method, the IPLImage will NOT be released/freed at this object destructor.

See also:
setFromIplImageReadOnly

Definition at line 716 of file CImage.h.

void mrpt::utils::CImage::setFromIplImage ( void *  iplImage )

Reads the image from a OpenCV IplImage object (WITHOUT making a copy).

This object will own the memory of the passed object and free the IplImage upon destruction, so the caller CAN'T free the original object. This method provides a fast method to grab images from a camera without making a copy of every frame.

void mrpt::utils::CImage::setFromIplImageReadOnly ( void *  iplImage )

Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image cannot be modified, just read.

When assigning an IPLImage to this object with this method, the IPLImage will NOT be released/freed at this object destructor. This method provides a fast method to grab images from a camera without making a copy of every frame.

See also:
setFromImageReadOnly
template<typename Derived >
void mrpt::utils::CImage::setFromMatrix ( const Eigen::MatrixBase< Derived > &  m,
bool  matrix_is_normalized = true 
) [inline]

Set the image from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false)

See also:
getAsMatrix

Definition at line 722 of file CImage.h.

References ASSERT_, get_unsafe(), MRPT_END, and MRPT_START.

void mrpt::utils::CImage::setOriginTopLeft ( bool  val )

Changes the property of the image stating if the top-left corner (vs.

bottom-left) is the coordinate reference.

void mrpt::utils::CImage::setPixel ( int  x,
int  y,
size_t  color 
) [virtual]

Changes the value of the pixel (x,y).

Pixel coordinates starts at the left-top corner of the image, and start in (0,0). The meaning of the parameter "color" depends on the implementation: it will usually be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level. This method must support (x,y) values OUT of the actual image size without neither raising exceptions, nor leading to memory access errors.

Implements mrpt::utils::CCanvas.

void mrpt::utils::CImage::swap ( CImage o )

Very efficient swap of two images (just swap the internal pointers)

void mrpt::utils::CImage::swapRB (  )

Swaps red and blue channels.

See also:
flipVertical
void mrpt::utils::CImage::unload (  )

For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded).

It does not need to be called explicitly, unless the user wants to save memory for images that will not be used often. If called for an image without the flag "external storage", it is simply ignored.

See also:
setExternalStorage, forceLoad
void mrpt::utils::CImage::update_patch ( const CImage patch,
const unsigned int  col,
const unsigned int  row 
)

Update a part of this image with the "patch" given as argument.

The "patch" will be "pasted" at the (col,row) coordinates of this image.

Exceptions:
std::exceptionif patch pasted on the pixel (_row, _column) jut out of the image.
See also:
extract_patch

Member Data Documentation

Definition at line 110 of file CImage.h.

Definition at line 110 of file CImage.h.

Definition at line 110 of file CImage.h.

By default, when storing images through the CSerializable interface, grayscale images will be ZIP compressed if they are larger than 16Kb: this flag can be turn on to disable ZIP compression and gain speed versus occupied space.

The default value of this variable is "false".

Definition at line 187 of file CImage.h.

By default, ".".

See also:
setExternalStorage

Definition at line 645 of file CImage.h.

void* mrpt::utils::CImage::img [protected]

The internal IplImage pointer to the actual image content.

Definition at line 838 of file CImage.h.

std::string mrpt::utils::CImage::m_externalFile [mutable, protected]

The file name of a external storage image.

Definition at line 847 of file CImage.h.

Set to true only when using setExternalStorage.

See also:
setExternalStorage

Definition at line 846 of file CImage.h.

Set to true only when using setFromIplImageReadOnly.

See also:
setFromIplImageReadOnly

Definition at line 842 of file CImage.h.




Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:46:17 UTC 2011