class mrpt::img::CImage
Overview
A class for storing images as grayscale, RGB, or RGBA bitmaps.
Supported I/O are:
Saving/loading from files of different formats (JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC) using the methods CImage::loadFromFile() and CImage::saveToFile(). This uses the stb library.
Importing from an XPM array (.xpm file format) using CImage::loadFromXPM()
Binary dump using the CSerializable interface (<< and >> operators), just as most objects in MRPT. This format is not compatible with any standardized image format but it is fast.
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:
Since MRPT 3.0.0, the internal format for images is a raw memory buffer managed by the STB library. Previous versions used OpenCV’s cv::Mat, but this was removed to reduce dependencies.
By default, all images use unsigned 8-bit storage format for pixels (on each channel), but 16-bit depth is also supported via PixelDepth::D16U.
An external storage mode can be enabled by calling CImage::setExternalStorage, useful for storing large collections of image objects in memory while loading the image data itself only for the relevant images at any time. See CImage::forceLoad() and CImage::unload().
Operator = and copy ctor make shallow copies. For deep copies, see CImage::makeDeepCopy() or CImage(const CImage&, copy_type_t), e.g:
CImage a(20, 10, CH_GRAY); // Shallow copy ctor: CImage b(a, mrpt::img::SHALLOW_COPY); CImage c(a, mrpt::img::DEEP_COPY);
If you are interested in a smart pointer to an image, use:
CImage::Ptr myImg = CImage::Create(); // optional ctor arguments // or: CImage::Ptr myImg = std::make_shared<CImage>(...);
See also:
mrpt::vision, mrpt::serialization::CSerializable, mrpt::img::CCanvas
#include <mrpt/img/CImage.h> class CImage: public mrpt::serialization::CSerializable, public mrpt::img::CCanvas { public: // typedefs typedef std::shared_ptr<mrpt::img ::CImage> Ptr; typedef std::shared_ptr<const mrpt::img ::CImage> ConstPtr; typedef std::unique_ptr<mrpt::img ::CImage> UniquePtr; typedef std::unique_ptr<const mrpt::img ::CImage> ConstUniquePtr; // structs struct Impl; // fields static constexpr const char* className = "mrpt::img" "::" "CImage"; // construction CImage(); CImage(int32_t width, int32_t height, TImageChannels nChannels = CH_RGB); CImage(const CImage& other_img, ] ctor_CImage_ref_or_gray _); CImage(const CImage& img, copy_type_t copy_type); // methods static constexpr auto getClassName(); static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); static std::shared_ptr<CObject> CreateObject(); template <typename... Args> static Ptr Create(Args&&... args); template <typename Alloc, typename... Args> static Ptr CreateAlloc( const Alloc& alloc, Args&&... args ); template <typename... Args> static UniquePtr CreateUnique(Args&&... args); virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const; virtual mrpt::rtti::CObject* clone() const; static const std::string& getImagesPathBase(); static void setImagesPathBase(const std::string& path); void setExternalStorage(const std::string& fileName); bool isExternallyStored() const; std::string getExternalStorageFile() const; void getExternalStorageFileAbsolutePath(std::string& out_path) const; std::string getExternalStorageFileAbsolutePath() const; void forceLoad() const; void unload() const; void cross_correlation_FFT( const CImage& in_img, mrpt::math::CMatrixFloat& out_corr, std::optional<int32_t> u_search_ini = std::nullopt, std::optional<int32_t> v_search_ini = std::nullopt, std::optional<int32_t> u_search_size = std::nullopt, std::optional<int32_t> v_search_size = std::nullopt, std::optional<float> biasThisImg = std::nullopt, std::optional<float> biasInImg = std::nullopt ) const; static mrpt::img::CImage LoadFromFile(const std::string& fileName, TImageChannels loadChannels = CH_AS_IS); void loadFromMemoryBuffer( int32_t width, int32_t height, TImageChannels color_channels, uint8_t* rawpixels, bool swapRedBlue = false ); template <typename MAT> void setFromMatrix( const MAT& m, bool matrix_is_normalized = true, bool flip_vertically = false ); template <typename MAT> void setFromRGBMatrices( const MAT& r, const MAT& g, const MAT& b, bool matrix_is_normalized = true ); void loadFromStreamAsJPEG(mrpt::io::CStream& in); bool loadFromFile(const std::string& fileName, TImageChannels loadChannels = CH_AS_IS); bool loadFromXPM(const char*const* xpm_array, bool swap_rb = true); bool saveToFile(const std::string& fileName, int jpeg_quality = 95) const; void saveToStreamAsJPEG(mrpt::io::CStream& out, int jpeg_quality = 95) const; void clear(); void resize(int32_t width, int32_t height, TImageChannels nChannels, PixelDepth depth = PixelDepth::D8U); PixelDepth getPixelDepth() const; void scaleImage(CImage& out_img, int32_t width, int32_t height, TInterpolationMethod interp = IMG_INTERP_CUBIC) const; void rotateImage(CImage& out_img, double ang, const TPixelCoord& center, double scale = 1.0) const; virtual void setPixel(const TPixelCoord& pt, const mrpt::img::TColor& color); void setPixelGray( const TPixelCoord& pt, const uint8_t& grayLevel ); virtual void drawImage(const TPixelCoord& pt, const mrpt::img::CImage& img); virtual void filledRectangle(const TPixelCoord& pt0, const TPixelCoord& pt1, mrpt::img::TColor color); CImage scaleHalf(TInterpolationMethod interp) const; bool scaleHalf(CImage& out_image, TInterpolationMethod interp) const; CImage scaleDouble(TInterpolationMethod interp) const; void scaleDouble(CImage& out_image, TInterpolationMethod interp) const; void extract_patch(CImage& patch, const TPixelCoord& top_left_corner, const TImageSize& patch_size) const; void normalize(); void flipVertical(); void flipHorizontal(); void swapRB(); void undistort(CImage& out_img, const mrpt::img::TCamera& cameraParams) const; void filterMedian(CImage& out_img, int W = 3) const; void filterGaussian(CImage& out_img, int W = 3, int H = 3, double sigma = 1.0) const; bool drawChessboardCorners( const std::vector<TPixelCoordf>& cornerCoords, unsigned int check_size_x, unsigned int check_size_y, unsigned int lines_width = 1, unsigned int circles_radius = 4 ); void joinImagesHorz(const CImage& im1, const CImage& im2); float KLT_response(const TPixelCoord& pt, int32_t half_window_size) const; CImage makeShallowCopy() const; CImage makeDeepCopy() const; void copyFromForceLoad(const CImage& o); void swap(CImage& o); template <typename T> const T& at(int32_t col, int32_t row, int8_t channel = 0) const; template <typename T> T& at( int32_t col, int32_t row, int8_t channel = 0 ); template <typename T> const T* ptr(int32_t col, int32_t row, int8_t channel = 0) const; template <typename T> T* ptr( int32_t col, int32_t row, int8_t channel = 0 ); template <typename T> const T* ptrLine(int32_t row) const; template <typename T> T* ptrLine(int32_t row); float getAsFloat(const TPixelCoord& pt, int8_t channel) const; float getAsFloat(const TPixelCoord& pt) const; virtual int32_t getWidth() const; virtual int32_t getHeight() const; TImageSize getSize() const; size_t getRowStride() const; std::string getChannelsOrder() const; TImageChannels channels() const; bool isColor() const; bool isEmpty() const; 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, bool normalize_01 = true ) const; void getAsMatrix( mrpt::math::CMatrix_u8& outMatrix, bool doResize = true, int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1 ) const; std::tuple<mrpt::math::CMatrixFloat, mrpt::math::CMatrixFloat, mrpt::math::CMatrixFloat> getAsRGBMatricesFloat(int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1) const; std::tuple<mrpt::math::CMatrix_u8, mrpt::math::CMatrix_u8, mrpt::math::CMatrix_u8> getAsRGBMatricesBytes( int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1 ) const; CImage grayscale() const; bool grayscale(CImage& ret) const; CImage colorImage() const; void colorImage(CImage& ret) const; };
Inherited Members
public: // typedefs typedef std::shared_ptr<CObject> Ptr; typedef std::shared_ptr<const CObject> ConstPtr; typedef std::shared_ptr<CSerializable> Ptr; typedef std::shared_ptr<const CSerializable> ConstPtr; // enums enum TPenStyle; // methods static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const; virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const; static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); CCanvas& operator = (const CCanvas& other); CCanvas& operator = (CCanvas&& other); virtual void setPixel(const TPixelCoord& pt, const mrpt::img::TColor& color) = 0; virtual int32_t getWidth() const = 0; virtual int32_t getHeight() const = 0; virtual void line( const TPixelCoord& pt0, const TPixelCoord& pt1, const mrpt::img::TColor& color, int32_t width = 1, TPenStyle penStyle = psSolid ); void rectangle(const TPixelCoord& pt0, const TPixelCoord& pt1, const mrpt::img::TColor& color, int32_t width = 1); void triangle(const TPixelCoord& pt, int32_t size, mrpt::img::TColor color, bool inferior = true, int32_t width = 1); virtual void filledRectangle(const TPixelCoord& pt0, const TPixelCoord& pt1, mrpt::img::TColor color); virtual void textOut(const TPixelCoord& pt, const std::string& str, mrpt::img::TColor color); virtual void selectTextFont(const std::string& fontName); virtual void drawImage(const TPixelCoord& pt, const mrpt::img::CImage& img); void drawMark(const TPixelCoord& pt, const mrpt::img::TColor& color, char type, int32_t size = 5, int32_t width = 1); virtual void drawCircle( const TPixelCoord& center, int32_t radius, const mrpt::img::TColor& color = mrpt::img::TColor(255, 255, 255), int32_t width = 1 ); void ellipseGaussian( const mrpt::math::CMatrixFixed<double, 2, 2>& cov2D, double mean_x, double mean_y, double confIntervalStds = 2, const mrpt::img::TColor& color = mrpt::img::TColor(255, 255, 255), int32_t width = 1, int nEllipsePoints = 20 );
Typedefs
typedef std::shared_ptr<mrpt::img ::CImage> Ptr
A type for the associated smart pointer.
Construction
CImage()
Default constructor: initialize to empty image.
It’s an error trying to access the image in such a state (except reading the image width/height, which are both zero). Either call resize(), assign from another image, load from disk, deserialize from an archive, etc. to properly initialize the image.
CImage(int32_t width, int32_t height, TImageChannels nChannels = CH_RGB)
Constructor for a given image size and type.
Examples:
CImage img1(width, height, CH_GRAY ); // Grayscale image (8U1C) CImage img2(width, height, CH_RGB ); // RGB image (8U3C)
CImage(const CImage& other_img, ] ctor_CImage_ref_or_gray _)
Fast constructor of a grayscale version of another image, making a shallow copy from the original image if it already was grayscale, or otherwise creating a new grayscale image and converting the original image into it.
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. }
CImage(const CImage& img, copy_type_t copy_type)
Constructor from another CImage, making or not a deep copy of the data.
Methods
virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const
Returns information about the class of an object in runtime.
virtual mrpt::rtti::CObject* clone() const
Returns a deep copy (clone) of the object, indepently of its class.
static const std::string& getImagesPathBase()
By default, “.”.
Since MRPT 2.3.3 this is a synonym with mrpt::io::getLazyLoadPathBase()
See also:
static void setImagesPathBase(const std::string& path)
Since MRPT 2.3.3 this is a synonym with mrpt::io::setLazyLoadPathBase()
void 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::getImagesPathBase() 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 );
Modifications to the memory copy of the image are not automatically saved to disk.
See also:
bool isExternallyStored() const
See setExternalStorage().
std::string getExternalStorageFile() const
Only if isExternallyStored() returns true.
See also:
getExternalStorageFileAbsolutePath
void getExternalStorageFileAbsolutePath(std::string& out_path) const
Only if isExternallyStored() returns true.
See also:
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
See also:
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory.
Note that usually images are loaded on-the-fly on first access and there’s no need to call this.
See also:
void unload() const
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.
See also:
void cross_correlation_FFT( const CImage& in_img, mrpt::math::CMatrixFloat& out_corr, std::optional<int32_t> u_search_ini = std::nullopt, std::optional<int32_t> v_search_ini = std::nullopt, std::optional<int32_t> u_search_size = std::nullopt, std::optional<int32_t> v_search_size = std::nullopt, std::optional<float> biasThisImg = std::nullopt, std::optional<float> biasInImg = std::nullopt ) const
Computes the correlation matrix between this image and another one.
This implementation uses the 2D FFT for achieving reduced computation time.
Parameters:
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 subtracted to the pixels of “this” image before performing correlation. |
biasInImg |
This optional parameter is a fixed “bias” value to be subtracted 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) |
static mrpt::img::CImage LoadFromFile( const std::string& fileName, TImageChannels loadChannels = CH_AS_IS )
Static method to construct an CImage object from a file.
See CImage::loadFromFile() for meaning of parameters.
New in MRPT 2.4.2
Parameters:
std::exception |
On load error. |
void loadFromMemoryBuffer( int32_t width, int32_t height, TImageChannels color_channels, uint8_t* rawpixels, bool swapRedBlue = false )
Reads the image from raw pixels buffer in memory.
template <typename MAT> void setFromMatrix( const MAT& m, bool matrix_is_normalized = true, bool flip_vertically = false )
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0,1] (normalized=true) or [0,255] (normalized=false) Matrix indexes are assumed to be in this order: M(row,column)
See also:
template <typename MAT> void setFromRGBMatrices( const MAT& r, const MAT& g, const MAT& b, bool matrix_is_normalized = true )
Set the image from RGB matrices, given the pixels in the range [0,1] (normalized=true) or [0,255] (normalized=false) Matrix indexes are assumed to be in this order: M(row,column)
See also:
getAsRGBMatrices
void loadFromStreamAsJPEG(mrpt::io::CStream& in)
Reads the image from a binary stream containing a binary jpeg file.
Parameters:
std::exception |
On pixel coordinates out of bounds |
bool loadFromFile(const std::string& fileName, TImageChannels loadChannels = CH_AS_IS)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
MRPT also provides the special loader loadFromXPM().
Parameters:
fileName |
The file to read from. |
Returns:
False on any error
See also:
saveToFile, setExternalStorage, loadFromXPM
bool loadFromXPM(const char*const* xpm_array, bool swap_rb = true)
Loads the image from an XPM array, as included from a “.xpm” file.
Parameters:
swap_rb |
Swaps red/blue channels from loaded image. Seems to be always needed, so it’s enabled by default. |
Returns:
false on any error
See also:
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 the stb library).
The supported formats are:
*.png: Portable Network Graphics*.bmp: Windows bitmaps*.tga: TGA files*.jpeg|*.jpg: JPEG files
Parameters:
fileName |
The file to write to. |
jpeg_quality |
Only for JPEG files, the quality of the compression in the range [0-100]. Larger is better quality but slower. |
Returns:
False on any error
See also:
void saveToStreamAsJPEG(mrpt::io::CStream& out, int jpeg_quality = 95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
Parameters:
std::exception |
On number of rows or cols equal to zero or other errors. |
See also:
saveToJPEG
void clear()
Resets the image to the state after a default ctor.
Accessing the image after will throw an exception, unless it is formerly initialized somehow: loading an image from disk, calling resize(), etc.
void resize(int32_t width, int32_t height, TImageChannels nChannels, PixelDepth depth = PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content, for that, see scaleImage).
See also:
void scaleImage(CImage& out_img, int32_t width, int32_t 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, or operating in-place if out_img==this.
See also:
void rotateImage( CImage& out_img, double ang, const TPixelCoord& center, double scale = 1.0 ) const
Rotates the image by the given angle (in radians) around the given center point, with an optional scale factor.
Uses bilinear interpolation; fills out-of-bounds pixels with zero.
See also:
virtual void setPixel(const TPixelCoord& pt, const mrpt::img::TColor& color)
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. If writing into an grayscale image, only the BLUE channel (least significant byte) will be used from the incoming RGBA color.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
See also:
virtual void drawImage(const TPixelCoord& pt, const mrpt::img::CImage& img)
Draws an image as a bitmap at a given position.
Parameters:
pt |
The top-left corner on this canvas where the image is to be drawn |
img |
The image to be drawn in this canvas This method may be redefined in some classes implementing this interface in a more appropriate manner. |
virtual void filledRectangle(const TPixelCoord& pt0, const TPixelCoord& pt1, mrpt::img::TColor color)
Draws a filled rectangle.
Parameters:
pt0 |
The top-left point |
pt1 |
The right-bottom point |
color |
The color of the rectangle fill This method may be redefined in some classes implementing this interface in a more appropriate manner. |
See also:
CImage scaleHalf(TInterpolationMethod interp) const
Returns a new image scaled down to half its original size.
Parameters:
std::exception |
On odd size |
See also:
bool scaleHalf(CImage& out_image, TInterpolationMethod interp) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns:
true if an optimized SSE2/SSE3 version could be used.
CImage scaleDouble(TInterpolationMethod interp) const
Returns a new image scaled up to double its original size.
Parameters:
std::exception |
On odd size |
See also:
void scaleDouble(CImage& out_image, TInterpolationMethod interp) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void extract_patch(CImage& patch, const TPixelCoord& top_left_corner, const TImageSize& patch_size) const
Extract a patch from this image, saving it into “patch” (its previous contents will be overwritten).
The patch to extract starts at (col,row) and has the given dimensions.
void normalize()
Optimize the brightness range of an image without using histogram (linear stretch to [0,255]).
Works on images of any number of channels.
void flipVertical()
Flips the image vertically.
See also:
void flipHorizontal()
Flips the image horizontally.
See also:
void swapRB()
Swaps red and blue channels.
void undistort(CImage& out_img, const mrpt::img::TCamera& cameraParams) const
Undistort the image according to some camera parameters, using a precomputed remap (CUndistortMap).
void filterMedian(CImage& out_img, int W = 3) const
Filter the image with a Median filter with a window size WxW (W must be odd).
void filterGaussian(CImage& out_img, int W = 3, int H = 3, double sigma = 1.0) const
Filter the image with a Gaussian filter with a window size WxH (both must be odd).
Separable 1D convolution.
bool drawChessboardCorners( const 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 joinImagesHorz(const CImage& im1, const CImage& im2)
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)
float KLT_response(const TPixelCoord& pt, int32_t half_window_size) const
Compute the KLT response at a given pixel (x,y) - Only for grayscale images.
CImage makeShallowCopy() const
Returns a shallow copy of the original image.
CImage makeDeepCopy() const
Returns a deep copy of this image.
If the image is externally-stored, there is no difference with a shallow copy.
See also:
void copyFromForceLoad(const CImage& o)
Copies from another image (shallow copy), and, if it is externally stored, the image file will be actually loaded into memory in “this” object.
Parameters:
If the external image couldn’t be loaded. |
See also:
operator =
void swap(CImage& o)
Efficiently swap of two images.
template <typename T> const T& at(int32_t col, int32_t row, int8_t channel = 0) const
Access to pixels without checking boundaries, and doing a reinterpret_cast<> of the data as the given type.
See also:
The CImage::operator() which does check for coordinate limits.
template <typename T> const T* ptr( int32_t col, int32_t row, int8_t channel = 0 ) const
Returns a pointer to a given pixel, without checking for boundaries.
See also:
The CImage::operator() which does check for coordinate limits.
template <typename T> const T* ptrLine(int32_t row) const
Returns a pointer to the first pixel of the given line.
See also:
float getAsFloat(const TPixelCoord& pt, int8_t 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.
Parameters:
std::exception |
On pixel coordinates out of bounds |
float getAsFloat(const TPixelCoord& pt) 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.
Parameters:
std::exception |
On pixel coordinates out of bounds |
virtual int32_t getWidth() const
Returns the width of the image in pixels.
See also:
virtual int32_t getHeight() const
Returns the height of the image in pixels.
See also:
TImageSize getSize() const
Return the size of the image.
See also:
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows.
You can access the pointer to the first row with ptrLine(0)
See also:
std::string getChannelsOrder() const
As of mrpt 3.0.0, this returns either “GRAY”, “RGB”, or “RGBA”.
TImageChannels channels() const
Returns 1 (grayscale), 3 (RGB) or 4 (RGBA)
bool isColor() const
Returns true if the image is RGB or RGBA, false if it is grayscale.
bool isEmpty() const
Returns true if the object is in the state after default constructor.
Returns false for delay-loaded images, disregarding whether the image is actually on disk or memory.
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, bool normalize_01 = true ) const
Returns the image as a matrix with pixel grayscale values in the range [0,1].
Matrix indexes in this order: M(row,column)
Parameters:
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. |
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) |
normalize_01 |
Normalize the image values such that they fall in the range [0,1] (default: true). If set to false, the matrix will hold numbers in the range [0,255]. |
See also:
std::tuple<mrpt::math::CMatrixFloat, mrpt::math::CMatrixFloat, mrpt::math::CMatrixFloat> getAsRGBMatricesFloat( int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1 ) const
Returns three image as [R,G,B] matrices with pixel values in the range [0,1].
Matrix indexes in this order: M(row,column)
Parameters:
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) |
See also:
CImage grayscale() const
Returns a grayscale version of the image, or a shallow copy of itself if it is already a grayscale image.
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a color image.
See also: