A class for storing images as grayscale or RGB bitmaps.
File I/O is supported in two different ways:
How to create color/grayscale images:
CImage img1(width, height, CH_GRAY ); // Grayscale image (8U1C) CImage img2(width, height, CH_RGB ); // RGB image (8U3C)
Additional notes:
CImagePtr myImgPtr = CImagePtr( new CImage(...) );
For many computer vision functions that use CImage as its image data type, see mrpt::vision.
#include <mrpt/utils/CImage.h>
Public Member Functions | |
Constructors & destructor | |
CImage () | |
Default constructor: initialize an 1x1 RGB image. | |
CImage (unsigned int width, unsigned int height, TImageChannels nChannels=CH_RGB, bool originTopLeft=true) | |
Constructor for a given image size and type. | |
CImage (const CImage &o) | |
Copy constructor, makes a full copy of the original image contents (unless it was externally stored, in that case, this new image will just point to the same image file). | |
CImage (TConstructorFlags_CImage constructor_flag) | |
Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL). | |
CImage (const CImage &other_img, TConstructorFlags_CImage constructor_flag) | |
Fast constructor of a grayscale version of another image, making a reference to the original image if it already was in grayscale, or otherwise creating a new grayscale image and converting the original image into it. | |
CImage (void *iplImage) | |
Constructor from an IPLImage*, making a copy of the image. | |
template<typename Derived > | |
CImage (const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized) | |
Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false) | |
virtual | ~CImage () |
Destructor: | |
Manipulate the image contents or size, various computer-vision methods (image filters, undistortion, etc.) | |
void | resize (unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft) |
Changes the size of the image, erasing previous contents (does NOT scale its current content, for that, see scaleImage). | |
void | scaleImage (unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC) |
Scales this image to a new size, interpolating as needed. | |
void | scaleImage (CImage &out_img, unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC) const |
Scales this image to a new size, interpolating as needed, saving the new image in a different output object. | |
void | rotateImage (double angle_radians, unsigned int center_x, unsigned int center_y, double scale=1.0) |
Rotates the image by the given angle around the given center point, with an optional scale factor. | |
void | setPixel (int x, int y, size_t color) |
Changes the value of the pixel (x,y). | |
void | setOriginTopLeft (bool val) |
Changes the property of the image stating if the top-left corner (vs. | |
virtual void | line (int x0, int y0, int x1, int y1, const mrpt::utils::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) |
Draws a line. | |
void | drawCircle (int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1) |
Draws a circle of a given radius. | |
void | equalizeHistInPlace () |
Equalize the image histogram, replacing the original image. | |
void | equalizeHist (CImage &outImg) const |
Equalize the image histogram, saving the new image in the given output object. | |
CImage | scaleHalf () const |
Returns a new image scaled down to half its original size. | |
CImage | scaleDouble () const |
Returns a new image scaled up to double its original size. | |
void | update_patch (const CImage &patch, const unsigned int col, const unsigned int row) |
Update a part of this image with the "patch" given as argument. | |
void | extract_patch (CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const |
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten). | |
float | correlate (const CImage &img2int, int width_init=0, int height_init=0) const |
Computes the correlation coefficient (returned as val), between two images This function use grayscale images only img1, img2 must be same size (by AJOGD @ DEC-2006) | |
void | cross_correlation (const CImage &patch_img, size_t &u_max, size_t &v_max, double &max_val, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, CImage *out_corr_image=NULL) const |
Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate. | |
void | cross_correlation_FFT (const CImage &in_img, math::CMatrixFloat &out_corr, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, float biasThisImg=0, float biasInImg=0) const |
Computes the correlation matrix between this image and another one. | |
void | normalize () |
Optimize de brightness range of a image without using histogram Only for one channel images. | |
void | flipVertical (bool also_swapRB=false) |
Flips vertically the image. | |
void | swapRB () |
Swaps red and blue channels. | |
void | rectifyImage (CImage &out_img, const mrpt::utils::TCamera &cameraParams) const |
Rectify (un-distort) the image according to some camera parameters, and returns an output un-distorted image. | |
void | rectifyImage (CImage &out_img, const math::CMatrixDouble33 &cameraMatrix, const vector_double &distCoeff) const |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image. | |
void | rectifyImageInPlace (const mrpt::utils::TCamera &cameraParams) |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image. | |
void | rectifyImageInPlace (const math::CMatrixDouble33 &cameraMatrix, const vector_double &distCoeff) |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image. | |
void | rectifyImageInPlace (void *mapX, void *mapY) |
Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed rectification maps. | |
void | filterMedian (CImage &out_img, int W=3) const |
Filter the image with a Median filter with a window size WxW, returning the filtered image in out_img. | |
void | filterMedianInPlace (int W=3) |
Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered one. | |
void | filterGaussianInPlace (int W=3, int H=3) |
Filter the image with a Gaussian filter with a window size WxH, returning the filtered image in out_img. | |
void | filterGaussian (CImage &out_img, int W=3, int H=3) const |
Filter the image with a Gaussian filter with a window size WxH, replacing "this" image by the filtered one. | |
bool | drawChessboardCorners (std::vector< TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y) |
Draw onto this image the detected corners of a chessboard. | |
void | joinImagesHorz (const CImage &im1, const CImage &im2) |
Joins two images side-by-side horizontally. | |
float | KLT_response (const unsigned int x, const unsigned int y, const unsigned int half_window_size) const |
Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids converting to grayscale internally). | |
Copy, move & swap operations | |
CImage & | operator= (const CImage &o) |
Copy operator (if the image is externally stored, the writen image will be such as well). | |
void | copyFromForceLoad (const CImage &o) |
Copies from another image, and, if that one is externally stored, the image file will be actually loaded into memory in "this" object. | |
void | copyFastFrom (CImage &o) |
Moves an image from another object, erasing the origin image in the process (this is much faster than copying) | |
void | swap (CImage &o) |
Very efficient swap of two images (just swap the internal pointers) | |
Access to image contents (IplImage structure and raw pixels). | |
template<typename T > | |
const T * | getAs () const |
Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. | |
template<typename T > | |
T * | getAs () |
Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. | |
void * | getAsIplImage () const |
Returns a pointer to an OpenCV's IplImage struct containing the image, which is linked to this class: free neigther that pointer nor this class until they are not required anymore, since this class is in charge of freeing the memory buffers inside of the returned image. | |
unsigned char * | get_unsafe (unsigned int col, unsigned int row, unsigned int channel=0) const |
Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates. | |
float | getAsFloat (unsigned int col, unsigned int row, unsigned int channel) const |
Returns the contents of a given pixel at the desired channel, in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image. | |
float | getAsFloat (unsigned int col, unsigned int row) const |
Returns the contents of a given pixel (for gray-scale images, in color images the gray scale equivalent is computed for the pixel), in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image. | |
unsigned char * | operator() (unsigned int col, unsigned int row, unsigned int channel=0) const |
Returns a pointer to a given pixel information. | |
Query image properties | |
size_t | getWidth () const |
Returns the width of the image in pixels. | |
size_t | getHeight () const |
Returns the height of the image in pixels. | |
void | getSize (TImageSize &s) const |
Return the size of the image. | |
TImageSize | getSize () const |
Return the size of the image. | |
float | getMaxAsFloat () const |
Return the maximum pixel value of the image, as a float value in the range [0,1]. | |
bool | isColor () const |
Returns true if the image is RGB, false if it is grayscale. | |
bool | isOriginTopLeft () const |
Returns true if the coordinates origin is top-left, or false if it is bottom-left. | |
const char * | getChannelsOrder () const |
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering. | |
TImageChannels | getChannelCount () const |
Returns the number of channels, typically 1 (GRAY) or 3 (RGB) | |
void | getAsMatrix (mrpt::math::CMatrixFloat &outMatrix, bool doResize=true, int x_min=0, int y_min=0, int x_max=-1, int y_max=-1) const |
Returns the image as a matrix with pixel grayscale values in the range [0,1]. | |
void | getAsMatrixTiled (math::CMatrix &outMatrix) const |
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to fill the entire size of the matrix on input. | |
Set, load & save methods | |
void | loadFromMemoryBuffer (unsigned int width, unsigned int height, bool color, unsigned char *rawpixels, bool swapRedBlue=false) |
Reads the image from raw pixels buffer in memory. | |
void | loadFromMemoryBuffer (unsigned int width, unsigned int height, unsigned int bytesPerRow, unsigned char *red, unsigned char *green, unsigned char *blue) |
Reads a color image from three raw pixels buffers in memory. | |
void | loadFromIplImage (void *iplImage) |
Reads the image from a OpenCV IplImage object (making a COPY). | |
void | setFromIplImage (void *iplImage) |
Reads the image from a OpenCV IplImage object (WITHOUT making a copy). | |
void | setFromIplImageReadOnly (void *iplImage) |
Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image cannot be modified, just read. | |
void | setFromImageReadOnly (const CImage &other_img) |
Sets the internal IplImage pointer to that of another given image, WITHOUT making a copy, and from now on the image cannot be modified in this object (it will be neither freed, so the memory responsibility will still be of the original image object). | |
template<typename Derived > | |
void | setFromMatrix (const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized=true) |
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false) | |
void | loadFromStreamAsJPEG (CStream &in) |
Reads the image from a binary stream containing a binary jpeg file. | |
bool | loadFromFile (const std::string &fileName, int isColor=-1) |
Load image from a file, whose format is determined from the extension (internally uses OpenCV). | |
bool | saveToFile (const std::string &fileName, int jpeg_quality=95) const |
Save the image to a file, whose format is determined from the extension (internally uses OpenCV). | |
void | saveToStreamAsJPEG (CStream &out) const |
Save image to binary stream as a JPEG (.jpg) compresed format. | |
Color/Grayscale conversion | |
CImage | grayscale () const |
Returns a grayscale version of the image, or itself if it is already a grayscale image. | |
void | grayscale (CImage &ret) const |
Returns a grayscale version of the image, or itself if it is already a grayscale image. | |
void | colorImage (CImage &ret) const |
Returns a RGB version of the grayscale image, or itself if it is already a RGB image. | |
void | colorImageInPlace () |
Replaces this grayscale image with a RGB version of it. | |
void | grayscaleInPlace () |
Replaces the image with a grayscale version of it. | |
Static Public Attributes | |
static bool | DISABLE_ZIP_COMPRESSION |
By default, when storing images through the CSerializable interface, grayscale images will be ZIP compressed if they are larger than 16Kb: this flag can be turn on to disable ZIP compression and gain speed versus occupied space. | |
Protected Member Functions | |
void | changeSize (unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft) |
Resize the buffers in "img" to accomodate a new image size and/or format. | |
void | releaseIpl (bool thisIsExternalImgUnload=false) MRPT_NO_THROWS |
Release the internal IPL image, if not NULL or read-only. | |
void | makeSureImageIsLoaded () const throw (std::exception,utils::CExceptionExternalImageNotFound ) |
Checks if the image is of type "external storage", and if so and not loaded yet, load it. | |
Protected Attributes | |
Data members | |
void * | img |
The internal IplImage pointer to the actual image content. | |
bool | m_imgIsReadOnly |
Set to true only when using setFromIplImageReadOnly. | |
bool | m_imgIsExternalStorage |
Set to true only when using setExternalStorage. | |
std::string | m_externalFile |
The file name of a external storage image. | |
RTTI stuff | |
typedef CImagePtr | SmartPtr |
static mrpt::utils::CLASSINIT | _init_CImage |
static mrpt::utils::TRuntimeClassId | classCImage |
static const mrpt::utils::TRuntimeClassId * | classinfo |
static const mrpt::utils::TRuntimeClassId * | _GetBaseClass () |
virtual const mrpt::utils::TRuntimeClassId * | GetRuntimeClass () const |
Returns information about the class of an object in runtime. | |
virtual mrpt::utils::CObject * | duplicate () const |
Returns a copy of the object, indepently of its class. | |
static mrpt::utils::CObject * | CreateObject () |
static CImagePtr | Create () |
External storage-mode methods | |
static std::string | IMAGES_PATH_BASE |
By default, ".". | |
void | setExternalStorage (const std::string &fileName) MRPT_NO_THROWS |
By using this method the image is marked as referenced to an external file, which will be loaded only under demand. | |
bool | isExternallyStored () const MRPT_NO_THROWS |
See setExternalStorage(). | |
std::string | getExternalStorageFile () const MRPT_NO_THROWS |
< Only if isExternallyStored() returns true. | |
void | getExternalStorageFileAbsolutePath (std::string &out_path) const |
Only if isExternallyStored() returns true. | |
std::string | getExternalStorageFileAbsolutePath () const |
Only if isExternallyStored() returns true. | |
void | forceLoad () |
For external storage image objects only, this method makes sure the image is loaded in memory. | |
void | unload () MRPT_NO_THROWS |
For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded). |
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 |
||
) |
mrpt::utils::CImage::CImage | ( | const CImage & | o | ) |
Copy constructor, makes a full copy of the original image contents (unless it was externally stored, in that case, this new image will just point to the same image file).
mrpt::utils::CImage::CImage | ( | TConstructorFlags_CImage | constructor_flag | ) | [inline] |
Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL).
Use only when you know the image will be soon be assigned another image. Example of usage:
CImage myImg(UNINITIALIZED_IMAGE);
mrpt::utils::CImage::CImage | ( | const CImage & | other_img, |
TConstructorFlags_CImage | constructor_flag | ||
) | [inline] |
Fast constructor of a grayscale version of another image, making a reference to the original image if it already was in grayscale, or otherwise creating a new grayscale image and converting the original image into it.
It's very important to keep in mind that the original image can't be destroyed before the new object being created with this constructor. Example of usage:
void my_func(const CImage &in_img) { const CImage gray_img(in_img, FAST_REF_OR_CONVERT_TO_GRAY); // We can now operate on "gray_img" being sure it's in grayscale. }
Definition at line 156 of file CImage.h.
References grayscale(), and isColor().
mrpt::utils::CImage::CImage | ( | void * | iplImage | ) |
Constructor from an IPLImage*, making a copy of the image.
mrpt::utils::CImage::CImage | ( | const Eigen::MatrixBase< Derived > & | m, |
bool | matrix_is_normalized | ||
) | [inline, explicit] |
Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false)
virtual mrpt::utils::CImage::~CImage | ( | ) | [virtual] |
Destructor:
static const mrpt::utils::TRuntimeClassId* mrpt::utils::CImage::_GetBaseClass | ( | ) | [static, protected] |
Reimplemented from mrpt::utils::CSerializable.
void mrpt::utils::CImage::changeSize | ( | unsigned int | width, |
unsigned int | height, | ||
TImageChannels | nChannels, | ||
bool | originTopLeft | ||
) | [protected] |
Resize the buffers in "img" to accomodate a new image size and/or format.
void mrpt::utils::CImage::colorImage | ( | CImage & | ret | ) | const |
Returns a RGB version of the grayscale image, or itself if it is already a RGB image.
Referenced by mrpt::gui::CDisplayWindow::showImageAndPoints(), and mrpt::gui::CDisplayWindow::showTiledImageAndPoints().
void mrpt::utils::CImage::colorImageInPlace | ( | ) |
Replaces this grayscale image with a RGB version of it.
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)
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.
float mrpt::utils::CImage::correlate | ( | const CImage & | img2int, |
int | width_init = 0 , |
||
int | height_init = 0 |
||
) | const |
Computes the correlation coefficient (returned as val), between two images This function use grayscale images only img1, img2 must be same size (by AJOGD @ DEC-2006)
static CImagePtr mrpt::utils::CImage::Create | ( | ) | [static] |
static mrpt::utils::CObject* mrpt::utils::CImage::CreateObject | ( | ) | [static] |
void mrpt::utils::CImage::cross_correlation | ( | const CImage & | patch_img, |
size_t & | u_max, | ||
size_t & | v_max, | ||
double & | max_val, | ||
int | u_search_ini = -1 , |
||
int | v_search_ini = -1 , |
||
int | u_search_size = -1 , |
||
int | v_search_size = -1 , |
||
CImage * | out_corr_image = NULL |
||
) | const |
Computes the correlation between this image and another one, encapsulating the openCV function cvMatchTemplate.
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 |
out_corr_image | If 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.
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) |
bool mrpt::utils::CImage::drawChessboardCorners | ( | std::vector< TPixelCoordf > & | cornerCoords, |
unsigned int | check_size_x, | ||
unsigned int | check_size_y | ||
) |
Draw onto this image the detected corners of a chessboard.
The length of cornerCoords must be the product of the two check_sizes.
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 |
void mrpt::utils::CImage::drawCircle | ( | int | x, |
int | y, | ||
int | radius, | ||
const mrpt::utils::TColor & | color = mrpt::utils::TColor(255, 255, 255) , |
||
unsigned int | width = 1 |
||
) |
Draws a circle of a given radius.
x | The center - x coordinate in pixels. |
y | The center - y coordinate in pixels. |
radius | The radius - in pixels. |
color | The color of the circle. |
width | The desired width of the line |
virtual mrpt::utils::CObject* mrpt::utils::CImage::duplicate | ( | ) | const [virtual] |
Returns a copy of the object, indepently of its class.
Implements mrpt::utils::CObject.
void mrpt::utils::CImage::equalizeHist | ( | CImage & | outImg | ) | const |
Equalize the image histogram, saving the new image in the given output object.
void mrpt::utils::CImage::equalizeHistInPlace | ( | ) |
Equalize the image histogram, replacing the original image.
void mrpt::utils::CImage::extract_patch | ( | CImage & | patch, |
const unsigned int | col = 0 , |
||
const unsigned int | row = 0 , |
||
const unsigned int | width = 1 , |
||
const unsigned int | height = 1 |
||
) | const |
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten).
The patch to extract starts at (col,row) and has the given dimensions.
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.
void mrpt::utils::CImage::forceLoad | ( | ) | [inline] |
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.
const T* mrpt::utils::CImage::getAs | ( | ) | const [inline] |
Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
T* mrpt::utils::CImage::getAs | ( | ) | [inline] |
Returns a pointer to an T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
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.
std::exception | On pixel coordinates out of bounds |
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.
std::exception | On pixel coordinates out of bounds |
void* mrpt::utils::CImage::getAsIplImage | ( | ) | const [inline] |
Returns a pointer to an OpenCV's IplImage struct containing the image, which is linked to this class: free neigther that pointer nor this class until they are not required anymore, since this class is in charge of freeing the memory buffers inside of the returned image.
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].
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) |
void mrpt::utils::CImage::getAsMatrixTiled | ( | math::CMatrix & | outMatrix | ) | const |
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to fill the entire size of the matrix on input.
TImageChannels mrpt::utils::CImage::getChannelCount | ( | ) | const |
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
const char* mrpt::utils::CImage::getChannelsOrder | ( | ) | const |
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
std::string mrpt::utils::CImage::getExternalStorageFile | ( | ) | const [inline] |
< Only if isExternallyStored() returns true.
std::string mrpt::utils::CImage::getExternalStorageFileAbsolutePath | ( | ) | const [inline] |
Only if isExternallyStored() returns true.
void mrpt::utils::CImage::getExternalStorageFileAbsolutePath | ( | std::string & | out_path | ) | const |
Only if isExternallyStored() returns true.
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].
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 |
TImageSize mrpt::utils::CImage::getSize | ( | ) | const [inline] |
size_t mrpt::utils::CImage::getWidth | ( | ) | const [virtual] |
Returns the width of the image in pixels.
Implements mrpt::utils::CCanvas.
Referenced by mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints().
CImage mrpt::utils::CImage::grayscale | ( | ) | const |
Returns a grayscale version of the image, or itself if it is already a grayscale image.
Referenced by CImage().
void mrpt::utils::CImage::grayscale | ( | CImage & | ret | ) | const |
Returns a grayscale version of the image, or itself if it is already a grayscale image.
void mrpt::utils::CImage::grayscaleInPlace | ( | ) |
Replaces the image with a grayscale version of it.
bool mrpt::utils::CImage::isColor | ( | ) | const |
Returns true if the image is RGB, false if it is grayscale.
Referenced by CImage().
bool mrpt::utils::CImage::isExternallyStored | ( | ) | const [inline] |
See setExternalStorage().
bool mrpt::utils::CImage::isOriginTopLeft | ( | ) | const |
Returns true if the coordinates origin is top-left, or false if it is bottom-left.
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)
im1 | [IN] The first image. |
im2 | [IN] The other image. |
Referenced by mrpt::gui::CDisplayWindow::showImagesAndMatchedPoints().
float mrpt::utils::CImage::KLT_response | ( | const unsigned int | x, |
const unsigned int | y, | ||
const unsigned int | half_window_size | ||
) | const |
Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids converting to grayscale internally).
virtual void mrpt::utils::CImage::line | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
const mrpt::utils::TColor | color, | ||
unsigned int | width = 1 , |
||
TPenStyle | penStyle = psSolid |
||
) | [virtual] |
Draws a line.
x0 | The starting point x coordinate |
y0 | The starting point y coordinate |
x1 | The end point x coordinate |
y1 | The end point y coordinate |
color | The color of the line |
width | The desired width of the line (this is IGNORED in this virtual class) This method may be redefined in some classes implementing this interface in a more appropiate manner. |
Reimplemented from mrpt::utils::CCanvas.
bool mrpt::utils::CImage::loadFromFile | ( | const std::string & | fileName, |
int | isColor = -1 |
||
) |
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
fileName | The file to read from. |
isColor | Specifies colorness of the loaded image:
|
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.
std::exception | On pixel coordinates out of bounds |
void mrpt::utils::CImage::makeSureImageIsLoaded | ( | ) | const throw (std::exception,utils::CExceptionExternalImageNotFound ) [protected] |
Checks if the image is of type "external storage", and if so and not loaded yet, load it.
void mrpt::utils::CImage::normalize | ( | ) |
Optimize de brightness range of a image without using histogram Only for one channel images.
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.
std::exception | On pixel coordinates out of bounds |
Copy operator (if the image is externally stored, the writen image will be such as well).
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.
out_img | The output rectified image |
cameraParams | The input camera params (containing the intrinsic and distortion parameters of the camera) |
Referenced by mrpt::vision::correctDistortion().
void mrpt::utils::CImage::rectifyImage | ( | CImage & | out_img, |
const math::CMatrixDouble33 & | cameraMatrix, | ||
const vector_double & | distCoeff | ||
) | const [inline] |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients and returns an output rectified image.
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 393 of file CImage.h.
References mrpt::utils::TCamera::intrinsicParams, and mrpt::utils::TCamera::setDistortionParamsVector().
void mrpt::utils::CImage::rectifyImageInPlace | ( | void * | mapX, |
void * | mapY | ||
) |
Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed rectification maps.
mapX,mapY | [IN] The pre-computed maps of the rectification (should be computed beforehand) |
void mrpt::utils::CImage::rectifyImageInPlace | ( | const math::CMatrixDouble33 & | cameraMatrix, |
const vector_double & | distCoeff | ||
) | [inline] |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.
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 410 of file CImage.h.
References mrpt::utils::TCamera::intrinsicParams, and mrpt::utils::TCamera::setDistortionParamsVector().
void mrpt::utils::CImage::rectifyImageInPlace | ( | const mrpt::utils::TCamera & | cameraParams | ) |
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coefficients, replacing "this" with the rectified image.
cameraParams | The input camera params (containing the intrinsic and distortion parameters of the camera) |
void mrpt::utils::CImage::releaseIpl | ( | bool | thisIsExternalImgUnload = false | ) | [protected] |
Release the internal IPL image, if not NULL or read-only.
void mrpt::utils::CImage::resize | ( | unsigned int | width, |
unsigned int | height, | ||
TImageChannels | nChannels, | ||
bool | originTopLeft | ||
) | [inline] |
Changes the size of the image, erasing previous contents (does NOT scale its current content, for that, see scaleImage).
Definition at line 199 of file CImage.h.
References ASSERT_.
void mrpt::utils::CImage::rotateImage | ( | double | angle_radians, |
unsigned int | center_x, | ||
unsigned int | center_y, | ||
double | scale = 1.0 |
||
) |
Rotates the image by the given angle around the given center point, with an optional scale factor.
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).
fileName | The file to write to. |
The supported formats are:
jpeg_quality | Only for JPEG files, the quality of the compression in the range [0-100]. Larger is better quality but slower. |
void mrpt::utils::CImage::saveToStreamAsJPEG | ( | CStream & | out | ) | const |
Save image to binary stream as a JPEG (.jpg) compresed format.
std::exception | On number of rows or cols equal to zero, or other errors. |
CImage mrpt::utils::CImage::scaleDouble | ( | ) | const |
Returns a new image scaled up to double its original size.
std::exception | On odd size |
CImage mrpt::utils::CImage::scaleHalf | ( | ) | const |
Returns a new image scaled down to half its original size.
std::exception | On odd size |
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.
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.
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 );
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.
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.
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)
Definition at line 722 of file CImage.h.
References ASSERT_, get_unsafe(), MRPT_END, and MRPT_START.
void mrpt::utils::CImage::setOriginTopLeft | ( | bool | val | ) |
Changes the property of the image stating if the top-left corner (vs.
bottom-left) is the coordinate reference.
void mrpt::utils::CImage::setPixel | ( | int | x, |
int | y, | ||
size_t | color | ||
) | [virtual] |
Changes the value of the pixel (x,y).
Pixel coordinates starts at the left-top corner of the image, and start in (0,0). The meaning of the parameter "color" depends on the implementation: it will usually be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray level. This method must support (x,y) values OUT of the actual image size without neither raising exceptions, nor leading to memory access errors.
Implements mrpt::utils::CCanvas.
void mrpt::utils::CImage::swap | ( | CImage & | o | ) |
Very efficient swap of two images (just swap the internal pointers)
void mrpt::utils::CImage::swapRB | ( | ) |
Swaps red and blue channels.
void mrpt::utils::CImage::unload | ( | ) |
For external storage image objects only, this method unloads the image from memory (or does nothing if already unloaded).
It does not need to be called explicitly, unless the user wants to save memory for images that will not be used often. If called for an image without the flag "external storage", it is simply ignored.
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.
std::exception | if patch pasted on the pixel (_row, _column) jut out of the image. |
mrpt::utils::CLASSINIT mrpt::utils::CImage::_init_CImage [static, protected] |
const mrpt::utils::TRuntimeClassId* mrpt::utils::CImage::classinfo [static] |
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.
The default value of this variable is "false".
std::string mrpt::utils::CImage::IMAGES_PATH_BASE [static] |
void* mrpt::utils::CImage::img [protected] |
std::string mrpt::utils::CImage::m_externalFile [mutable, protected] |
bool mrpt::utils::CImage::m_imgIsExternalStorage [mutable, protected] |
Set to true only when using setExternalStorage.
bool mrpt::utils::CImage::m_imgIsReadOnly [protected] |
Set to true only when using setFromIplImageReadOnly.
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011 |