116 CImage(
unsigned int width,
118 TImageChannels nChannels =
CH_RGB,
119 bool originTopLeft = true
123 CImage( const CImage &o );
149 else this->setFromImageReadOnly(other_img);
160 template <
typename Derived>
161 explicit inline CImage(
const Eigen::MatrixBase<Derived> &m,
bool matrix_is_normalized) : img(NULL),m_imgIsReadOnly(false), m_imgIsExternalStorage(false)
163 this->setFromMatrix(m,matrix_is_normalized);
202 TImageChannels nChannels,
205 changeSize(width,height,nChannels,originTopLeft);
221 void rotateImage(
double angle_radians,
unsigned int center_x,
unsigned int center_y,
double scale = 1.0 );
230 void setPixel(
int x,
int y,
size_t color);
234 void setOriginTopLeft(
bool val);
251 unsigned int width = 1,
252 TPenStyle penStyle = psSolid);
266 unsigned int width = 1);
268 void equalizeHistInPlace();
269 void equalizeHist(
CImage &outImg )
const;
278 this->scaleHalf(ret);
283 void scaleHalf(
CImage &out_image)
const;
293 this->scaleHalfSmooth(ret);
298 void scaleHalfSmooth(
CImage &out_image)
const;
308 this->scaleDouble(ret);
313 void scaleDouble(
CImage &out_image)
const;
322 void update_patch(
const CImage &patch,
323 const unsigned int col,
324 const unsigned int row);
332 const unsigned int col=0,
333 const unsigned int row=0,
334 const unsigned int width=1,
335 const unsigned int height=1 )
const;
342 float correlate(
const CImage &img2int,
int width_init=0,
int height_init=0 )
const;
358 void cross_correlation(
365 int u_search_size=-1,
366 int v_search_size=-1,
367 CImage *out_corr_image = NULL
389 int u_search_size=-1,
390 int v_search_size=-1,
391 float biasThisImg = 0,
405 void flipVertical(
bool also_swapRB =
false);
429 void rectifyImageInPlace(
void *mapX,
void *mapY );
432 void filterMedian(
CImage &out_img,
int W=3 )
const;
435 void filterMedianInPlace(
int W=3 );
438 void filterGaussianInPlace(
int W = 3,
int H = 3 );
441 void filterGaussian(
CImage &out_img,
int W = 3,
int H = 3)
const;
453 bool drawChessboardCorners(
454 std::vector<TPixelCoordf> &cornerCoords,
455 unsigned int check_size_x,
456 unsigned int check_size_y,
457 unsigned int lines_width = 1,
458 unsigned int circles_radius = 4
475 const unsigned int x,
476 const unsigned int y,
477 const unsigned int half_window_size )
const;
497 void copyFromForceLoad(
const CImage &o);
502 void copyFastFrom(
CImage &o );
515 template <
typename T>
inline const T*
getAs()
const {
516 makeSureImageIsLoaded();
517 return static_cast<const T*
>(img);
520 template <
typename T>
inline T*
getAs(){
521 makeSureImageIsLoaded();
522 return static_cast<T*
>(img);
531 unsigned int channel=0)
const;
538 float getAsFloat(
unsigned int col,
unsigned int row,
unsigned int channel)
const;
545 float getAsFloat(
unsigned int col,
unsigned int row)
const;
551 unsigned char* operator()(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
const;
565 size_t getWidth()
const;
570 size_t getHeight()
const;
589 size_t getRowStride()
const;
594 float getMaxAsFloat()
const;
597 bool isColor()
const;
600 bool isOriginTopLeft()
const;
603 const char * getChannelsOrder()
const;
606 void setChannelsOrder_RGB();
608 void setChannelsOrder_BGR();
613 TImageChannels getChannelCount()
const;
625 bool doResize =
true,
640 void getAsRGBMatrices(
644 bool doResize =
true,
679 void setExternalStorage(
const std::string &fileName )
MRPT_NO_THROWS;
688 return m_externalFile;
692 void getExternalStorageFileAbsolutePath(std::string &out_path)
const;
697 getExternalStorageFileAbsolutePath(tmp);
704 inline void forceLoad()
const { makeSureImageIsLoaded(); }
711 void unload() const MRPT_NO_THROWS;
723 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
bool color,
unsigned char *rawpixels,
bool swapRedBlue = false );
728 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
unsigned int bytesPerRow,
unsigned char *red,
unsigned char *green,
unsigned char *blue );
732 void loadFromIplImage(
void* iplImage );
739 void setFromIplImage(
void* iplImage );
746 void setFromIplImageReadOnly(
void* iplImage );
752 inline
void setFromImageReadOnly( const
CImage &other_img ) { setFromIplImageReadOnly(const_cast<void*>(other_img.getAs<
void>()) ); }
758 template <
typename Derived>
759 void setFromMatrix(
const Eigen::MatrixBase<Derived> &m,
bool matrix_is_normalized=
true)
762 const unsigned int lx = m.cols();
763 const unsigned int ly = m.rows();
764 this->changeSize(lx,ly,1,
true);
765 if (matrix_is_normalized) {
766 for (
unsigned int y=0;y<ly;y++) {
767 unsigned char *pixels = this->
get_unsafe(0,y,0);
768 for (
unsigned int x=0;x<lx;x++)
769 (*pixels++) =
static_cast<unsigned char>( m.get_unsafe(y,x) * 255 );
773 for (
unsigned int y=0;y<ly;y++) {
774 unsigned char *pixels = this->
get_unsafe(0,y,0);
775 for (
unsigned int x=0;x<lx;x++)
776 (*pixels++) =
static_cast<unsigned char>( m.get_unsafe(y,x) );
786 template <
typename Derived>
787 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)
790 makeSureImageIsLoaded();
792 ASSERT_((m_r.size() == m_g.size())&&(m_r.size() == m_b.size()));
793 const unsigned int lx = m_r.cols();
794 const unsigned int ly = m_r.rows();
795 this->changeSize(lx,ly,3,
true);
796 this->setChannelsOrder_RGB();
798 if (matrix_is_normalized) {
799 for (
unsigned int y=0;y<ly;y++) {
800 unsigned char *pixels = this->
get_unsafe(0,y,0);
801 for (
unsigned int x=0;x<lx;x++)
803 (*pixels++) = static_cast<unsigned char>( m_r.get_unsafe(y,x) * 255 );
804 (*pixels++) = static_cast<unsigned char>( m_g.get_unsafe(y,x) * 255 );
805 (*pixels++) = static_cast<unsigned char>( m_b.get_unsafe(y,x) * 255 );
810 for (
unsigned int y=0;y<ly;y++) {
811 unsigned char *pixels = this->
get_unsafe(0,y,0);
812 for (
unsigned int x=0;x<lx;x++)
814 (*pixels++) = static_cast<unsigned char>( m_r.get_unsafe(y,x) );
815 (*pixels++) = static_cast<unsigned char>( m_g.get_unsafe(y,x) );
816 (*pixels++) = static_cast<unsigned char>( m_b.get_unsafe(y,x) );
826 void loadFromStreamAsJPEG(
CStream &in );
846 bool loadFromFile(
const std::string& fileName,
int isColor = -1 );
857 bool loadFromXPM(
const char** xpm_array,
bool swap_rb =
true );
876 bool saveToFile(
const std::string& fileName,
int jpeg_quality = 95 )
const;
882 void saveToStreamAsJPEG(
CStream &out,
const int jpeg_quality = 95 )
const;
899 void grayscale(
CImage &ret )
const;
904 void colorImage(
CImage &ret )
const;
909 void colorImageInPlace();
915 void grayscaleInPlace();
943 TImageChannels nChannels,
944 bool originTopLeft );
947 void releaseIpl(
bool thisIsExternalImgUnload =
false) MRPT_NO_THROWS;
TConstructorFlags_CImage
For usage in one of the CImage constructors.
CImage(const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized)
Explicit constructor from a matrix, interpreted as grayscale intensity values, in the range [0...
CImage scaleHalf() const
Returns a new image scaled down to half its original size.
std::string m_externalFile
The file name of a external storage image.
CImage scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows) On odd s...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
bool m_imgIsReadOnly
Set to true only when using setFromIplImageReadOnly.
A class for storing images as grayscale or RGB bitmaps.
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...
A pair (x,y) of pixel coordinates (integer resolution).
static std::string IMAGES_PATH_BASE
By default, ".".
std::string getExternalStorageFile() const MRPT_NO_THROWS
< Only if isExternallyStored() returns true.
#define MRPT_NO_THROWS
Used after member declarations.
TImageSize getSize() const
Return the size of the image.
int TImageChannels
For use in mrpt::utils::CImage.
static bool DISABLE_JPEG_COMPRESSION
By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed t...
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...
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
CImage grayscale() const
Returns a grayscale version of the image, or itself if it is already a grayscale image.
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
static int SERIALIZATION_JPEG_QUALITY
Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB imag...
bool isExternallyStored() const MRPT_NO_THROWS
See setExternalStorage().
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...
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
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...
TInterpolationMethod
Interpolation methods for images.
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
CImage scaleDouble() const
Returns a new image scaled up to double its original size.
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs()" so we can avoid here including OpenCV's headers.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
A matrix of dynamic size.
This virtual class defines the interface of any object accepting drawing primitives on it...
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
T * getAs()
Returns a pointer to a T* containing the image - the idea is to call like "img.getAs()" so ...
This class is a "CSerializable" wrapper for "CMatrixFloat".
Used in mrpt::utils::CImage.
void * img
The internal IplImage pointer to the actual image content.
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!)
Structure to hold the parameters of a pinhole camera model.
void BASE_IMPEXP cross_correlation_FFT(const CMatrixFloat &A, const CMatrixFloat &B, CMatrixFloat &out_corr)
Correlation of two matrixes using 2D FFT.
static bool DISABLE_ZIP_COMPRESSION
By default, when storing images through the CSerializable interface, grayscale images will be ZIP com...