MRPT logo

mrpt::utils::CMRPTImage Class Reference

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

#include <mrpt/utils/CMRPTImage.h>

Inheritance diagram for mrpt::utils::CMRPTImage:

mrpt::utils::CSerializable mrpt::utils::CMRPTCanvas

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).
void scaleImage (unsigned int width, unsigned int height, TInterpMethod interp=IMG_INTERP_CUBIC)
 Scales the image to a new size, interpolating as needed.
void setPixel (int x, int y, size_t color)
 Changes the value of the pixel (x,y).
 CMRPTImage ()
 Default constructor:.
 CMRPTImage (unsigned int width, unsigned int height, unsigned int nChannels=3, bool originTopLeft=true)
 Constructor:.
 CMRPTImage (const CMRPTImage &o)
 Copy constructor:.
 CMRPTImage (const CMRPTImageFloat &o)
 Copy constructor:.
void operator= (const CMRPTImage &o)
 Copy operator.
void operator= (const CMRPTImageFloat &o)
 Copy operator from a gray-scale, float image:.
void copyFastFrom (CMRPTImage &o)
 Moves an image from another object, erasing the origin image in the process (this is much faster than copying).
 CMRPTImage (void *iplImage)
 Constructor from IplImage.
virtual ~CMRPTImage ()
 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.
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 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).
MRPT_DEPRECATED_PRE bool loadFromBMP (const std::string &fileName) MRPT_DEPRECATED_POST
 Load image from a bitmap file (.bmp) format, automatically determining if the file format is 8 or 24 bits/pixel.
MRPT_DEPRECATED_PRE bool loadFromJPEG (const std::string &fileName) MRPT_DEPRECATED_POST
 Load image from a JPEG file (.jpg).
void loadFromStreamAsJPEG (CStream &in)
 Reads the image from a binary stream containing a binary jpeg file.
MRPT_DEPRECATED_PRE bool saveToBMP (const std::string &fileName) const MRPT_DEPRECATED_POST
 Save image to a bitmap file (.bmp) format: Currently supported formats are 24-bit RGB bitmap for color images and 8-bit grayscale for grayscale images.
MRPT_DEPRECATED_PRE bool saveToJPEG (const std::string &fileName) const MRPT_DEPRECATED_POST
 Save image to a JPEG file (.jpg) format.
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.
CMRPTImage grayscale () const
 Returns a grayscale version of the image, or itself if it is already a grayscale image.
void grayscale (CMRPTImage &ret) const
 Returns a grayscale version of the image, or itself if it is already a grayscale image.
CMRPTImage scaleHalf () const
 Returns a new image scaled down to half its original size.
CMRPTImage 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.
void extract_patch (CMRPTImage &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 CMRPTImage &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 (CMRPTImage &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 CMRPTImage &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 (math::CMatrix &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.
void normalize ()
 Optimize de brightness range of a image without using histogram Only for one channel images.
void openCV_cross_correlation (const CMRPTImage &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 (CMRPTImage &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 (CMRPTImage &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 (CMRPTImage &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 (CMRPTImage &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.

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 () 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 (CMRPTImage &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 CMRPTImageFloat


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:

Since MRPT 0.4BETA (Sep 2007), this class becomes a wrapper class for OpenCV functions.

See also:
CMRPTImage, CMRPTImageFloat, CSerializable

Definition at line 82 of file CMRPTImage.h.


Constructor & Destructor Documentation

mrpt::utils::CMRPTImage::CMRPTImage (  ) 

Default constructor:.

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

Constructor:.

mrpt::utils::CMRPTImage::CMRPTImage ( const CMRPTImage o  ) 

Copy constructor:.

mrpt::utils::CMRPTImage::CMRPTImage ( const CMRPTImageFloat o  ) 

Copy constructor:.

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

Constructor from IplImage.

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

Destructor:.


Member Function Documentation

void mrpt::utils::CMRPTImage::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::CMRPTImage::copyFastFrom ( CMRPTImage 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::CMRPTImage::correlate ( const CMRPTImage 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::CMRPTImage::cross_correlation ( CMRPTImage 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::CMRPTImage::cross_correlation_FFT ( const CMRPTImage 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

void mrpt::utils::CMRPTImage::extract_patch ( CMRPTImage 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)

void mrpt::utils::CMRPTImage::filterGaussian ( CMRPTImage 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::CMRPTImage::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::CMRPTImage::filterMedian ( CMRPTImage 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::CMRPTImage::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::CMRPTImage::flipVertical ( bool  also_swapRB = false  ) 

Flips vertically the image.

See also:
swapRB

unsigned char* mrpt::utils::CMRPTImage::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:
CMRPTImage::operator()

float mrpt::utils::CMRPTImage::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::CMRPTImage::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::CMRPTImage::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::CMRPTImage::getAsMatrix ( math::CMatrix 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)

void mrpt::utils::CMRPTImage::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)

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

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

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

< Only if isExternallyStored() returns true.

See also:
getExternalStorageFileAbsolutePath

Definition at line 293 of file CMRPTImage.h.

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

Only if isExternallyStored() returns true.

See also:
getExternalStorageFile

size_t mrpt::utils::CMRPTImage::getHeight (  )  const [virtual]

Returns the height of the image in pixels.

Implements mrpt::utils::CMRPTCanvas.

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

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

See also:
getAsFloat

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

Returns the width of the image in pixels.

Implements mrpt::utils::CMRPTCanvas.

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

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

CMRPTImage mrpt::utils::CMRPTImage::grayscale (  )  const

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

bool mrpt::utils::CMRPTImage::isColor (  )  const

Returns true if the image is RGB, false if it is gray scale.

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

See setExternalStorage().

Definition at line 291 of file CMRPTImage.h.

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

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

MRPT_DEPRECATED_PRE bool mrpt::utils::CMRPTImage::loadFromBMP ( const std::string &  fileName  ) 

Load image from a bitmap file (.bmp) format, automatically determining if the file format is 8 or 24 bits/pixel.

Returns:
False on any error
Deprecated:
{Use the generic loadFromFile instead}

bool mrpt::utils::CMRPTImage::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::CMRPTImage::loadFromIplImage ( void *  iplImage  ) 

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

MRPT_DEPRECATED_PRE bool mrpt::utils::CMRPTImage::loadFromJPEG ( const std::string &  fileName  ) 

Load image from a JPEG file (.jpg).

Returns:
False on any error
Deprecated:
{Use the generic loadFromFile instead}

void mrpt::utils::CMRPTImage::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::CMRPTImage::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::CMRPTImage::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::CMRPTImage::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::CMRPTImage::normalize (  ) 

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

(by AJOGD @ JAN-2007)

void mrpt::utils::CMRPTImage::openCV_cross_correlation ( const CMRPTImage 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::CMRPTImage::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

void mrpt::utils::CMRPTImage::operator= ( const CMRPTImageFloat o  ) 

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

See also:
copyFastFrom

void mrpt::utils::CMRPTImage::operator= ( const CMRPTImage o  ) 

Copy operator.

See also:
copyFastFrom

template<class T1 , class T2 >
void mrpt::utils::CMRPTImage::rectifyImage ( CMRPTImage 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 559 of file CMRPTImage.h.

template<class T1 , class T2 >
void mrpt::utils::CMRPTImage::rectifyImage ( CMRPTImage 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 532 of file CMRPTImage.h.

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

template<class T1 , class T2 >
void mrpt::utils::CMRPTImage::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 572 of file CMRPTImage.h.

template<class T1 , class T2 >
void mrpt::utils::CMRPTImage::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 545 of file CMRPTImage.h.

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

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

void mrpt::utils::CMRPTImage::releaseIpl (  )  [protected]

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

void mrpt::utils::CMRPTImage::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).

  • 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 133 of file CMRPTImage.h.

References ASSERT_.

MRPT_DEPRECATED_PRE bool mrpt::utils::CMRPTImage::saveToBMP ( const std::string &  fileName  )  const

Save image to a bitmap file (.bmp) format: Currently supported formats are 24-bit RGB bitmap for color images and 8-bit grayscale for grayscale images.

Returns:
False on any error
Deprecated:
{Use the generic saveToFile instead}

bool mrpt::utils::CMRPTImage::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

MRPT_DEPRECATED_PRE bool mrpt::utils::CMRPTImage::saveToJPEG ( const std::string &  fileName  )  const

Save image to a JPEG file (.jpg) format.

Returns:
False on any error
See also:
saveToStreamAsJPEG
Deprecated:
{Use the generic saveToFile instead}

void mrpt::utils::CMRPTImage::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

CMRPTImage mrpt::utils::CMRPTImage::scaleDouble (  )  const

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

Exceptions:
std::exception On odd size
See also:
scaleHalf

CMRPTImage mrpt::utils::CMRPTImage::scaleHalf (  )  const

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

Exceptions:
std::exception On odd size
See also:
scaleDouble

void mrpt::utils::CMRPTImage::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

void mrpt::utils::CMRPTImage::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 CMRPTImage 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 CMRPTImage::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::CMRPTImage::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::CMRPTImage::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::CMRPTImage::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::CMRPTCanvas.

void mrpt::utils::CMRPTImage::swapRB (  ) 

Swaps red and blue channels.

See also:
flipVertical

void mrpt::utils::CMRPTImage::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 CMRPTImageFloat [friend]

Definition at line 84 of file CMRPTImage.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 126 of file CMRPTImage.h.

By default, ".".

See also:
setExternalStorage

Definition at line 288 of file CMRPTImage.h.

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

Data members.

Definition at line 91 of file CMRPTImage.h.

std::string mrpt::utils::CMRPTImage::m_externalFile [protected]

The file name of a external storage image.

Definition at line 102 of file CMRPTImage.h.

Set to true only when using setExternalStorage.

See also:
setExternalStorage

Definition at line 101 of file CMRPTImage.h.

Set to true only when using setFromIplImageReadOnly.

See also:
setFromIplImageReadOnly

Definition at line 96 of file CMRPTImage.h.




Page generated by Doxygen 1.5.8 for MRPT 0.6.5 SVN: at Thu Feb 26 02:18:33 EST 2009