129 bool originTopLeft =
true
159 else this->setFromImageReadOnly(other_img);
170 template <
typename Derived>
171 explicit inline CImage(
const Eigen::MatrixBase<Derived> &m,
bool matrix_is_normalized) : img(NULL),m_imgIsReadOnly(false), m_imgIsExternalStorage(false)
173 this->setFromMatrix(m,matrix_is_normalized);
215 changeSize(width,height,nChannels,originTopLeft);
231 void rotateImage(
double angle_radians,
unsigned int center_x,
unsigned int center_y,
double scale = 1.0 );
258 unsigned int width = 1,
275 void equalizeHistInPlace();
276 void equalizeHist(
CImage &outImg ) const;
285 this->scaleHalf(ret);
300 this->scaleHalfSmooth(ret);
315 this->scaleDouble(ret);
330 const unsigned int col,
331 const unsigned int row);
339 const unsigned int col=0,
340 const unsigned int row=0,
341 const unsigned int width=1,
342 const unsigned int height=1 )
const;
372 int u_search_size=-1,
373 int v_search_size=-1,
374 CImage *out_corr_image = NULL
396 int u_search_size=-1,
397 int v_search_size=-1,
398 float biasThisImg = 0,
461 std::vector<TPixelCoordf> &cornerCoords,
462 unsigned int check_size_x,
463 unsigned int check_size_y,
464 unsigned int lines_width = 1,
465 unsigned int circles_radius = 4
482 const unsigned int x,
483 const unsigned int y,
484 const unsigned int half_window_size )
const;
522 template <
typename T>
inline const T*
getAs()
const {
523 makeSureImageIsLoaded();
524 return static_cast<const T*
>(img);
527 template <
typename T>
inline T*
getAs(){
528 makeSureImageIsLoaded();
529 return static_cast<T*
>(img);
538 unsigned int channel=0)
const;
545 float getAsFloat(
unsigned int col,
unsigned int row,
unsigned int channel)
const;
558 unsigned char*
operator()(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
const;
617 bool doResize =
true,
636 bool doResize =
true,
680 return m_externalFile;
689 getExternalStorageFileAbsolutePath(tmp);
696 inline void forceLoad()
const { makeSureImageIsLoaded(); }
715 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
bool color,
unsigned char *rawpixels,
bool swapRedBlue = false );
720 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
unsigned int bytesPerRow,
unsigned char *red,
unsigned char *green,
unsigned char *blue );
724 void loadFromIplImage(
void* iplImage );
731 void setFromIplImage(
void* iplImage );
738 void setFromIplImageReadOnly(
void* iplImage );
744 inline
void setFromImageReadOnly( const
CImage &other_img ) { setFromIplImageReadOnly(
const_cast<void*
>(other_img.getAs<
void>()) ); }
750 template <
typename Derived>
751 void setFromMatrix(
const Eigen::MatrixBase<Derived> &m,
bool matrix_is_normalized=
true)
754 const unsigned int lx = m.cols();
755 const unsigned int ly = m.rows();
756 this->changeSize(lx,ly,1,
true);
757 if (matrix_is_normalized) {
758 for (
unsigned int y=0;y<ly;y++) {
759 unsigned char *pixels = this->
get_unsafe(0,y,0);
760 for (
unsigned int x=0;x<lx;x++)
761 (*pixels++) =
static_cast<unsigned char>( m.get_unsafe(y,x) * 255 );
765 for (
unsigned int y=0;y<ly;y++) {
766 unsigned char *pixels = this->
get_unsafe(0,y,0);
767 for (
unsigned int x=0;x<lx;x++)
768 (*pixels++) =
static_cast<unsigned char>( m.get_unsafe(y,x) );
778 template <
typename Derived>
779 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)
782 makeSureImageIsLoaded();
784 ASSERT_((m_r.size() == m_g.size())&&(m_r.size() == m_b.size()));
785 const unsigned int lx = m_r.cols();
786 const unsigned int ly = m_r.rows();
787 this->changeSize(lx,ly,3,
true);
788 this->setChannelsOrder_RGB();
790 if (matrix_is_normalized) {
791 for (
unsigned int y=0;y<ly;y++) {
792 unsigned char *pixels = this->
get_unsafe(0,y,0);
793 for (
unsigned int x=0;x<lx;x++)
795 (*pixels++) =
static_cast<unsigned char>( m_r.get_unsafe(y,x) * 255 );
796 (*pixels++) =
static_cast<unsigned char>( m_g.get_unsafe(y,x) * 255 );
797 (*pixels++) =
static_cast<unsigned char>( m_b.get_unsafe(y,x) * 255 );
802 for (
unsigned int y=0;y<ly;y++) {
803 unsigned char *pixels = this->
get_unsafe(0,y,0);
804 for (
unsigned int x=0;x<lx;x++)
806 (*pixels++) =
static_cast<unsigned char>( m_r.get_unsafe(y,x) );
807 (*pixels++) =
static_cast<unsigned char>( m_g.get_unsafe(y,x) );
808 (*pixels++) =
static_cast<unsigned char>( m_b.get_unsafe(y,x) );
868 bool saveToFile(
const std::string& fileName,
int jpeg_quality = 95 )
const;
936 bool originTopLeft );
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class.
This class is a "CSerializable" wrapper for "CMatrixFloat".
A matrix of dynamic size.
This virtual class defines the interface of any object accepting drawing primitives on it.
TPenStyle
Definition of pen styles.
Used in mrpt::utils::CImage.
A class for storing images as grayscale or RGB bitmaps.
static bool DISABLE_ZIP_COMPRESSION
By default, when storing images through the CSerializable interface, grayscale images will be ZIP com...
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
void releaseIpl(bool thisIsExternalImgUnload=false) MRPT_NO_THROWS
Release the internal IPL image, if not NULL or read-only.
void rectifyImageInPlace(const mrpt::utils::TCamera &cameraParams)
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coeffici...
void setPixel(int x, int y, size_t color) MRPT_OVERRIDE
Changes the value of the pixel (x,y).
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,...
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.
static int SERIALIZATION_JPEG_QUALITY
Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB imag...
void setOriginTopLeft(bool val)
Changes the property of the image stating if the top-left corner (vs.
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.
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process (this is much faster than...
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...
CImage(const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized)
Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0,...
std::string getExternalStorageFile() const MRPT_NO_THROWS
< Only if isExternallyStored() returns true.
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows.
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 equivale...
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 gra...
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 cvMatc...
void * img
The internal IplImage pointer to the actual image content.
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_i...
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...
unsigned char * operator()(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel information.
CImage()
Default constructor: initialize an 1x1 RGB image.
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 filtere...
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images.
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,...
T * getAs()
Returns a pointer to a T* containing the image - the idea is to call like "img.getAs<IplImage>()" so ...
void saveToStreamAsJPEG(mrpt::utils::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
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.
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.
void swapRB()
Swaps red and blue channels.
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,...
CImage scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows)
bool isExternallyStored() const MRPT_NO_THROWS
See setExternalStorage().
void scaleDouble(CImage &out_image) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 ...
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
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].
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.
bool isOriginTopLeft() const
Returns true if the coordinates origin is top-left, or false if it is bottom-left
void loadFromStreamAsJPEG(CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
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,...
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-distorte...
static std::string IMAGES_PATH_BASE
By default, ".".
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,...
CImage(TConstructorFlags_CImage)
Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL).
void getAsMatrixTiled(math::CMatrix &outMatrix) const
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to ...
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img....
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...
CImage(unsigned int width, unsigned int height, TImageChannels nChannels=CH_RGB, bool originTopLeft=true)
Constructor for a given image size and type.
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).
virtual ~CImage()
Destructor:
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1].
bool loadFromXPM(const char **xpm_array, bool swap_rb=true)
Loads the image from an XPM array, as #include'd from a ".xpm" file.
void flipVertical(bool also_swapRB=false)
Flips vertically the 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 setChannelsOrder_RGB()
Marks the channel ordering in a color image as "RGB" (this doesn't actually modify the image data,...
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
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
bool m_imgIsReadOnly
Set to true only when using setFromIplImageReadOnly.
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 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 setChannelsOrder_BGR()
Marks the channel ordering in a color image as "BGR" (this doesn't actually modify the image data,...
CImage grayscale() const
Returns a grayscale version of the image, or itself if it is already a grayscale image.
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
void scaleHalfSmooth(CImage &out_image) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
CImage(const CImage &o)
Copy constructor, makes a full copy of the original image contents (unless it was externally stored,...
static bool DISABLE_JPEG_COMPRESSION
By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed t...
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 grayscal...
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).
CImage scaleDouble() const
Returns a new image scaled up to double its original size.
CImage(void *iplImage)
Constructor from an IPLImage*, making a copy of the image.
void unload() const MRPT_NO_THROWS
For external storage image objects only, this method unloads the image from memory (or does nothing i...
void grayscaleInPlace()
Replaces the image with a grayscale version of it.
void rectifyImageInPlace(void *mapX, void *mapY)
Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed...
void colorImageInPlace()
Replaces this grayscale image with a RGB version of it.
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.
std::string m_externalFile
The file name of a external storage image.
const char * getChannelsOrder() const
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory.
void copyFromForceLoad(const CImage &o)
Copies from another image, and, if that one is externally stored, the image file will be actually loa...
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed.
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
void scaleHalf(CImage &out_image) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void filterMedianInPlace(int W=3)
Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered ...
void swap(CImage &o)
Very efficient swap of two images (just swap the internal pointers)
void getExternalStorageFileAbsolutePath(std::string &out_path) const
Only if isExternallyStored() returns true.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Structure to hold the parameters of a pinhole camera model.
EIGEN_STRONG_INLINE Scalar get_unsafe(const size_t row, const size_t col) const
Read-only access to one element (Use with caution, bounds are not checked!)
TInterpolationMethod
Interpolation methods for images.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_NO_THROWS
Used after member declarations.
TConstructorFlags_CImage
For usage in one of the CImage constructors.
@ FAST_REF_OR_CONVERT_TO_GRAY
int TImageChannels
For use in mrpt::utils::CImage.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A pair (x,y) of pixel coordinates (integer resolution).