MRPT logo

mrpt::utils::CImage Class Reference

A class for storing images as grayscale or RGB bitmaps. More...

#include <mrpt/utils/CImage.h>

Inheritance diagram for mrpt::utils::CImage:

mrpt::utils::CSerializable mrpt::utils::CCanvas

List of all members.

Public Member Functions

void resize (unsigned int width, unsigned int height, unsigned int 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, TInterpMethod interp=IMG_INTERP_CUBIC)
 Scales the image to a new size, interpolating as needed.
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 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.
 CImage ()
 Default constructor:.
 CImage (unsigned int width, unsigned int height, unsigned int nChannels=3, bool originTopLeft=true)
 Constructor:.
 CImage (const CImage &o)
 Copy constructor:.
 CImage (const CImageFloat &o)
 Copy constructor:.
CImageoperator= (const CImage &o)
 Copy operator.
CImageoperator= (const CImageFloat &o)
 Copy operator from a gray-scale, float image:.
void copyFastFrom (CImage &o)
 Moves an image from another object, erasing the origin image in the process (this is much faster than copying).
 CImage (void *iplImage)
 Constructor from IplImage.
virtual ~CImage ()
 Destructor:.
void * getAsIplImage () const
 Returns a pointer to an "OpenCv" 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.
float getMaxAsFloat () const
 Return the maximum pixel value of the image, as a float value.
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.
bool isColor () const
 Returns true if the image is RGB, false if it is gray scale.
bool isOriginTopLeft () const
 Returns true if the coordinates origin is top-left, or false if it is bottom-left.
void setOriginTopLeft (bool val)
 Changes the property of the image stating if the top-left corner (vs.
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 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.
void unload () MRPT_NO_THROWS
 For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded).
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) 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.
unsigned char * operator() (unsigned int col, unsigned int row, unsigned int channel=0) const
 Returns a pointer to a given pixel information.
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 grayscaleInPlace ()
 Replaces the image with a grayscale version of it.
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.
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.
const char * getChannelsOrder () const
 Returns a string of the form "BGR" indicating the channels ordering.
unsigned int getChannelCount () const
 Returns the number of channels (typ: 1 or 3).
void extract_patch (CImage &patch, const unsigned int col_=0, const unsigned int row_=0, const unsigned int col_num=1, const unsigned int row_num=1) const
 Extracts a patch of this image into another image.
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 (CImage &img2, math::CMatrixFloat &M, const int &u_search_ini, const int &v_search_ini, const int &u_search_size, const int &v_search_size) const
 Computes the cross_correlation between two images and return a matrix of correlation coeficients This function use grayscale images only (by AJOGD @ DEC-2006).
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 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 setFromMatrix (const mrpt::math::CMatrixFloat &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 setFromMatrix (const mrpt::math::CMatrixDouble &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 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.
void normalize ()
 Optimize de brightness range of a image without using histogram Only for one channel images.
void openCV_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) const
 Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate This implementation reduced computation time.
void flipVertical (bool also_swapRB=false)
 Flips vertically the image.
void swapRB ()
 Swaps red and blue channels.
template<class T1 , class T2 >
void rectifyImage (CImage &out_img, const math::CMatrixTemplateNumeric< T1 > &cameraMatrix, const math::CMatrixTemplateNumeric< T2 > &distCoeff) const
 Rectifies the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.
template<class T1 , class T2 >
void rectifyImageInPlace (const math::CMatrixTemplateNumeric< T1 > &cameraMatrix, const math::CMatrixTemplateNumeric< T2 > &distCoeff)
 Rectifies the image according to a certain camera matrix and vector of distortion coefficients, replacing "this"· with the rectified image.
template<class T1 , class T2 >
void rectifyImage (CImage &out_img, const math::CMatrixTemplateNumeric< T1 > &cameraMatrix, const std::vector< T2 > &distCoeff) const
 Rectifies the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.
template<class T1 , class T2 >
void rectifyImageInPlace (const math::CMatrixTemplateNumeric< T1 > &cameraMatrix, const std::vector< T2 > &distCoeff)
 Rectifies the image according to a certain camera matrix and vector of distortion coefficients, replacing "this"· with the rectified image.
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 findChessboardCorners (std::vector< TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y, bool normalize_image=true) const
 Look for the corners of a chessboard in the image.
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.

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.
static std::string IMAGES_PATH_BASE
 By default, ".".

Protected Member Functions

void changeSize (unsigned int width, unsigned int height, unsigned int 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.
void rectifyImage_internal (CImage &out_img, const math::CMatrixDouble &cameraMatrix, const vector_double &distCoeff) const
void rectifyImageInPlace_internal (const math::CMatrixDouble &cameraMatrix, const vector_double &distCoeff)

Protected Attributes

void * img
 Data members.
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.

Friends

class CImageFloat


Detailed Description

A class for storing images as grayscale or RGB bitmaps.

File I/O is supported in two different ways:

Additional notes:

Additional implementated operators:

Note:
This class acts as a wrapper class for OpenCV functions, and an IplImage is the internal representation for compatibility.
See also:
mrpt::vision, mrpt::vision::CFeatureExtractor, CSerializable, CCanvas

Definition at line 84 of file CImage.h.


Constructor & Destructor Documentation

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

Default constructor:.

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

Constructor:.

mrpt::utils::CImage::CImage ( const CImage o  ) 

Copy constructor:.

mrpt::utils::CImage::CImage ( const CImageFloat o  ) 

Copy constructor:.

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

Constructor from IplImage.

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

Destructor:.


Member Function Documentation

void mrpt::utils::CImage::changeSize ( unsigned int  width,
unsigned int  height,
unsigned int  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

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 =

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).

void mrpt::utils::CImage::cross_correlation ( CImage img2,
math::CMatrixFloat M,
const int &  u_search_ini,
const int &  v_search_ini,
const int &  u_search_size,
const int &  v_search_size 
) const

Computes the cross_correlation between two images and return a matrix of correlation coeficients This function use grayscale images only (by AJOGD @ DEC-2006).

See also:
cross_correlation_FFT

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_img The "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images.
u_search_ini The "x" coordinate of the search window.
v_search_ini The "y" coordinate of the search window.
u_search_size The width of the search window.
v_search_size The height of the search window.
out_corr The output for the correlation matrix, which will be "u_search_size" x "v_search_size"
biasThisImg This optional parameter is a fixed "bias" value to be substracted to the pixels of "this" image before performing correlation.
biasInImg This 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:
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 
) [virtual]

Draws a circle of a given radius.

Parameters:
x The center - x coordinate in pixels.
y The center - y coordinate in pixels.
radius The radius - in pixels.
color The color of the circle.
width The desired width of the line

Reimplemented from mrpt::utils::CCanvas.

void mrpt::utils::CImage::extract_patch ( CImage patch,
const unsigned int  col_ = 0,
const unsigned int  row_ = 0,
const unsigned int  col_num = 1,
const unsigned int  row_num = 1 
) const

Extracts a patch of this image into another image.

(by AJOGD @ DEC-2006)

Referenced by mrpt::monoslam::CFeaturePatch::set_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.

bool mrpt::utils::CImage::findChessboardCorners ( std::vector< TPixelCoordf > &  cornerCoords,
unsigned int  check_size_x,
unsigned int  check_size_y,
bool  normalize_image = true 
) const

Look for the corners of a chessboard in the image.

This method uses internally OpenCV functions:

  • cvFindChessboardCorners
  • cvFindCornerSubPix

Parameters:
cornerCoords [OUT] 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
normalize_image [IN] Whether to normalize the image before detection
Returns:
true on success
See also:
mrpt::vision::checkerBoardCameraCalibration, drawChessboardCorners

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

Flips vertically the image.

See also:
swapRB

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()

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::exception On pixel coordinates out of bounds
See also:
operator()

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::exception On pixel coordinates out of bounds
See also:
operator()

void* mrpt::utils::CImage::getAsIplImage (  )  const

Returns a pointer to an "OpenCv" 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.

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:
doResize If 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_min The starting "x" coordinate to extract (default=0=the first column)
y_min The starting "y" coordinate to extract (default=0=the first row)
x_max The final "x" coordinate (inclusive) to extract (default=-1=the last column)
y_max The final "y" coordinate (inclusive) to extract (default=-1=the last row) (by JLBC @ JAN-2006)
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.

(by JLBC @ JAN-2006)

unsigned int mrpt::utils::CImage::getChannelCount (  )  const

Returns the number of channels (typ: 1 or 3).

See also:
isColor

const char* mrpt::utils::CImage::getChannelsOrder (  )  const

Returns a string of the form "BGR" indicating the channels ordering.

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

< Only if isExternallyStored() returns true.

See also:
getExternalStorageFileAbsolutePath

Definition at line 334 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.

Referenced by mrpt::monoslam::CFeaturePatch::CFeaturePatch(), and mrpt::monoslam::CFeaturePatch::set_patch().

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

Return the maximum pixel value of the image, as a float value.

See also:
getAsFloat

TImageSize mrpt::utils::CImage::getSize (  )  const [inline]

Return the size of the image.

See also:
getWidth, getHeight

Definition at line 269 of file CImage.h.

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

Return the size of the image.

See also:
getWidth, getHeight

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::monoslam::CFeaturePatch::CFeaturePatch(), and mrpt::monoslam::CFeaturePatch::set_patch().

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

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

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

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 gray scale.

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

See setExternalStorage().

Definition at line 332 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.

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:
fileName The file to read from.
isColor Specifies 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,
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::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::loadFromStreamAsJPEG ( CStream in  ) 

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

Exceptions:
std::exception On 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.

(by AJOGD @ JAN-2007)

void mrpt::utils::CImage::openCV_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 
) const

Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate This implementation reduced computation time.

Parameters:
patch_img The "patch" image, which must be equal, or smaller than "this" image. This function supports gray-scale (1 channel only) images.
u_search_ini The "x" coordinate of the search window.
v_search_ini The "y" coordinate of the search window.
u_search_size The width of the search window.
v_search_size The height of the search window.
u_max The u coordinate where find the maximun cross correlation value.
v_max The v coordinate where find the maximun cross correlation value
max_val The maximun value of cross correlation which we can find Note: By default, the search area is the whole (this) image. (by AJOGD @ MAR-2007)
See also:
cross_correlation

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::exception On pixel coordinates out of bounds

CImage& mrpt::utils::CImage::operator= ( const CImageFloat o  ) 

Copy operator from a gray-scale, float image:.

See also:
copyFastFrom

CImage& mrpt::utils::CImage::operator= ( const CImage o  ) 

Copy operator.

See also:
copyFastFrom

template<class T1 , class T2 >
void mrpt::utils::CImage::rectifyImage ( CImage out_img,
const math::CMatrixTemplateNumeric< T1 > &  cameraMatrix,
const std::vector< T2 > &  distCoeff 
) const [inline]

Rectifies the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.

Parameters:
out_img The output rectified image
cameraMatrix The 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
distCoeff The (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 607 of file CImage.h.

template<class T1 , class T2 >
void mrpt::utils::CImage::rectifyImage ( CImage out_img,
const math::CMatrixTemplateNumeric< T1 > &  cameraMatrix,
const math::CMatrixTemplateNumeric< T2 > &  distCoeff 
) const [inline]

Rectifies the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.

Parameters:
out_img The output rectified image
cameraMatrix The 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
distCoeff The (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 580 of file CImage.h.

void mrpt::utils::CImage::rectifyImage_internal ( CImage out_img,
const math::CMatrixDouble cameraMatrix,
const vector_double distCoeff 
) const [protected]

template<class T1 , class T2 >
void mrpt::utils::CImage::rectifyImageInPlace ( const math::CMatrixTemplateNumeric< T1 > &  cameraMatrix,
const std::vector< T2 > &  distCoeff 
) [inline]

Rectifies the image according to a certain camera matrix and vector of distortion coefficients, replacing "this"· with the rectified image.

Parameters:
cameraMatrix The 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
distCoeff The (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 620 of file CImage.h.

template<class T1 , class T2 >
void mrpt::utils::CImage::rectifyImageInPlace ( const math::CMatrixTemplateNumeric< T1 > &  cameraMatrix,
const math::CMatrixTemplateNumeric< T2 > &  distCoeff 
) [inline]

Rectifies the image according to a certain camera matrix and vector of distortion coefficients, replacing "this"· with the rectified image.

Parameters:
cameraMatrix The 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
distCoeff The (input) distortion coefficients: [k1, k2, p1, p2]: k1 and k2 (radial) and p1 and p2 (tangential)

Definition at line 593 of file CImage.h.

References mrpt::math::CMatrixTemplate< T >::extractRow().

void mrpt::utils::CImage::rectifyImageInPlace_internal ( const math::CMatrixDouble cameraMatrix,
const vector_double distCoeff 
) [protected]

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,
unsigned int  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 135 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  )  const

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

Parameters:
fileName The 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.

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::exception On 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::exception On 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::exception On odd size
See also:
scaleDouble, scaleImage

void mrpt::utils::CImage::scaleImage ( unsigned int  width,
unsigned int  height,
TInterpMethod  interp = IMG_INTERP_CUBIC 
)

Scales the 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.

This feature has been added in MRPT 0.5.5.

See also:
unload, isExternallyStored

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

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

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.

This method provides a fast method to grab images from a camera without making a copy of every frame.

void mrpt::utils::CImage::setFromMatrix ( const mrpt::math::CMatrixDouble 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).

See also:
getAsMatrix

void mrpt::utils::CImage::setFromMatrix ( const mrpt::math::CMatrixFloat 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).

See also:
getAsMatrix

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::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


Friends And Related Function Documentation

friend class CImageFloat [friend]

Definition at line 86 of file CImage.h.


Member Data Documentation

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 128 of file CImage.h.

By default, ".".

See also:
setExternalStorage

Definition at line 329 of file CImage.h.

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

Data members.

Definition at line 93 of file CImage.h.

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

The file name of a external storage image.

Definition at line 104 of file CImage.h.

Set to true only when using setExternalStorage.

See also:
setExternalStorage

Definition at line 103 of file CImage.h.

Set to true only when using setFromIplImageReadOnly.

See also:
setFromIplImageReadOnly

Definition at line 98 of file CImage.h.




Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:27:43 EDT 2009