Main MRPT website > C++ reference for MRPT 1.5.0
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
mrpt::utils::CImage Class Reference

Detailed Description

A class for storing images as grayscale or RGB bitmaps.

File I/O is supported as:

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:

Some functions are implemented in MRPT with highly optimized SSE2/SSE3 routines, in suitable platforms and compilers. To see the list of optimizations refer to this page. If optimized versions are not available in some platform it falls back to default OpenCV methods.

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, mrpt::vision::CImagePyramid, CSerializable, CCanvas

Definition at line 101 of file CImage.h.

#include <mrpt/utils/CImage.h>

Inheritance diagram for mrpt::utils::CImage:
Inheritance graph

Public Types

enum  TPenStyle {
  psSolid = 0, psDash, psDot, psDashDot,
  psDashDotDot
}
 Definition of pen styles. More...
 

Public Member Functions

void * operator new (size_t size)
 
void * operator new[] (size_t size)
 
void operator delete (void *ptr) throw ()
 
void operator delete[] (void *ptr) throw ()
 
void operator delete (void *memory, void *ptr) throw ()
 
void * operator new (size_t size, const std::nothrow_t &) throw ()
 
void operator delete (void *ptr, const std::nothrow_t &) throw ()
 
virtual mxArraywriteToMatlab () const
 Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class. More...
 
mrpt::utils::CObjectPtr duplicateGetSmartPtr () const
 Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer). More...
 
CObjectclone () const
 Cloning interface for smart pointers. More...
 
void rectangle (int x0, int y0, int x1, int y1, const mrpt::utils::TColor color, unsigned int width=1)
 Draws a rectangle (an empty rectangle, without filling) More...
 
void triangle (int x0, int y0, int size, const mrpt::utils::TColor color, bool inferior=true, unsigned int width=1)
 Draws a triangle. More...
 
virtual void filledRectangle (int x0, int y0, int x1, int y1, const mrpt::utils::TColor color)
 Draws a filled rectangle. More...
 
virtual void textOut (int x0, int y0, const std::string &str, const mrpt::utils::TColor color)
 Renders 2D text using bitmap fonts. More...
 
virtual void selectTextFont (const std::string &fontName)
 Select the current font used when drawing text. More...
 
virtual void drawImage (int x, int y, const utils::CImage &img)
 Draws an image as a bitmap at a given position. More...
 
virtual void drawImage (int x, int y, const utils::CImage &img, float rotation, float scale)
 Draws an image as a bitmap at a given position, with some custom scale and rotation changes. More...
 
void cross (int x0, int y0, const mrpt::utils::TColor color, char type, unsigned int size=5, unsigned int width=1)
 Draw a cross. More...
 
template<class MATRIX2X2 >
void ellipseGaussian (const MATRIX2X2 *cov2D, const double mean_x, const double mean_y, double confIntervalStds=2, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1, int nEllipsePoints=20)
 Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution. More...
 
template<class FEATURELIST >
void drawFeaturesSimple (const FEATURELIST &list, const TColor &color=TColor::red, const int cross_size=5)
 Draws a set of marks onto the image, given a generic container of entities having just "x" and "y" fields. More...
 
template<class FEATURELIST >
void drawFeatures (const FEATURELIST &list, const TColor &color=TColor::red, const bool showIDs=false, const bool showResponse=false)
 Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic container of features. More...
 
Constructors & destructor
 CImage ()
 Default constructor: initialize an 1x1 RGB image. More...
 
 CImage (unsigned int width, unsigned int height, TImageChannels nChannels=CH_RGB, bool originTopLeft=true)
 Constructor for a given image size and type. More...
 
 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). More...
 
 CImage (TConstructorFlags_CImage)
 Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL). More...
 
 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. More...
 
 CImage (void *iplImage)
 Constructor from an IPLImage*, making a copy of the image. More...
 
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) More...
 
virtual ~CImage ()
 Destructor: More...
 
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). More...
 
void scaleImage (unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
 Scales this image to a new size, interpolating as needed. More...
 
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. More...
 
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. More...
 
void setPixel (int x, int y, size_t color) MRPT_OVERRIDE
 Changes the value of the pixel (x,y). More...
 
void setOriginTopLeft (bool val)
 Changes the property of the image stating if the top-left corner (vs. More...
 
void line (int x0, int y0, int x1, int y1, const mrpt::utils::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) MRPT_OVERRIDE
 Draws a line. More...
 
void drawCircle (int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1) MRPT_OVERRIDE
 Draws a circle of a given radius. More...
 
void equalizeHistInPlace ()
 Equalize the image histogram, replacing the original image. More...
 
void equalizeHist (CImage &outImg) const
 Equalize the image histogram, saving the new image in the given output object. More...
 
CImage scaleHalf () const
 Returns a new image scaled down to half its original size. More...
 
void scaleHalf (CImage &out_image) const
 
CImage scaleHalfSmooth () const
 Returns a new image scaled down to half its original size (averaging between every two rows)

Exceptions
std::exceptionOn odd size.
More...
 
void scaleHalfSmooth (CImage &out_image) const
 
CImage scaleDouble () const
 Returns a new image scaled up to double its original size. More...
 
void scaleDouble (CImage &out_image) const
 
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. More...
 
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). More...
 
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) More...
 
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. More...
 
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. More...
 
void normalize ()
 Optimize the brightness range of an image without using histogram Only for one channel images. More...
 
void flipVertical (bool also_swapRB=false)
 Flips vertically the image. More...
 
void swapRB ()
 Swaps red and blue channels. More...
 
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. More...
 
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. More...
 
void rectifyImageInPlace (void *mapX, void *mapY)
 Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed rectification maps. More...
 
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. More...
 
void filterMedianInPlace (int W=3)
 Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered one. More...
 
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. More...
 
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. More...
 
bool drawChessboardCorners (std::vector< TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y, unsigned int lines_width=1, unsigned int circles_radius=4)
 Draw onto this image the detected corners of a chessboard. More...
 
void joinImagesHorz (const CImage &im1, const CImage &im2)
 Joins two images side-by-side horizontally. More...
 
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). More...
 
Copy, move & swap operations
CImageoperator= (const CImage &o)
 Copy operator (if the image is externally stored, the writen image will be such as well). More...
 
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. More...
 
void copyFastFrom (CImage &o)
 Moves an image from another object, erasing the origin image in the process (this is much faster than copying) More...
 
void swap (CImage &o)
 Very efficient swap of two images (just swap the internal pointers) More...
 
Access to image contents (IplImage structure and raw pixels).
template<typename T >
const T * getAs () const
 Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. More...
 
template<typename T >
T * getAs ()
 Returns a pointer to a T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. More...
 
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. More...
 
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. More...
 
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. More...
 
unsigned char * operator() (unsigned int col, unsigned int row, unsigned int channel=0) const
 Returns a pointer to a given pixel information. More...
 
Query image properties
size_t getWidth () const MRPT_OVERRIDE
 Returns the width of the image in pixels. More...
 
size_t getHeight () const MRPT_OVERRIDE
 Returns the height of the image in pixels. More...
 
void getSize (TImageSize &s) const
 Return the size of the image. More...
 
TImageSize getSize () const
 Return the size of the image. More...
 
size_t getRowStride () const
 Returns the row stride of the image: this is the number of bytes between two consecutive rows. More...
 
float getMaxAsFloat () const
 Return the maximum pixel value of the image, as a float value in the range [0,1]. More...
 
bool isColor () const
 Returns true if the image is RGB, false if it is grayscale. More...
 
bool isOriginTopLeft () const
 Returns true if the coordinates origin is top-left, or false if it is bottom-left. More...
 
const char * getChannelsOrder () const
 Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering. More...
 
void setChannelsOrder_RGB ()
 Marks the channel ordering in a color image as "RGB" (this doesn't actually modify the image data, just the format description) More...
 
void setChannelsOrder_BGR ()
 Marks the channel ordering in a color image as "BGR" (this doesn't actually modify the image data, just the format description) More...
 
TImageChannels getChannelCount () const
 Returns the number of channels, typically 1 (GRAY) or 3 (RGB) More...
 
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]. More...
 
void getAsRGBMatrices (mrpt::math::CMatrixFloat &outMatrixR, mrpt::math::CMatrixFloat &outMatrixG, mrpt::math::CMatrixFloat &outMatrixB, bool doResize=true, int x_min=0, int y_min=0, int x_max=-1, int y_max=-1) const
 Returns the image as RGB matrices with pixel values in the range [0,1]. More...
 
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. More...
 
Color/Grayscale conversion
CImage grayscale () const
 Returns a grayscale version of the image, or itself if it is already a grayscale image. More...
 
void grayscale (CImage &ret) const
 Returns a grayscale version of the image, or itself if it is already a grayscale image. More...
 
void colorImage (CImage &ret) const
 Returns a RGB version of the grayscale image, or itself if it is already a RGB image. More...
 
void colorImageInPlace ()
 Replaces this grayscale image with a RGB version of it. More...
 
void grayscaleInPlace ()
 Replaces the image with a grayscale version of it. More...
 

Static Public Member Functions

static void * operator new (size_t size, void *ptr)
 

Static Public Attributes

static const
mrpt::utils::TRuntimeClassId 
classCObject
 
Serialization format global flags
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. More...
 
static bool DISABLE_JPEG_COMPRESSION
 By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed to save space. More...
 
static int SERIALIZATION_JPEG_QUALITY
 Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB images. More...
 
RTTI stuff
static const
mrpt::utils::TRuntimeClassId 
classCSerializable
 

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. More...
 
void releaseIpl (bool thisIsExternalImgUnload=false) MRPT_NO_THROWS
 Release the internal IPL image, if not NULL or read-only. More...
 
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. More...
 
CSerializable virtual methods
void writeToStream (mrpt::utils::CStream &out, int *getVersion) const
 Introduces a pure virtual method responsible for writing to a CStream. More...
 
void readFromStream (mrpt::utils::CStream &in, int version)
 Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori. More...
 

Protected Attributes

std::string m_selectedFont
 The selected font name. More...
 
const uint32_t * m_selectedFontBitmaps
 Direct access to character bitmaps. More...
 
Data members
void * img
 The internal IplImage pointer to the actual image content. More...
 
bool m_imgIsReadOnly
 Set to true only when using setFromIplImageReadOnly. More...
 
bool m_imgIsExternalStorage
 Set to true only when using setExternalStorage. More...
 
std::string m_externalFile
 The file name of a external storage image. More...
 

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. More...
 
virtual mrpt::utils::CObjectduplicate () const
 Returns a copy of the object, indepently of its class. More...
 
static mrpt::utils::CObjectCreateObject ()
 
static CImagePtr Create ()
 

External storage-mode methods

static std::string IMAGES_PATH_BASE
 By default, ".". More...
 
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. More...
 
bool isExternallyStored () const MRPT_NO_THROWS
 See setExternalStorage(). More...
 
std::string getExternalStorageFile () const MRPT_NO_THROWS
 < Only if isExternallyStored() returns true. More...
 
void getExternalStorageFileAbsolutePath (std::string &out_path) const
 Only if isExternallyStored() returns true. More...
 
std::string getExternalStorageFileAbsolutePath () const
 Only if isExternallyStored() returns true. More...
 
void forceLoad () const
 For external storage image objects only, this method makes sure the image is loaded in memory. More...
 
void unload () const MRPT_NO_THROWS
 For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded). More...
 

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. More...
 
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. More...
 
void loadFromIplImage (void *iplImage)
 Reads the image from a OpenCV IplImage object (making a COPY). More...
 
void setFromIplImage (void *iplImage)
 Reads the image from a OpenCV IplImage object (WITHOUT making a copy). More...
 
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. More...
 
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). More...
 
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) Matrix indexes are assumed to be in this order: M(row,column) More...
 
template<typename Derived >
void setFromRGBMatrices (const Eigen::MatrixBase< Derived > &m_r, const Eigen::MatrixBase< Derived > &m_g, const Eigen::MatrixBase< Derived > &m_b, bool matrix_is_normalized=true)
 Set the image from RGB matrices, given the pixels in the range [0,1] (normalized=true) or [0,255] (normalized=false) Matrix indexes are assumed to be in this order: M(row,column) More...
 
void loadFromStreamAsJPEG (CStream &in)
 Reads the image from a binary stream containing a binary jpeg file. More...
 
bool loadFromFile (const std::string &fileName, int isColor=-1)
 Load image from a file, whose format is determined from the extension (internally uses OpenCV). More...
 
bool loadFromXPM (const char **xpm_array, bool swap_rb=true)
 Loads the image from an XPM array, as #include'd from a ".xpm" file. More...
 
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). More...
 
void saveToStreamAsJPEG (mrpt::utils::CStream &out, const int jpeg_quality=95) const
 Save image to binary stream as a JPEG (.jpg) compressed format. More...
 
static bool loadTGA (const std::string &fileName, mrpt::utils::CImage &out_RGB, mrpt::utils::CImage &out_alpha)
 Loads a TGA true-color RGBA image as two CImage objects, one for the RGB channels plus a separate gray-level image with A channel. More...
 

Member Typedef Documentation

typedef CImagePtr mrpt::utils::CImage::SmartPtr

A typedef for the associated smart pointer

Definition at line 103 of file CImage.h.

Member Enumeration Documentation

Definition of pen styles.

Enumerator
psSolid 
psDash 
psDot 
psDashDot 
psDashDotDot 

Definition at line 53 of file CCanvas.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  )
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 142 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 155 of file CImage.h.

References grayscale(), isColor(), and MRPT_UNUSED_PARAM.

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

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

CObject* mrpt::utils::CObject::clone ( ) const
inlineinherited

Cloning interface for smart pointers.

Definition at line 139 of file CObject.h.

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::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 =
Exceptions
CExceptionExternalImageNotFoundIf the external image couldn't be loaded.
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::CCanvas::cross ( int  x0,
int  y0,
const mrpt::utils::TColor  color,
char  type,
unsigned int  size = 5,
unsigned int  width = 1 
)
inherited

Draw a cross.

Parameters
x0The point x coordinate
y0The point y coordinate
colorThe color of the cross
sizeThe size of the cross
typeThe cross type. It could be: 'x', '+' or ':'(like '+' but clear at the center dot)
widthThe desired width of the cross (this is IGNORED yet)
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,
unsigned int  lines_width = 1,
unsigned int  circles_radius = 4 
)

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

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

Reimplemented from mrpt::utils::CCanvas.

template<class FEATURELIST >
void mrpt::utils::CCanvas::drawFeatures ( const FEATURELIST &  list,
const TColor color = TColor::red,
const bool  showIDs = false,
const bool  showResponse = false 
)
inlineinherited

Draws a set of marks (or scaled circles for features with scale) onto the image, given a generic container of features.

The class of FEATURELIST can be:

See Also
drawFeaturesSimple

Definition at line 322 of file CCanvas.h.

References mrpt::format(), mrpt::utils::TColor::red, and mrpt::utils::round().

template<class FEATURELIST >
void mrpt::utils::CCanvas::drawFeaturesSimple ( const FEATURELIST &  list,
const TColor color = TColor::red,
const int  cross_size = 5 
)
inlineinherited

Draws a set of marks onto the image, given a generic container of entities having just "x" and "y" fields.

The class of FEATURELIST can be, for example, std::vector<mrpt::math::TPoint2D>, std::vector<TPixelCoordsf> or mrpt::vision::CFeatureList

See Also
drawFeatures

Definition at line 304 of file CCanvas.h.

References mrpt::utils::round().

virtual void mrpt::utils::CCanvas::drawImage ( int  x,
int  y,
const utils::CImage img 
)
virtualinherited

Draws an image as a bitmap at a given position.

Parameters
x0The top-left corner x coordinates on this canvas where the image is to be drawn
y0The top-left corner y coordinates on this canvas where the image is to be drawn
imgThe image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented in mrpt::utils::CEnhancedMetaFile.

Referenced by mrpt::utils::CEnhancedMetaFile::drawImage().

virtual void mrpt::utils::CCanvas::drawImage ( int  x,
int  y,
const utils::CImage img,
float  rotation,
float  scale 
)
virtualinherited

Draws an image as a bitmap at a given position, with some custom scale and rotation changes.

Parameters
x0The top-left corner x coordinates on this canvas where the image is to be drawn
y0The top-left corner y coordinates on this canvas where the image is to be drawn
rotationThe rotation in radians, positive values being anti-clockwise direction, 0 is the normal position.
scaleThe scale factor, e.g. 2 means twice the original size.
imgThe image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropiate manner.

Reimplemented in mrpt::utils::CEnhancedMetaFile.

virtual mrpt::utils::CObject* mrpt::utils::CImage::duplicate ( ) const
virtual

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

Implements mrpt::utils::CObject.

mrpt::utils::CObjectPtr mrpt::utils::CObject::duplicateGetSmartPtr ( ) const
inlineinherited

Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object will exist as long as any copy of this smart pointer).

Definition at line 136 of file CObject.h.

template<class MATRIX2X2 >
void mrpt::utils::CCanvas::ellipseGaussian ( const MATRIX2X2 *  cov2D,
const double  mean_x,
const double  mean_y,
double  confIntervalStds = 2,
const mrpt::utils::TColor color = mrpt::utils::TColor(255,255,255),
unsigned int  width = 1,
int  nEllipsePoints = 20 
)
inlineinherited

Draws an ellipse representing a given confidence interval of a 2D Gaussian distribution.

Parameters
mean_xThe x coordinate of the center point of the ellipse.
mean_yThe y coordinate of the center point of the ellipse.
cov2DA 2x2 covariance matrix.
confIntervalStdsHow many "sigmas" for the confidence level (i.e. 2->95%, 3=99.97%,...)
colorThe color of the ellipse
widthThe desired width of the line (this is IGNORED in this virtual class)
nEllipsePointsThe number of points to generate to approximate the ellipse shape.
Exceptions
std::exceptionOn an invalid matrix.

Definition at line 255 of file CCanvas.h.

References M_2PI, MRPT_END_WITH_CLEAN_UP, MRPT_START, and mrpt::utils::round().

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

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

Note
RGB images are first converted to HSV color space, then equalized for brightness (V)
void mrpt::utils::CImage::equalizeHistInPlace ( )

Equalize the image histogram, replacing the original image.

Note
RGB images are first converted to HSV color space, then equalized for brightness (V)
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
virtual void mrpt::utils::CCanvas::filledRectangle ( int  x0,
int  y0,
int  x1,
int  y1,
const mrpt::utils::TColor  color 
)
virtualinherited

Draws a filled rectangle.

Parameters
x0The top-left x coordinate
y0The top-left y coordinate
x1The right-bottom x coordinate
y1The right-bottom y coordinate
colorThe color of the rectangle fill This method may be redefined in some classes implementing this interface in a more appropiate manner.
See Also
rectangle
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 ( ) const
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 696 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()

Referenced by mrpt::obs::detail::project3DPointsFromDepthImageInto().

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

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

Definition at line 522 of file CImage.h.

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

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

Definition at line 527 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::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].

Matrix indexes in this order: M(row,column)

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.

void mrpt::utils::CImage::getAsRGBMatrices ( mrpt::math::CMatrixFloat outMatrixR,
mrpt::math::CMatrixFloat outMatrixG,
mrpt::math::CMatrixFloat outMatrixB,
bool  doResize = true,
int  x_min = 0,
int  y_min = 0,
int  x_max = -1,
int  y_max = -1 
) const

Returns the image as RGB matrices with pixel values in the range [0,1].

Matrix indexes in this order: M(row,column)

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

See Also
setChannelsOrder, swapRB
std::string mrpt::utils::CImage::getExternalStorageFile ( ) const
inline

< Only if isExternallyStored() returns true.

See Also
getExternalStorageFileAbsolutePath

Definition at line 678 of file CImage.h.

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

Only if isExternallyStored() returns true.

See Also
getExternalStorageFile
std::string mrpt::utils::CImage::getExternalStorageFileAbsolutePath ( ) const
inline

Only if isExternallyStored() returns true.

See Also
getExternalStorageFile

Definition at line 687 of file CImage.h.

size_t mrpt::utils::CImage::getHeight ( ) const
virtual
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
size_t mrpt::utils::CImage::getRowStride ( ) const

Returns the row stride of the image: this is the number of bytes between two consecutive rows.

You can access the pointer to the first row with get_unsafe(0,0)

See Also
getSize, get_unsafe
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 574 of file CImage.h.

size_t mrpt::utils::CImage::getWidth ( ) const
virtual
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(), and mrpt::obs::detail::project3DPointsFromDepthImageInto().

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

See setExternalStorage().

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

Referenced by mrpt::maps::COccupancyGridMap2D::saveAsBitmapFileWithLandmarks().

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

See KLT_response_optimized for more details on the internal optimizations of this method, but this graph shows a general view:

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.

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

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,loadFromXPM, loadTGA
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
bool mrpt::utils::CImage::loadFromXPM ( const char **  xpm_array,
bool  swap_rb = true 
)

Loads the image from an XPM array, as #include'd from a ".xpm" file.

Parameters
[in]swap_rbSwaps red/blue channels from loaded image. Seems to be always needed, so it's enabled by default.
See Also
loadFromFile
Returns
false on any error
static bool mrpt::utils::CImage::loadTGA ( const std::string &  fileName,
mrpt::utils::CImage out_RGB,
mrpt::utils::CImage out_alpha 
)
static

Loads a TGA true-color RGBA image as two CImage objects, one for the RGB channels plus a separate gray-level image with A channel.

Returns
true on success
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 the brightness range of an image without using histogram Only for one channel images.

See Also
equalizeHist
void mrpt::utils::CImage::operator delete ( void *  ptr) throw ()
inline

Definition at line 103 of file CImage.h.

void mrpt::utils::CImage::operator delete ( void *  memory,
void *  ptr 
) throw ()
inline

Definition at line 103 of file CImage.h.

void mrpt::utils::CImage::operator delete ( void *  ptr,
const std::nothrow_t &   
) throw ()
inline

Definition at line 103 of file CImage.h.

void mrpt::utils::CImage::operator delete[] ( void *  ptr) throw ()
inline

Definition at line 103 of file CImage.h.

static void* mrpt::utils::CImage::operator new ( size_t  size,
void *  ptr 
)
inlinestatic

Definition at line 103 of file CImage.h.

void* mrpt::utils::CImage::operator new ( size_t  size)
inline

Definition at line 103 of file CImage.h.

void* mrpt::utils::CImage::operator new ( size_t  size,
const std::nothrow_t &   
) throw ()
inline

Definition at line 103 of file CImage.h.

void* mrpt::utils::CImage::operator new[] ( size_t  size)
inline

Definition at line 103 of file CImage.h.

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::readFromStream ( mrpt::utils::CStream in,
int  version 
)
protectedvirtual

Introduces a pure virtual method responsible for loading from a CStream This can not be used directly be users, instead use "stream >> object;" for reading it from a stream or "stream >> object_ptr;" if the class is unknown apriori.

Parameters
inThe input binary stream where the object data must read from.
versionThe version of the object stored in the stream: use this version number in your code to know how to read the incoming data.
Exceptions
std::exceptionOn any error, see CStream::ReadBuffer
See Also
CStream

Implements mrpt::utils::CSerializable.

void mrpt::utils::CCanvas::rectangle ( int  x0,
int  y0,
int  x1,
int  y1,
const mrpt::utils::TColor  color,
unsigned int  width = 1 
)
inherited

Draws a rectangle (an empty rectangle, without filling)

Parameters
x0The top-left x coordinate
y0The top-left y coordinate
x1The right-bottom x coordinate
y1The right-bottom y coordinate
colorThe color of the line
widthThe desired width of the line.
See Also
filledRectangle

Referenced by mrpt::maps::COccupancyGridMap2D::saveAsBitmapFileWithLandmarks().

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)
See Also
mrpt::vision::CUndistortMap
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)
See Also
mrpt::vision::CUndistortMap
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
mrpt::vision::CStereoRectifyMap, mrpt::vision::computeStereoRectificationMaps
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 209 of file CImage.h.

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

Referenced by mrpt::maps::COccupancyGridMap2D::saveAsBitmapFileWithLandmarks().

void mrpt::utils::CImage::saveToStreamAsJPEG ( mrpt::utils::CStream out,
const int  jpeg_quality = 95 
) const

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

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

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

Exceptions
std::exceptionOn odd size
See Also
scaleHalf, scaleImage

Definition at line 312 of file CImage.h.

References mrpt::utils::UNINITIALIZED_IMAGE.

void mrpt::utils::CImage::scaleDouble ( CImage out_image) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

CImage mrpt::utils::CImage::scaleHalf ( ) const
inline

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

Exceptions
std::exceptionOn odd size
See Also
scaleDouble, scaleImage, scaleHalfSmooth

Definition at line 282 of file CImage.h.

References mrpt::utils::UNINITIALIZED_IMAGE.

void mrpt::utils::CImage::scaleHalf ( CImage out_image) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

CImage mrpt::utils::CImage::scaleHalfSmooth ( ) const
inline

Returns a new image scaled down to half its original size (averaging between every two rows)

Exceptions
std::exceptionOn odd size.

See Also
scaleDouble, scaleImage, scaleHalf

Definition at line 297 of file CImage.h.

References mrpt::utils::UNINITIALIZED_IMAGE.

void mrpt::utils::CImage::scaleHalfSmooth ( CImage out_image) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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::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
virtual void mrpt::utils::CCanvas::selectTextFont ( const std::string &  fontName)
virtualinherited

Select the current font used when drawing text.

Parameters
fontNameThe name of the font

Valid font names:

  • 5x7
  • 6x13
  • 6x13B
  • 6x13O
  • 9x15 (Default at start-up)
  • 9x15B
  • 10x20
  • 18x18ja (Asian characters for UTF-8 strings - Only available if MRPT is built with MRPT_HAS_ASIAN_FONTS = true)

See Also
textOut, The example in this page.
void mrpt::utils::CImage::setChannelsOrder_BGR ( )

Marks the channel ordering in a color image as "BGR" (this doesn't actually modify the image data, just the format description)

See Also
getChannelsOrder, swapRB
void mrpt::utils::CImage::setChannelsOrder_RGB ( )

Marks the channel ordering in a color image as "RGB" (this doesn't actually modify the image data, just the format description)

See Also
getChannelsOrder, swapRB
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 744 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) Matrix indexes are assumed to be in this order: M(row,column)

See Also
getAsMatrix

Definition at line 751 of file CImage.h.

References get_unsafe(), MRPT_END, MRPT_START, and exprtk::details::x().

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_t >::updateRangeImageViewport().

template<typename Derived >
void mrpt::utils::CImage::setFromRGBMatrices ( const Eigen::MatrixBase< Derived > &  m_r,
const Eigen::MatrixBase< Derived > &  m_g,
const Eigen::MatrixBase< Derived > &  m_b,
bool  matrix_is_normalized = true 
)
inline

Set the image from RGB matrices, given the pixels in the range [0,1] (normalized=true) or [0,255] (normalized=false) Matrix indexes are assumed to be in this order: M(row,column)

See Also
getAsRGBMatrices

Definition at line 779 of file CImage.h.

References ASSERT_, get_unsafe(), MRPT_END, MRPT_START, and exprtk::details::x().

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
virtual void mrpt::utils::CCanvas::textOut ( int  x0,
int  y0,
const std::string &  str,
const mrpt::utils::TColor  color 
)
virtualinherited

Renders 2D text using bitmap fonts.

Parameters
x0The x coordinates
y0The y coordinates
strThe string to put. If using UNICODE characters, use UTF-8 encoding.
colorThe text color
See Also
selectTextFont

Reimplemented in mrpt::utils::CEnhancedMetaFile.

Referenced by mrpt::maps::COccupancyGridMap2D::saveAsBitmapFileWithLandmarks().

void mrpt::utils::CCanvas::triangle ( int  x0,
int  y0,
int  size,
const mrpt::utils::TColor  color,
bool  inferior = true,
unsigned int  width = 1 
)
inherited

Draws a triangle.

Parameters
x0The triangle center x coordinate
y0The triangle center y coordinate
sizeThe size of the triangle
colorThe color of the line
inferiorThe position of the triangle
widthThe desired width of the line.
See Also
triangle
void mrpt::utils::CImage::unload ( ) const

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
virtual mxArray* mrpt::utils::CSerializable::writeToMatlab ( ) const
inlinevirtualinherited

Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.

Returns
A new mxArray (caller is responsible of memory freeing) or NULL is class does not support conversion to MATLAB.

Definition at line 79 of file CSerializable.h.

void mrpt::utils::CImage::writeToStream ( mrpt::utils::CStream out,
int *  getVersion 
) const
protectedvirtual

Introduces a pure virtual method responsible for writing to a CStream.

This can not be used directly be users, instead use "stream << object;" for writing it to a stream.

Parameters
outThe output binary stream where object must be dumped.
getVersionIf NULL, the object must be dumped. If not, only the version of the object dump must be returned in this pointer. This enables the versioning of objects dumping and backward compatibility with previously stored data.
Exceptions
std::exceptionOn any error, see CStream::WriteBuffer
See Also
CStream

Implements mrpt::utils::CSerializable.

Member Data Documentation

mrpt::utils::CLASSINIT mrpt::utils::CImage::_init_CImage
staticprotected

Definition at line 103 of file CImage.h.

mrpt::utils::TRuntimeClassId mrpt::utils::CImage::classCImage
static

Definition at line 103 of file CImage.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CObject::classCObject
staticinherited

Definition at line 124 of file CObject.h.

const mrpt::utils::TRuntimeClassId mrpt::utils::CSerializable::classCSerializable
staticinherited

Definition at line 42 of file CSerializable.h.

const mrpt::utils::TRuntimeClassId* mrpt::utils::CImage::classinfo
static

Definition at line 103 of file CImage.h.

bool mrpt::utils::CImage::DISABLE_JPEG_COMPRESSION
static

By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed to save space.

If for some reason you prefer storing RAW image data, disable this feature by setting this flag to true. (Default = false)

Definition at line 192 of file CImage.h.

bool mrpt::utils::CImage::DISABLE_ZIP_COMPRESSION
static

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.

(Default = false)

Definition at line 188 of file CImage.h.

std::string mrpt::utils::CImage::IMAGES_PATH_BASE
static

By default, ".".

See Also
setExternalStorage

Definition at line 673 of file CImage.h.

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

The internal IplImage pointer to the actual image content.

Definition at line 917 of file CImage.h.

std::string mrpt::utils::CImage::m_externalFile
mutableprotected

The file name of a external storage image.

Definition at line 926 of file CImage.h.

bool mrpt::utils::CImage::m_imgIsExternalStorage
mutableprotected

Set to true only when using setExternalStorage.

See Also
setExternalStorage

Definition at line 925 of file CImage.h.

bool mrpt::utils::CImage::m_imgIsReadOnly
protected

Set to true only when using setFromIplImageReadOnly.

See Also
setFromIplImageReadOnly

Definition at line 921 of file CImage.h.

std::string mrpt::utils::CCanvas::m_selectedFont
protectedinherited

The selected font name.

Definition at line 43 of file CCanvas.h.

const uint32_t* mrpt::utils::CCanvas::m_selectedFontBitmaps
protectedinherited

Direct access to character bitmaps.

Definition at line 45 of file CCanvas.h.

int mrpt::utils::CImage::SERIALIZATION_JPEG_QUALITY
static

Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB images.

(Default = 95)

Definition at line 196 of file CImage.h.




Page generated by Doxygen 1.8.3.1 for MRPT 1.5.0 Git: 7b95fe2 Thu Jan 19 22:55:15 2017 +0100 at Fri Jan 20 00:00:19 CET 2017 Hosted on:
SourceForge.net Logo