Go to the documentation of this file.
59 : std::runtime_error(
s )
211 template <
typename Derived>
288 double angle_radians,
unsigned int center_x,
unsigned int center_y,
331 int x ,
int y ,
int radius,
333 unsigned int width = 1)
override ;
395 const CImage & patch,
const unsigned int col,
const unsigned int row );
403 CImage & patch,
const unsigned int col = 0,
const unsigned int row = 0,
404 const unsigned int width = 1,
const unsigned int height = 1)
const ;
413 const CImage & img2int,
int width_init = 0,
int height_init = 0)
const ;
436 const CImage & patch_img,
size_t & u_max,
size_t & v_max,
double & max_val,
437 int u_search_ini = -1,
int v_search_ini = -1,
int u_search_size = -1,
438 int v_search_size = -1,
CImage * out_corr_image =
nullptr )
const ;
461 int u_search_ini = -1,
int v_search_ini = -1,
int u_search_size = -1,
462 int v_search_size = -1,
float biasThisImg = 0,
463 float biasInImg = 0)
const ;
536 std::vector<TPixelCoordf>& cornerCoords,
unsigned int check_size_x,
537 unsigned int check_size_y,
unsigned int lines_width = 1,
538 unsigned int circles_radius = 4);
555 const unsigned int x ,
const unsigned int y ,
556 const unsigned int half_window_size)
const ;
598 template <
typename T>
602 return static_cast< const T*
> (
img );
607 template <
typename T>
611 return static_cast< T*
> (
img );
619 unsigned int col,
unsigned int row ,
unsigned int channel = 0)
const ;
628 unsigned int col,
unsigned int row ,
unsigned int channel)
const ;
644 unsigned int col,
unsigned int row ,
unsigned int channel = 0)
const ;
722 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1)
const ;
744 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1)
const ;
826 void unload () const noexcept;
839 unsigned char * rawpixels,
bool swapRedBlue = false);
846 unsigned int width ,
unsigned int height ,
unsigned int bytesPerRow,
847 unsigned char *
red ,
unsigned char *
green ,
unsigned char *
blue );
890 template <
typename Derived>
895 const unsigned int lx = m.cols();
896 const unsigned int ly = m.rows();
898 if (matrix_is_normalized)
900 for (
unsigned int y = 0;
y < ly;
y ++)
903 for (
unsigned int x = 0;
x < lx;
x ++)
905 static_cast< unsigned char > (m.get_unsafe(
y ,
x ) * 255);
910 for (
unsigned int y = 0;
y < ly;
y ++)
913 for (
unsigned int x = 0;
x < lx;
x ++)
915 static_cast< unsigned char > (m.get_unsafe(
y ,
x ));
926 template <
typename Derived>
935 ASSERT_ ((m_r.size() == m_g.size()) && (m_r.size() == m_b.size()));
936 const unsigned int lx = m_r.cols();
937 const unsigned int ly = m_r.rows();
941 if (matrix_is_normalized)
943 for (
unsigned int y = 0;
y < ly;
y ++)
946 for (
unsigned int x = 0;
x < lx;
x ++)
949 static_cast< unsigned char > (m_r.get_unsafe(
y ,
x ) * 255);
951 static_cast< unsigned char > (m_g.get_unsafe(
y ,
x ) * 255);
953 static_cast< unsigned char > (m_b.get_unsafe(
y ,
x ) * 255);
959 for (
unsigned int y = 0;
y < ly;
y ++)
962 for (
unsigned int x = 0;
x < lx;
x ++)
965 static_cast< unsigned char > (m_r.get_unsafe(
y ,
x ));
967 static_cast< unsigned char > (m_g.get_unsafe(
y ,
x ));
969 static_cast< unsigned char > (m_b.get_unsafe(
y ,
x ));
1016 bool loadFromXPM (
const char *
const * xpm_array,
bool swap_rb =
true );
1109 bool originTopLeft);
1112 void releaseIpl (
bool thisIsExternalImgUnload =
false ) noexcept;
unsigned char * operator()(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel information.
void saveToStreamAsJPEG(mrpt::io::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
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,...
CExceptionExternalImageNotFound(const std::string &s)
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...
size_t getWidth() const override
Returns the width of the image in pixels.
std::string getExternalStorageFile() const noexcept
Only if isExternallyStored() returns true.
void flipHorizontal()
Flips the image horizontally.
void filterMedianInPlace(int W=3)
Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered ...
TConstructorFlags_CImage
For usage in one of the CImage constructors.
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].
static void setImagesPathBase(const std::string &path)
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed.
CImage scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows)
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
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
TImageSize getSize() const
Return the size of the image.
void flipVertical(bool also_swapRB=false)
Flips the image vertically.
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows.
static bool DISABLE_ZIP_COMPRESSION
By default, when storing images through the CSerializable interface, grayscale images will be ZIP com...
bool m_imgIsReadOnly
Set to true only when using setFromIplImageReadOnly.
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it.
void setFromImageReadOnly(const CImage &other_img)
Sets the internal IplImage pointer to that of another given image, WITHOUT making a copy,...
void colorImageInPlace()
Replaces this grayscale image with a RGB version of it.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
static int SERIALIZATION_JPEG_QUALITY
Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB imag...
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=nullptr) const
Computes the correlation between this image and another one, encapsulating the openCV function cvMatc...
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 & operator=(const CImage &o)
Copy operator (if the image is externally stored, the writen image will be such as well).
CImage grayscale() const
Returns a grayscale version of the image, or itself if it is already a grayscale image.
void copyFromForceLoad(const CImage &o)
Copies from another image, and, if that one is externally stored, the image file will be actually loa...
std::string m_externalFile
The file name of a external storage image.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img....
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...
#define ASSERT_(f)
Defines an assertion mechanism.
void colorImage(CImage &ret) const
Returns a RGB version of the grayscale image, or itself if it is already a RGB image.
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process (this is much faster than...
static bool DISABLE_JPEG_COMPRESSION
By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed t...
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
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,...
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,...
void setPixel(int x, int y, size_t color) override
Changes the value of the pixel (x,y).
void swapRB()
Swaps red and blue channels.
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 forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory.
Used in mrpt::img::CImage.
A matrix of dynamic size.
void * img
The internal IplImage pointer to the actual image content.
CImage scaleHalf() const
Returns a new image scaled down to half its original size.
void loadFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (making a COPY).
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1].
int TImageChannels
For use in mrpt::img::CImage.
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
void setFromIplImageReadOnly(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image canno...
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.
This virtual class defines the interface of any object accepting drawing primitives on it.
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].
This class is a "CSerializable" wrapper for "CMatrixFloat".
void swap(CImage &o)
Very efficient swap of two images (just swap the internal pointers)
void loadFromStreamAsJPEG(mrpt::io::CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
bool isOriginTopLeft() const
Returns true if the coordinates origin is top-left, or false if it is bottom-left
CImage scaleDouble() const
Returns a new image scaled up to double its original size.
TInterpolationMethod
Interpolation methods for images.
virtual ~CImage()
Destructor:
CImage()
Default constructor: initialize an 1x1 RGB image.
void line(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) override
Draws a line.
The virtual base class which provides a unified interface for all persistent objects in MRPT.
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,...
void drawCircle(int x, int y, int radius, const mrpt::img::TColor &color=mrpt::img::TColor(255, 255, 255), unsigned int width=1) override
Draws a circle of a given radius.
Structure to hold the parameters of a pinhole camera model.
static const std::string & getImagesPathBase()
By default, ".".
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
GLenum GLsizei GLsizei height
void rectifyImageInPlace(const mrpt::img::TCamera &cameraParams)
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coeffici...
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class.
A class for storing images as grayscale or RGB bitmaps.
@ FAST_REF_OR_CONVERT_TO_GRAY
void grayscaleInPlace()
Replaces the image with a grayscale version of it.
void setChannelsOrder_RGB()
Marks the channel ordering in a color image as "RGB" (this doesn't actually modify the image data,...
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 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).
GLenum GLenum GLenum GLenum GLenum scale
void getAsMatrixTiled(math::CMatrix &outMatrix) const
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to ...
void unload() const noexcept
For external storage image objects only, this method unloads the image from memory (or does nothing i...
void setFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy).
size_t getHeight() const override
Returns the height of the image in pixels.
GLenum GLenum GLvoid * row
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void setExternalStorage(const std::string &fileName) noexcept
By using this method the image is marked as referenced to an external file, which will be loaded only...
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 rectifyImage(CImage &out_img, const mrpt::img::TCamera &cameraParams) const
Rectify (un-distort) the image according to some camera parameters, and returns an output un-distorte...
void equalizeHist(CImage &outImg) const
Equalize the image histogram, saving the new image in the given output object.
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...
GLsizei const GLchar ** string
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...
void setChannelsOrder_BGR()
Marks the channel ordering in a color image as "BGR" (this doesn't actually modify the image data,...
void releaseIpl(bool thisIsExternalImgUnload=false) noexcept
Release the internal IPL image, if not nullptr or read-only.
A pair (x,y) of pixel coordinates (integer resolution).
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...
static bool loadTGA(const std::string &fileName, mrpt::img::CImage &out_RGB, mrpt::img::CImage &out_alpha)
Loads a TGA true-color RGBA image as two CImage objects, one for the RGB channels plus a separate gra...
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 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,...
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
void equalizeHistInPlace()
Equalize the image histogram, replacing the original image.
const char * getChannelsOrder() const
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering.
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 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).
TPenStyle
Definition of pen styles.
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class.
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images.
CImage(TConstructorFlags_CImage)
Fast constructor that leaves the image uninitialized (the internal IplImage pointer set to nullptr).
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
bool loadFromXPM(const char *const *xpm_array, bool swap_rb=true)
Loads the image from an XPM array, as #include'd from a ".xpm" file.
bool isExternallyStored() const noexcept
See setExternalStorage().
T * getAs()
Returns a pointer to a T* containing the image - the idea is to call like "img.getAs<IplImage>()" so ...
void setOriginTopLeft(bool val)
Changes the property of the image stating if the top-left corner (vs.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST