22 namespace cv {
class Mat; }
273 CImage& out_img,
double ang,
unsigned int cx,
unsigned int cy,
274 double scale = 1.0)
const;
297 int x,
int y,
int radius,
299 unsigned int width = 1)
override;
346 const CImage& patch,
const unsigned int col,
const unsigned int row);
354 CImage& patch,
const unsigned int col = 0,
const unsigned int row = 0,
355 const unsigned int width = 1,
const unsigned int height = 1)
const;
364 const CImage& img2int,
int width_init = 0,
int height_init = 0)
const;
387 int u_search_ini = -1,
int v_search_ini = -1,
int u_search_size = -1,
388 int v_search_size = -1,
float biasThisImg = 0,
389 float biasInImg = 0)
const;
433 CImage& out_img,
int W = 3,
int H = 3,
double sigma = 1.0)
const;
448 std::vector<TPixelCoordf>& cornerCoords,
unsigned int check_size_x,
449 unsigned int check_size_y,
unsigned int lines_width = 1,
450 unsigned int circles_radius = 4);
467 const unsigned int x,
const unsigned int y,
468 const unsigned int half_window_size)
const;
474 [[deprecated(
"Use makeShallowCopy() instead")]]
inline void 503 [[deprecated(
"Use a=std::move(b); instead ")]]
inline void copyFastFrom(
506 *
this = std::move(o);
517 "Prefer a ctor from a cv::Mat instead or use loadFromIplImage() " 518 "explicitly specifying the kind of copy to be done")]]
inline void 536 template <
typename CV_MAT>
555 [[deprecated(
"Use at<>(), ptr<>() or ptrLine() instead ")]]
uint8_t*
557 unsigned int col,
unsigned int row,
uint8_t channel = 0)
const;
563 template <
typename T>
565 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const 570 template <
typename T>
571 T&
at(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
579 template <
typename T>
581 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const 586 template <
typename T>
587 T*
ptr(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
593 template <
typename T>
599 template <
typename T>
612 unsigned int col,
unsigned int row,
unsigned int channel)
const;
628 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const;
695 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1,
696 bool normalize_01 =
true)
const;
718 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1)
const;
798 void unload() const noexcept;
811 unsigned char* rawpixels,
bool swapRedBlue = false);
818 unsigned int width,
unsigned int height,
unsigned int bytesPerRow,
819 unsigned char*
red,
unsigned char*
green,
unsigned char*
blue);
826 template <typename MAT>
830 const unsigned int lx = m.cols();
831 const unsigned int ly = m.rows();
833 if (matrix_is_normalized)
835 for (
unsigned int y = 0;
y < ly;
y++)
837 auto*
pixels = ptrLine<uint8_t>(
y);
838 for (
unsigned int x = 0;
x < lx;
x++)
844 for (
unsigned int y = 0;
y < ly;
y++)
846 auto*
pixels = ptrLine<uint8_t>(
y);
847 for (
unsigned int x = 0;
x < lx;
x++)
859 template <
typename MAT>
861 const MAT&
r,
const MAT&
g,
const MAT&
b,
862 bool matrix_is_normalized =
true)
866 ASSERT_((
r.size() ==
g.size()) && (
r.size() ==
b.size()));
867 const unsigned int lx =
r.cols(), ly =
r.rows();
870 if (matrix_is_normalized)
872 for (
unsigned int y = 0;
y < ly;
y++)
874 auto*
pixels = ptrLine<uint8_t>(
y);
875 for (
unsigned int x = 0;
x < lx;
x++)
877 (*
pixels++) = static_cast<uint8_t>(
r.coeff(
y,
x) * 255);
878 (*
pixels++) = static_cast<uint8_t>(
g.coeff(
y,
x) * 255);
879 (*
pixels++) = static_cast<uint8_t>(
b.coeff(
y,
x) * 255);
885 for (
unsigned int y = 0;
y < ly;
y++)
887 auto*
pixels = ptrLine<uint8_t>(
y);
888 for (
unsigned int x = 0;
x < lx;
x++)
890 (*
pixels++) = static_cast<uint8_t>(
r.coeff(
y,
x));
891 (*
pixels++) = static_cast<uint8_t>(
g.coeff(
y,
x));
892 (*
pixels++) = static_cast<uint8_t>(
b.coeff(
y,
x));
939 bool loadFromXPM(
const char*
const* xpm_array,
bool swap_rb =
true);
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 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.
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.
CImage makeShallowCopy() const
Returns a shallow copy of the original image.
Shallow copy: the copied object is a reference to the original one.
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.
Used in mrpt::img::CImage.
ctor_CImage_ref_or_gray
For usage in one of the CImage constructors.
This virtual class defines the interface of any object accepting drawing primitives on it...
TPenStyle
Definition of pen styles.
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 getAsMatrixTiled(mrpt::math::CMatrixFloat &outMatrix) const
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to ...
static bool DISABLE_ZIP_COMPRESSION()
CImage scaleHalf(TInterpolationMethod interp) const
Returns a new image scaled down to half its original size.
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].
const T * ptrLine(unsigned int row) const
Returns a pointer to the first pixel of the given line.
GLenum GLenum GLenum GLenum GLenum scale
void copyFromForceLoad(const CImage &o)
Copies from another image (shallow copy), and, if it is externally stored, the image file will be act...
spimpl::impl_ptr< T > pimpl
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].
static bool DISABLE_JPEG_COMPRESSION()
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class...
GLdouble GLdouble GLdouble GLdouble q
copy_type_t
Define kind of copies.
CExceptionExternalImageNotFound(const std::string &s)
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1]. ...
void drawImage(int x, int y, const mrpt::img::CImage &img) override
Draws an image as a bitmap at a given position.
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
void flipHorizontal()
Flips the image horizontally.
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
size_t getHeight() const override
Returns the height of the image in pixels.
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 ...
std::string getChannelsOrder() const
As of mrpt 2.0.0, this returns either "GRAY" or "BGR".
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...
GLint GLint GLsizei GLsizei GLsizei depth
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...
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it...
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, replacing "this" image by the filtere...
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
bool isExternallyStored() const noexcept
See setExternalStorage().
const T & at(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries, and doing a reinterpret_cast<> of the data as the given...
void unload() const noexcept
For external storage image objects only, this method unloads the image from memory (or does nothing i...
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,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
mrpt::pimpl< Impl > m_impl
void swap(CImage &o)
Efficiently swap of two images.
void asCvMat(cv::Mat &out_img, copy_type_t copy_type) const
Makes a shallow or deep copy of this image into the provided cv::Mat.
T & at(unsigned int col, unsigned int row, unsigned int channel=0)
void swapRB()
Swaps red and blue channels.
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a ...
#define ASSERT_(f)
Defines an assertion mechanism.
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV)...
size_t getWidth() const override
Returns the width of the image in pixels.
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...
void resize(std::size_t width, std::size_t height, TImageChannels nChannels, PixelDepth depth=PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
unsigned char * operator()(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel information.
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process.
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class...
void internal_fromIPL(const IplImage *iplImage, copy_type_t c)
void saveToStreamAsJPEG(mrpt::io::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format.
void loadFromIplImage(const IplImage *iplImage, copy_type_t c=DEEP_COPY)
Assigns from an image in IplImage format.
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images...
A pair (x,y) of pixel coordinates (integer resolution).
void flipVertical()
Flips the image vertically.
void setFromMatrix(const MAT &m, bool matrix_is_normalized=true)
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0...
uint8_t * get_unsafe(unsigned int col, unsigned int row, uint8_t channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates.
Structure to hold the parameters of a pinhole camera model.
std::string getExternalStorageFile() const noexcept
Only if isExternallyStored() returns true.
void loadFromStreamAsJPEG(mrpt::io::CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
void rectifyImageInPlace(void *mapX, void *mapY)
Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed...
TImageSize getSize() const
Return the size of the image.
GLsizei const GLchar ** string
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
void clear()
Resets the image to the state after a default ctor.
uint8_t * internal_get(int col, int row, uint8_t channel=0) const
CImage grayscale() const
Returns a grayscale version of the image, or a shallow copy of itself if it is already a grayscale im...
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.
CV_MAT asCvMat(copy_type_t copy_type) const
void setFromIplImageReadOnly(IplImage *iplImage)
void setPixel(int x, int y, size_t color) override
Changes the value of the pixel (x,y).
T * ptr(unsigned int col, unsigned int row, unsigned int channel=0)
PixelDepth getPixelDepth() const
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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...
CImage()
Default constructor: initialize to empty image.
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 ima...
GLdouble GLdouble GLdouble r
CImage makeDeepCopy() const
Returns a deep copy of this image.
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
TInterpolationMethod
Interpolation methods for images.
bool isOriginTopLeft() const
Returns true (as of MRPT v2.0.0, it's fixed)
struct _IplImage IplImage
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
Deep copy: the copied object has a duplicate of all data, becoming independent.
GLenum GLenum GLvoid * row
const T * ptr(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel, without checking for boundaries.
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows...
CImage scaleDouble(TInterpolationMethod interp) const
Returns a new image scaled up to double its original size.
void rotateImage(CImage &out_img, double ang, unsigned int cx, unsigned int cy, double scale=1.0) const
Rotates the image by the given angle around the given center point, with an optional scale factor...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
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)...
T * ptrLine(unsigned int row)
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)...
TImageChannels
For use in mrpt::img::CImage.
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...
static int SERIALIZATION_JPEG_QUALITY()
void undistort(CImage &out_img, const mrpt::img::TCamera &cameraParams) const
Undistort the image according to some camera parameters, and returns an output undistorted image...
GLenum GLsizei GLsizei height
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
std::string m_externalFile
The file name of a external storage image.
static void setImagesPathBase(const std::string &path)
void equalizeHist(CImage &out_img) const
Equalize the image histogram, saving the new image in the given output object.
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory...
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 setFromImageReadOnly(const CImage &o)
A class for storing images as grayscale or RGB bitmaps.
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.
static const std::string & getImagesPathBase()
By default, ".".