23 namespace cv {
class Mat; }
175 unsigned int width,
unsigned int height,
266 CImage& out_img,
unsigned int width,
unsigned int height,
274 CImage& out_img,
double ang,
unsigned int cx,
unsigned int cy,
275 double scale = 1.0)
const;
289 void setPixel(
int x,
int y,
size_t color)
override;
298 int x,
int y,
int radius,
300 unsigned int width = 1)
override;
347 const CImage& patch,
const unsigned int col,
const unsigned int row);
355 CImage& patch,
const unsigned int col = 0,
const unsigned int row = 0,
356 const unsigned int width = 1,
const unsigned int height = 1)
const;
365 const CImage& img2int,
int width_init = 0,
int height_init = 0)
const;
388 int u_search_ini = -1,
int v_search_ini = -1,
int u_search_size = -1,
389 int v_search_size = -1,
float biasThisImg = 0,
390 float biasInImg = 0)
const;
436 CImage& out_img,
int W = 3,
int H = 3,
double sigma = 1.0)
const;
451 std::vector<TPixelCoordf>& cornerCoords,
unsigned int check_size_x,
452 unsigned int check_size_y,
unsigned int lines_width = 1,
453 unsigned int circles_radius = 4);
470 const unsigned int x,
const unsigned int y,
471 const unsigned int half_window_size)
const;
477 [[deprecated(
"Use makeShallowCopy() instead")]]
inline void 506 [[deprecated(
"Use a=std::move(b); instead ")]]
inline void copyFastFrom(
509 *
this = std::move(o);
520 "Prefer a ctor from a cv::Mat instead or use loadFromIplImage() " 521 "explicitly specifying the kind of copy to be done")]]
inline void 539 template <
typename CV_MAT>
558 [[deprecated(
"Use at<>(), ptr<>() or ptrLine() instead ")]] uint8_t*
560 unsigned int col,
unsigned int row, uint8_t channel = 0)
const;
566 template <
typename T>
568 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const 570 return *
reinterpret_cast<const T*
>(
internal_get(col, row, channel));
573 template <
typename T>
574 T&
at(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
576 return *
reinterpret_cast<T*
>(
internal_get(col, row, channel));
582 template <
typename T>
584 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const 586 return reinterpret_cast<const T*
>(
internal_get(col, row, channel));
589 template <
typename T>
590 T*
ptr(
unsigned int col,
unsigned int row,
unsigned int channel = 0)
592 return reinterpret_cast<T*
>(
internal_get(col, row, channel));
596 template <
typename T>
599 return reinterpret_cast<const T*
>(
internal_get(0, row, 0));
602 template <
typename T>
615 unsigned int col,
unsigned int row,
unsigned int channel)
const;
624 float getAsFloat(
unsigned int col,
unsigned int row)
const;
631 unsigned int col,
unsigned int row,
unsigned int channel = 0)
const;
701 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1,
702 bool normalize_01 =
true)
const;
707 int y_min = 0,
int x_max = -1,
int y_max = -1)
const;
729 int x_min = 0,
int y_min = 0,
int x_max = -1,
int y_max = -1)
const;
735 int y_min = 0,
int x_max = -1,
int y_max = -1)
const;
815 void unload() const noexcept;
827 unsigned int width,
unsigned int height,
bool color,
828 unsigned char* rawpixels,
bool swapRedBlue = false);
835 unsigned int width,
unsigned int height,
unsigned int bytesPerRow,
836 unsigned char* red,
unsigned char* green,
unsigned char* blue);
843 template <typename MAT>
847 const unsigned int lx = m.cols();
848 const unsigned int ly = m.rows();
850 if (matrix_is_normalized)
852 for (
unsigned int y = 0; y < ly; y++)
854 auto* pixels = ptrLine<uint8_t>(y);
855 for (
unsigned int x = 0; x < lx; x++)
856 (*pixels++) =
static_cast<uint8_t
>(m.coeff(y, x) * 255);
861 for (
unsigned int y = 0; y < ly; y++)
863 auto* pixels = ptrLine<uint8_t>(y);
864 for (
unsigned int x = 0; x < lx; x++)
865 (*pixels++) =
static_cast<uint8_t
>(m.coeff(y, x));
876 template <
typename MAT>
878 const MAT& r,
const MAT& g,
const MAT& b,
879 bool matrix_is_normalized =
true)
883 ASSERT_((r.size() == g.size()) && (r.size() == b.size()));
884 const unsigned int lx = r.cols(), ly = r.rows();
887 if (matrix_is_normalized)
889 for (
unsigned int y = 0; y < ly; y++)
891 auto* pixels = ptrLine<uint8_t>(y);
892 for (
unsigned int x = 0; x < lx; x++)
894 (*pixels++) = static_cast<uint8_t>(r.coeff(y, x) * 255);
895 (*pixels++) = static_cast<uint8_t>(g.coeff(y, x) * 255);
896 (*pixels++) = static_cast<uint8_t>(b.coeff(y, x) * 255);
902 for (
unsigned int y = 0; y < ly; y++)
904 auto* pixels = ptrLine<uint8_t>(y);
905 for (
unsigned int x = 0; x < lx; x++)
907 (*pixels++) = static_cast<uint8_t>(r.coeff(y, x));
908 (*pixels++) = static_cast<uint8_t>(g.coeff(y, x));
909 (*pixels++) = static_cast<uint8_t>(b.coeff(y, x));
956 bool loadFromXPM(
const char*
const* xpm_array,
bool swap_rb =
true);
978 bool saveToFile(
const std::string& fileName,
int jpeg_quality = 95)
const;
1044 uint8_t*
internal_get(
int col,
int row, uint8_t channel = 0)
const;
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.
bool isEmpty() const
Returns true if the object is in the state after default constructor.
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 ...
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.
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()
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...
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...
DECLARE_MEXPLUS_FROM(mrpt::img::TCamera) namespace std
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.
Parameters for the Brown-Conrady camera lens distortion model.
void getAsIplImage(IplImage *dest) const
(DEPRECATED, DO NOT USE - Kept here only to interface opencv 2.4)
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.
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
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...
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)
mrpt::vision::TStereoCalibResults out
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.
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)...
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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()
static bool DISABLE_ZIP_COMPRESSION()
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...
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, ".".