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);
231 void rotateImage(
double angle_radians,
unsigned int center_x,
unsigned int center_y,
double scale = 1.0 );
243 void setOriginTopLeft(
bool val);
258 unsigned int width = 1,
275 void equalizeHistInPlace();
276 void equalizeHist(
CImage &outImg ) const;
285 this->scaleHalf(ret);
290 void scaleHalf(
CImage &out_image)
const;
300 this->scaleHalfSmooth(ret);
305 void scaleHalfSmooth(
CImage &out_image)
const;
315 this->scaleDouble(ret);
320 void scaleDouble(
CImage &out_image)
const;
329 void update_patch(
const CImage &patch,
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;
349 float correlate(
const CImage &img2int,
int width_init=0,
int height_init=0 )
const;
365 void cross_correlation(
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,
409 void flipVertical(
bool also_swapRB =
false);
410 void flipHorizontal();
431 void rectifyImageInPlace(
void *mapX,
void *mapY );
434 void filterMedian(
CImage &out_img,
int W=3 )
const;
437 void filterMedianInPlace(
int W=3 );
440 void filterGaussianInPlace(
int W = 3,
int H = 3 );
443 void filterGaussian(
CImage &out_img,
int W = 3,
int H = 3)
const;
455 bool drawChessboardCorners(
456 std::vector<TPixelCoordf> &cornerCoords,
457 unsigned int check_size_x,
458 unsigned int check_size_y,
459 unsigned int lines_width = 1,
460 unsigned int circles_radius = 4
477 const unsigned int x,
478 const unsigned int y,
479 const unsigned int half_window_size )
const;
499 void copyFromForceLoad(
const CImage &o);
504 void copyFastFrom(
CImage &o );
517 template <
typename T>
inline const T*
getAs()
const {
518 makeSureImageIsLoaded();
519 return static_cast<const T*
>(
img);
522 template <
typename T>
inline T*
getAs(){
523 makeSureImageIsLoaded();
524 return static_cast<T*
>(
img);
533 unsigned int channel=0)
const;
540 float getAsFloat(
unsigned int col,
unsigned int row,
unsigned int channel)
const;
547 float getAsFloat(
unsigned int col,
unsigned int row)
const;
553 unsigned char* operator()(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
const;
577 size_t getRowStride()
const;
581 float getMaxAsFloat()
const;
584 bool isColor()
const;
587 bool isOriginTopLeft()
const;
590 const char * getChannelsOrder()
const;
593 void setChannelsOrder_RGB();
595 void setChannelsOrder_BGR();
612 bool doResize =
true,
627 void getAsRGBMatrices(
631 bool doResize =
true,
675 return m_externalFile;
679 void getExternalStorageFileAbsolutePath(
std::string &out_path)
const;
684 getExternalStorageFileAbsolutePath(tmp);
691 inline void forceLoad()
const { makeSureImageIsLoaded(); }
710 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
bool color,
unsigned char *rawpixels,
bool swapRedBlue = false );
715 void loadFromMemoryBuffer(
unsigned int width,
unsigned int height,
unsigned int bytesPerRow,
unsigned char *
red,
unsigned char *
green,
unsigned char *
blue );
719 void loadFromIplImage(
void* iplImage );
726 void setFromIplImage(
void* iplImage );
733 void setFromIplImageReadOnly(
void* iplImage );
739 inline
void setFromImageReadOnly( const
CImage &other_img ) { setFromIplImageReadOnly(const_cast<void*>(other_img.getAs<
void>()) ); }
745 template <
typename Derived>
746 void setFromMatrix(
const Eigen::MatrixBase<Derived> &m,
bool matrix_is_normalized=
true)
749 const unsigned int lx = m.cols();
750 const unsigned int ly = m.rows();
751 this->changeSize(lx,ly,1,
true);
752 if (matrix_is_normalized) {
753 for (
unsigned int y=0;
y<ly;
y++) {
755 for (
unsigned int x=0;
x<lx;
x++)
756 (*
pixels++) =
static_cast<unsigned char>( m.get_unsafe(
y,
x) * 255 );
760 for (
unsigned int y=0;
y<ly;
y++) {
762 for (
unsigned int x=0;
x<lx;
x++)
763 (*
pixels++) =
static_cast<unsigned char>( m.get_unsafe(
y,
x) );
773 template <
typename Derived>
774 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)
777 makeSureImageIsLoaded();
779 ASSERT_((m_r.size() == m_g.size())&&(m_r.size() == m_b.size()));
780 const unsigned int lx = m_r.cols();
781 const unsigned int ly = m_r.rows();
782 this->changeSize(lx,ly,3,
true);
783 this->setChannelsOrder_RGB();
785 if (matrix_is_normalized) {
786 for (
unsigned int y=0;
y<ly;
y++) {
788 for (
unsigned int x=0;
x<lx;
x++)
790 (*
pixels++) = static_cast<unsigned char>( m_r.get_unsafe(
y,
x) * 255 );
791 (*
pixels++) = static_cast<unsigned char>( m_g.get_unsafe(
y,
x) * 255 );
792 (*
pixels++) = static_cast<unsigned char>( m_b.get_unsafe(
y,
x) * 255 );
797 for (
unsigned int y=0;
y<ly;
y++) {
799 for (
unsigned int x=0;
x<lx;
x++)
801 (*
pixels++) = static_cast<unsigned char>( m_r.get_unsafe(
y,
x) );
802 (*
pixels++) = static_cast<unsigned char>( m_g.get_unsafe(
y,
x) );
803 (*
pixels++) = static_cast<unsigned char>( m_b.get_unsafe(
y,
x) );
813 void loadFromStreamAsJPEG(
CStream &
in );
833 bool loadFromFile(
const std::string& fileName,
int isColor = -1 );
844 bool loadFromXPM(
const char** xpm_array,
bool swap_rb =
true );
863 bool saveToFile(
const std::string& fileName,
int jpeg_quality = 95 )
const;
886 void grayscale(
CImage &ret )
const;
891 void colorImage(
CImage &ret )
const;
896 void colorImageInPlace();
902 void grayscaleInPlace();
931 bool originTopLeft );
934 void releaseIpl(
bool thisIsExternalImgUnload =
false)
MRPT_NO_THROWS;
938 void makeSureImageIsLoaded() const;
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...
static bool DISABLE_JPEG_COMPRESSION
By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed t...
static int SERIALIZATION_JPEG_QUALITY
Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB imag...
std::string m_externalFile
The file name of a external storage image.
CImage scaleDouble() const
Returns a new image scaled up to double its original size.
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.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
A class for storing images as grayscale or RGB bitmaps.
GLenum GLenum GLenum GLenum GLenum scale
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class...
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...
CImage(TConstructorFlags_CImage)
Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to NULL)...
A pair (x,y) of pixel coordinates (integer resolution).
std::string getExternalStorageFile() const MRPT_NO_THROWS
< Only if isExternallyStored() returns true.
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations.
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!)
int TImageChannels
For use in mrpt::utils::CImage.
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...
static std::string IMAGES_PATH_BASE
By default, ".".
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.
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 DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class...
void BASE_IMPEXP cross_correlation_FFT(const CMatrixFloat &A, const CMatrixFloat &B, CMatrixFloat &out_corr)
Correlation of two matrixes using 2D FFT.
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...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
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...
GLsizei const GLchar ** string
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
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 scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows) ...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
GLenum GLenum GLvoid * row
A matrix of dynamic size.
This virtual class defines the interface of any object accepting drawing primitives on it...
static bool DISABLE_ZIP_COMPRESSION
By default, when storing images through the CSerializable interface, grayscale images will be ZIP com...
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<IplImage>()" so ...
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
This class is a "CSerializable" wrapper for "CMatrixFloat".
double getHeight(const TPolygon3D &p, const TPoint3D &c)
GLenum GLsizei GLsizei height
void * img
The internal IplImage pointer to the actual image content.
Structure to hold the parameters of a pinhole camera model.
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.