MRPT  1.9.9
img/CImage.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/core/pimpl.h>
12 #include <mrpt/img/CCanvas.h>
13 #include <mrpt/img/TCamera.h>
14 #include <mrpt/img/TPixelCoord.h>
17 
18 // Forwards decls:
19 // clang-format off
20 struct _IplImage;
21 using IplImage = struct _IplImage;
22 namespace cv { class Mat; }
23 namespace mrpt::io { class CStream; }
24 // clang-format on
25 
26 // Add for declaration of mexplus::from template specialization
28 
29 namespace mrpt::img
30 {
31 enum class PixelDepth : int32_t
32 {
33  D8U = 0,
34  D8S = 1,
35  D16U = 2,
36  D16S = 3,
37  D32S = 4,
38  D32F = 5,
39  D64F = 6
40 };
41 
42 /** Interpolation methods for images.
43  * Used for OpenCV related operations with images, but also with MRPT native
44  * classes.
45  * \sa mrpt::img::CMappedImage, CImage::scaleImage
46  * \note These are numerically compatible to cv::InterpolationFlags
47  * \ingroup mrpt_img_grp
48  */
50 {
55 };
56 
57 /** For use in mrpt::img::CImage */
58 enum TImageChannels : uint8_t
59 {
60  CH_GRAY = 1,
61  CH_RGB = 3
62 };
63 
64 /** For usage in one of the CImage constructors */
66 {
68 };
69 
70 /** Define kind of copies */
72 {
73  /** Shallow copy: the copied object is a reference to the original one */
75  /** Deep copy: the copied object has a duplicate of all data, becoming
76  independent */
78 };
79 
80 /** Used in mrpt::img::CImage */
81 class CExceptionExternalImageNotFound : public std::runtime_error
82 {
83  public:
85 };
86 
87 /** A class for storing images as grayscale or RGB bitmaps.
88  * I/O is supported as:
89  * - Binary dump using the CSerializable interface(<< and >> operators),
90  *just as most objects in MRPT. This format is not compatible with any
91  *standarized image format but it is fast.
92  * - Saving/loading from files of different formats (bmp,jpg,png,...) using
93  *the methods CImage::loadFromFile and CImage::saveToFile. See OpenCV for the
94  *list of supported formats.
95  * - Importing from an XPM array (.xpm file format) using CImage::loadFromXPM()
96  * - Importing TGA images. See CImage::loadTGA()
97  *
98  * How to create color/grayscale images:
99  * \code
100  * CImage img1(width, height, CH_GRAY ); // Grayscale image (8U1C)
101  * CImage img2(width, height, CH_RGB ); // RGB image (8U3C)
102  * \endcode
103  *
104  * Additional notes:
105  * - The OpenCV `cv::Mat` format is used internally for compatibility with
106  * all OpenCV functions. Use CImage::asCvMat() to retrieve it. Example:
107  * \code
108  * CImage img;
109  * ...
110  * cv::Mat m = img.asCvMat()
111  * \endcode
112  * - By default, all images use unsigned 8-bit storage format for pixels (on
113  *each channel), but it can be changed by flags in the constructor.
114  * - An **external storage mode** can be enabled by calling
115  *CImage::setExternalStorage, useful for storing large collections of image
116  *objects in memory while loading the image data itself only for the relevant
117  *images at any time. See CImage::forceLoad() and CImage::unload().
118  * - Operator = and copy ctor make shallow copies. For deep copies, see
119  * CImage::makeDeepCopy() or CImage(const CImage&, copy_type_t), e.g:
120  * \code
121  * CImage a(20, 10, CH_GRAY);
122  * // Shallow copy ctor:
123  * CImage b(a, mrpt::img::SHALLOW_COPY);
124  * CImage c(a, mrpt::img::DEEP_COPY);
125  * \endcode
126  * - If you are interested in a smart pointer to an image, use:
127  * \code
128  * CImage::Ptr myImg = CImage::Create(); // optional ctor arguments
129  * // or:
130  * CImage::Ptr myImg = std::make_shared<CImage>(...);
131  * \endcode
132  * - To set a CImage from an OpenCV `cv::Mat` use
133  *CImage::CImage(cv::Mat,copy_type_t).
134  *
135  * Some functions are implemented in MRPT with highly optimized SSE2/SSE3
136  *routines, in suitable platforms and compilers. To see the list of
137  * optimizations refer to \ref sse_optimizations, falling back to default OpenCV
138  *methods where unavailable.
139  *
140  * For computer vision functions that use CImage as its image data type,
141  *see mrpt::vision.
142  *
143  * \sa mrpt::vision, mrpt::vision::CFeatureExtractor,
144  *mrpt::vision::CImagePyramid, CSerializable, CCanvas
145  * \ingroup mrpt_img_grp
146  */
148 {
150 
151  // This must be added for declaration of MEX-related functions
153 
154  public:
155  /** @name Constructors & destructor
156  @{ */
157 
158  /** Default constructor: initialize to empty image. It's an error trying to
159  * access the image in such a state (except reading the image width/height,
160  * which are both zero). Either call resize(), assign from another image,
161  * load from disk, deserialize from an archive, etc. to properly initialize
162  * the image.
163  */
164  CImage();
165 
166  /** Constructor for a given image size and type.
167  * Examples:
168  * \code
169  * CImage img1(width, height, CH_GRAY ); // Grayscale image (8U1C)
170  * CImage img2(width, height, CH_RGB ); // RGB image (8U3C)
171  * \endcode
172  */
173  CImage(
174  unsigned int width, unsigned int height,
175  TImageChannels nChannels = CH_RGB);
176 
177  /** Fast constructor of a grayscale version of another image, making a
178  * **shallow copy** from the original image if it already was grayscale, or
179  * otherwise creating a new grayscale image and converting the original
180  * image into it.
181  * Example of usage:
182  * \code
183  * void my_func(const CImage &in_img) {
184  * const CImage gray_img(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
185  * // We can now operate on "gray_img" being sure it's in grayscale.
186  * }
187  * \endcode
188  */
189  inline CImage(const CImage& other_img, ctor_CImage_ref_or_gray)
190  {
191  if (other_img.isColor())
192  {
193  *this = CImage();
194  other_img.grayscale(*this);
195  }
196  else
197  {
198  // shallow copy
199  *this = other_img;
200  }
201  }
202 
203  /** Constructor from a cv::Mat image, making or not a deep copy of the data
204  */
205  CImage(const cv::Mat& img, copy_type_t copy_type);
206 
207  /** Constructor from another CImage, making or not a deep copy of the data
208  */
209  CImage(const CImage& img, copy_type_t copy_type);
210 
211  /** @} */
212 
213  /** @name Behavior-changing global flags
214  @{ */
215 
216  /** By default, when storing images through the CSerializable interface,
217  * grayscale images will be ZIP compressed if they are larger than 16Kb:
218  * this flag can be turn on to disable ZIP compression and gain speed versus
219  * occupied space.
220  * (Default = false) */
221  static void DISABLE_ZIP_COMPRESSION(bool val);
222  static bool DISABLE_ZIP_COMPRESSION();
223 
224  /** By default, when storing images through the CSerializable interface, RGB
225  * images are JPEG-compressed to save space. If for some reason you prefer
226  * storing RAW image data, disable this feature by setting this flag to
227  * true.
228  * (Default = true) */
229  static void DISABLE_JPEG_COMPRESSION(bool val);
230  static bool DISABLE_JPEG_COMPRESSION();
231 
232  /** Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range
233  * 1-100) of serialized RGB images.
234  * (Default = 95) */
235  static void SERIALIZATION_JPEG_QUALITY(int q);
236  static int SERIALIZATION_JPEG_QUALITY();
237 
238  /** @} */
239 
240  /** @name Manipulate the image contents or size, various computer-vision
241  methods (image filters, undistortion, etc.)
242  @{ */
243 
244  /** Resets the image to the state after a default ctor. Accessing the image
245  * after will throw an exception, unless it is formerly initialized somehow:
246  * loading an image from disk, calling rezize(), etc. */
247  void clear();
248 
249  /** Changes the size of the image, erasing previous contents (does NOT scale
250  * its current content, for that, see scaleImage).
251  * - nChannels: Can be 3 for RGB images or 1 for grayscale images.
252  * \sa scaleImage
253  */
254  void resize(
255  std::size_t width, std::size_t height, TImageChannels nChannels,
257 
258  PixelDepth getPixelDepth() const;
259 
260  /** Scales this image to a new size, interpolating as needed, saving the new
261  * image in a different output object, or operating in-place if
262  * `out_img==this`. \sa resize, rotateImage
263  */
264  void scaleImage(
265  CImage& out_img, unsigned int width, unsigned int height,
267 
268  /** Rotates the image by the given angle around the given center point, with
269  * an optional scale factor.
270  * \sa resize, scaleImage
271  */
272  void rotateImage(
273  CImage& out_img, double ang, unsigned int cx, unsigned int cy,
274  double scale = 1.0) const;
275 
276  /** Changes the value of the pixel (x,y).
277  * Pixel coordinates starts at the left-top corner of the image, and start
278  * in (0,0).
279  * The meaning of the parameter "color" depends on the implementation: it
280  * will usually
281  * be a 24bit RGB value (0x00RRGGBB), but it can also be just a 8bit gray
282  * level.
283  * This method must support (x,y) values OUT of the actual image size
284  * without neither
285  * raising exceptions, nor leading to memory access errors.
286  * \sa at, ptr
287  */
288  void setPixel(int x, int y, size_t color) override;
289 
290  // See CCanvas docs
291  void line(
292  int x0, int y0, int x1, int y1, const mrpt::img::TColor color,
293  unsigned int width = 1, TPenStyle penStyle = psSolid) override;
294 
295  // See CCanvas docs
296  void drawCircle(
297  int x, int y, int radius,
298  const mrpt::img::TColor& color = mrpt::img::TColor(255, 255, 255),
299  unsigned int width = 1) override;
300 
301  // See CCanvas docs
302  void drawImage(int x, int y, const mrpt::img::CImage& img) override;
303 
304  /** Equalize the image histogram, saving the new image in the given output
305  * object. \note RGB images are first converted to HSV color space, then
306  * equalized for brightness (V) */
307  void equalizeHist(CImage& out_img) const;
308 
309  /** Returns a new image scaled down to half its original size
310  * \exception std::exception On odd size
311  * \sa scaleDouble, scaleImage, scaleHalfSmooth
312  */
314  {
315  CImage ret;
316  this->scaleHalf(ret, interp);
317  return ret;
318  }
319 
320  /** \overload
321  * \return true if an optimized SSE2/SSE3 version could be used. */
322  bool scaleHalf(CImage& out_image, TInterpolationMethod interp) const;
323 
324  /** Returns a new image scaled up to double its original size.
325  * \exception std::exception On odd size
326  * \sa scaleHalf, scaleImage
327  */
329  {
330  CImage ret;
331  this->scaleDouble(ret, interp);
332  return ret;
333  }
334 
335  //! \overload
336  void scaleDouble(CImage& out_image, TInterpolationMethod interp) const;
337 
338  /** Update a part of this image with the "patch" given as argument.
339  * The "patch" will be "pasted" at the (col,row) coordinates of this image.
340  * \exception std::exception if patch pasted on the pixel (_row, _column)
341  * jut out
342  * of the image.
343  * \sa extract_patch
344  */
345  void update_patch(
346  const CImage& patch, const unsigned int col, const unsigned int row);
347 
348  /** Extract a patch from this image, saveing it into "patch" (its previous
349  * contents will be overwritten).
350  * The patch to extract starts at (col,row) and has the given dimensions.
351  * \sa update_patch
352  */
353  void extract_patch(
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;
356 
357  /** Computes the correlation coefficient (returned as val), between two
358  *images
359  * This function use grayscale images only
360  * img1, img2 must be same size
361  * (by AJOGD @ DEC-2006)
362  */
363  float correlate(
364  const CImage& img2int, int width_init = 0, int height_init = 0) const;
365 
366  /** Computes the correlation matrix between this image and another one.
367  * This implementation uses the 2D FFT for achieving reduced computation
368  * time.
369  * \param in_img The "patch" image, which must be equal, or smaller than
370  * "this" image. This function supports gray-scale (1 channel only) images.
371  * \param u_search_ini The "x" coordinate of the search window.
372  * \param v_search_ini The "y" coordinate of the search window.
373  * \param u_search_size The width of the search window.
374  * \param v_search_size The height of the search window.
375  * \param out_corr The output for the correlation matrix, which will be
376  * "u_search_size" x "v_search_size"
377  * \param biasThisImg This optional parameter is a fixed "bias" value to be
378  * substracted to the pixels of "this" image before performing correlation.
379  * \param biasInImg This optional parameter is a fixed "bias" value to be
380  * substracted to the pixels of "in_img" image before performing
381  * correlation. Note: By default, the search area is the whole (this) image.
382  * (by JLBC @ JAN-2006)
383  * \sa cross_correlation
384  */
386  const CImage& in_img, math::CMatrixFloat& out_corr,
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;
390 
391  /** Optimize the brightness range of an image without using histogram
392  * Only for one channel images.
393  * \sa equalizeHist
394  */
395  void normalize();
396 
397  /** Flips the image vertically. \sa swapRB(), flipHorizontal() */
398  void flipVertical();
399  /** Flips the image horizontally \sa swapRB(), flipVertical() */
400  void flipHorizontal();
401 
402  /** Swaps red and blue channels. */
403  void swapRB();
404 
405  /** Undistort the image according to some camera parameters, and
406  * returns an output undistorted image.
407  * \param out_img The output undistorted image
408  * \param cameraParams The input camera params (containing the intrinsic
409  * and distortion parameters of the camera)
410  * \note The intrinsic parameters (fx,fy,cx,cy) of the output image are the
411  * same than in the input image.
412  * \sa mrpt::vision::CUndistortMap
413  */
414  void undistort(
415  CImage& out_img, const mrpt::img::TCamera& cameraParams) const;
416 
417  /** Rectify an image (undistorts and rectification) from a stereo pair
418  * according to a pair of precomputed rectification maps
419  * \param mapX, mapY [IN] The pre-computed maps of the rectification
420  * (should be computed beforehand)
421  * \sa mrpt::vision::CStereoRectifyMap,
422  * mrpt::vision::computeStereoRectificationMaps
423  */
424  void rectifyImageInPlace(void* mapX, void* mapY);
425 
426  /** Filter the image with a Median filter with a window size WxW, returning
427  * the filtered image in out_img. For inplace operation, set out_img to
428  * this. */
429  void filterMedian(CImage& out_img, int W = 3) const;
430 
431  /** Filter the image with a Gaussian filter with a window size WxH,
432  * replacing "this" image by the filtered one. For inplace operation, set
433  * out_img to this. */
434  void filterGaussian(
435  CImage& out_img, int W = 3, int H = 3, double sigma = 1.0) const;
436 
437  /** Draw onto this image the detected corners of a chessboard. The length of
438  * cornerCoords must be the product of the two check_sizes.
439  *
440  * \param cornerCoords [IN] The pixel coordinates of all the corners.
441  * \param check_size_x [IN] The number of squares, in the X direction
442  * \param check_size_y [IN] The number of squares, in the Y direction
443  *
444  * \return false if the length of cornerCoords is inconsistent (nothing is
445  * drawn then).
446  *
447  * \sa mrpt::vision::findChessboardCorners
448  */
450  std::vector<TPixelCoordf>& cornerCoords, unsigned int check_size_x,
451  unsigned int check_size_y, unsigned int lines_width = 1,
452  unsigned int circles_radius = 4);
453 
454  /** Joins two images side-by-side horizontally. Both images must have the
455  * same number of rows and be of the same type (i.e. depth and color mode)
456  *
457  * \param im1 [IN] The first image.
458  * \param im2 [IN] The other image.
459  */
460  void joinImagesHorz(const CImage& im1, const CImage& im2);
461 
462  /** Compute the KLT response at a given pixel (x,y) - Only for grayscale
463  * images (for efficiency it avoids converting to grayscale internally).
464  * See KLT_response() for more details on the internal
465  * optimizations of this method, but this graph shows a general view:
466  * <img src="KLT_response_performance_SSE2.png" >
467  */
468  float KLT_response(
469  const unsigned int x, const unsigned int y,
470  const unsigned int half_window_size) const;
471 
472  /** @} */
473 
474  /** @name Copy, move & swap operations
475  @{ */
476  [[deprecated("Use makeShallowCopy() instead")]] inline void
478  {
479  *this = o.makeShallowCopy();
480  }
481 
482  /** Returns a shallow copy of the original image */
483  inline CImage makeShallowCopy() const
484  {
485  CImage r = *this;
486  return r;
487  }
488 
489  /** Returns a deep copy of this image.
490  * If the image is externally-stored, there is no difference with a shallow
491  * copy. \sa makeShallowCopy() */
492  CImage makeDeepCopy() const;
493 
494  /** Copies from another image (shallow copy), and, if it is externally
495  * stored, the image file will be actually loaded into memory in "this"
496  * object. \sa operator = \exception CExceptionExternalImageNotFound If the
497  * external image couldn't be loaded.
498  */
499  void copyFromForceLoad(const CImage& o);
500 
501  /** Moves an image from another object, erasing the origin image in the
502  * process.
503  * \sa operator =
504  */
505  [[deprecated("Use a=std::move(b); instead ")]] inline void copyFastFrom(
506  CImage& o)
507  {
508  *this = std::move(o);
509  }
510 
511  /** Assigns from an image in IplImage format */
512  inline void loadFromIplImage(
513  const IplImage* iplImage, copy_type_t c = DEEP_COPY)
514  {
515  internal_fromIPL(iplImage, c);
516  }
517 
518  [[deprecated(
519  "Prefer a ctor from a cv::Mat instead or use loadFromIplImage() "
520  "explicitly specifying the kind of copy to be done")]] inline void
522  {
523  internal_fromIPL(iplImage, SHALLOW_COPY);
524  }
525 
526  /** Efficiently swap of two images */
527  void swap(CImage& o);
528 
529  /** @} */
530 
531  /** @name Access to image contents (OpenCV data structure, and raw pixels)
532  @{ */
533 
534  /** Makes a shallow or deep copy of this image into the provided cv::Mat.
535  * \sa asCvMatRef */
536  void asCvMat(cv::Mat& out_img, copy_type_t copy_type) const;
537 
538  template <typename CV_MAT>
539  CV_MAT asCvMat(copy_type_t copy_type) const
540  {
541  CV_MAT ret;
542  asCvMat(ret, copy_type);
543  return ret;
544  }
545 
546  /** Get a reference to the internal cv::Mat, which can be resized, etc. and
547  * changes will be reflected in this CImage object. */
548  cv::Mat& asCvMatRef();
549 
550  /** \overload */
551  const cv::Mat& asCvMatRef() const;
552 
553  /** Access to pixels without checking boundaries - Use normally the ()
554  operator better, which checks the coordinates.
555  \sa CImage::operator()
556  */
557  [[deprecated("Use at<>(), ptr<>() or ptrLine() instead ")]] uint8_t*
558  get_unsafe(
559  unsigned int col, unsigned int row, uint8_t channel = 0) const;
560 
561  /** Access to pixels without checking boundaries, and doing a
562  * reinterpret_cast<> of the data as the given type.
563  *\sa The CImage::operator() which does check for coordinate limits.
564  */
565  template <typename T>
566  const T& at(
567  unsigned int col, unsigned int row, unsigned int channel = 0) const
568  {
569  return *reinterpret_cast<const T*>(internal_get(col, row, channel));
570  }
571  /** \overload Non-const case */
572  template <typename T>
573  T& at(unsigned int col, unsigned int row, unsigned int channel = 0)
574  {
575  return *reinterpret_cast<T*>(internal_get(col, row, channel));
576  }
577 
578  /** Returns a pointer to a given pixel, without checking for boundaries.
579  *\sa The CImage::operator() which does check for coordinate limits.
580  */
581  template <typename T>
582  const T* ptr(
583  unsigned int col, unsigned int row, unsigned int channel = 0) const
584  {
585  return reinterpret_cast<const T*>(internal_get(col, row, channel));
586  }
587  /** \overload Non-const case */
588  template <typename T>
589  T* ptr(unsigned int col, unsigned int row, unsigned int channel = 0)
590  {
591  return reinterpret_cast<T*>(internal_get(col, row, channel));
592  }
593 
594  /** Returns a pointer to the first pixel of the given line.\sa ptr, at */
595  template <typename T>
596  const T* ptrLine(unsigned int row) const
597  {
598  return reinterpret_cast<const T*>(internal_get(0, row, 0));
599  }
600  /** \overload Non-const case */
601  template <typename T>
602  T* ptrLine(unsigned int row)
603  {
604  return reinterpret_cast<T*>(internal_get(0, row, 0));
605  }
606 
607  /** Returns the contents of a given pixel at the desired channel, in float
608  * format: [0,255]->[0,1]
609  * The coordinate origin is pixel(0,0)=top-left corner of the image.
610  * \exception std::exception On pixel coordinates out of bounds
611  * \sa operator()
612  */
613  float getAsFloat(
614  unsigned int col, unsigned int row, unsigned int channel) const;
615 
616  /** Returns the contents of a given pixel (for gray-scale images, in color
617  * images the gray scale equivalent is computed for the pixel), in float
618  * format: [0,255]->[0,1]
619  * The coordinate origin is pixel(0,0)=top-left corner of the image.
620  * \exception std::exception On pixel coordinates out of bounds
621  * \sa operator()
622  */
623  float getAsFloat(unsigned int col, unsigned int row) const;
624 
625  /** Returns a pointer to a given pixel information.
626  * The coordinate origin is pixel(0,0)=top-left corner of the image.
627  * \exception std::exception On pixel coordinates out of bounds
628  */
629  unsigned char* operator()(
630  unsigned int col, unsigned int row, unsigned int channel = 0) const;
631 
632  /** @} */
633 
634  /** @name Query image properties
635  @{ */
636 
637  /** Returns the width of the image in pixels \sa getSize */
638  size_t getWidth() const override;
639  /** Returns the height of the image in pixels \sa getSize */
640  size_t getHeight() const override;
641 
642  /** Return the size of the image \sa getWidth, getHeight */
643  void getSize(TImageSize& s) const;
644  /** Return the size of the image \sa getWidth, getHeight */
645  inline TImageSize getSize() const
646  {
647  TImageSize ret;
648  getSize(ret);
649  return ret;
650  }
651 
652  /** Returns the row stride of the image: this is the number of *bytes*
653  * between two consecutive rows. You can access the pointer to the first row
654  * with ptrLine(0)
655  * \sa getSize, as, ptr, ptrLine */
656  size_t getRowStride() const;
657 
658  /** As of mrpt 2.0.0, this returns either "GRAY" or "BGR". */
660 
661  /** Return the maximum pixel value of the image, as a float value in the
662  * range [0,1]
663  * \sa getAsFloat */
664  float getMaxAsFloat() const;
665 
666  /** Returns true if the image is RGB, false if it is grayscale */
667  bool isColor() const;
668 
669  /** Returns true if the object is in the state after default constructor */
670  bool isEmpty() const;
671 
672  /** Returns true (as of MRPT v2.0.0, it's fixed) */
673  bool isOriginTopLeft() const;
674 
675  /** Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
676  * \sa isColor
677  */
679 
680  /** Returns the image as a matrix with pixel grayscale values in the range
681  * [0,1]. Matrix indexes in this order: M(row,column)
682  * \param doResize If set to true (default), the output matrix will be
683  * always the size of the image at output. If set to false, the matrix will
684  * be enlarged to the size of the image, but it will not be cropped if it
685  * has room enough (useful for FFT2D,...)
686  * \param x_min The starting "x" coordinate to extract (default=0=the
687  * first column)
688  * \param y_min The starting "y" coordinate to extract (default=0=the
689  * first row)
690  * \param x_max The final "x" coordinate (inclusive) to extract
691  * (default=-1=the last column)
692  * \param y_max The final "y" coordinate (inclusive) to extract
693  * (default=-1=the last row)
694  * \param normalize_01 Normalize the image values such that they fall in the
695  * range [0,1] (default: true). If set to false, the matrix will hold
696  * numbers in the range [0,255]. \sa setFromMatrix
697  */
698  void getAsMatrix(
699  mrpt::math::CMatrixFloat& outMatrix, bool doResize = true,
700  int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1,
701  bool normalize_01 = true) const;
702 
703  /** Returns the image as RGB matrices with pixel values in the range [0,1].
704  * Matrix indexes in this order: M(row,column)
705  * \param doResize If set to true (default), the output matrix will be
706  * always the size of the image at output. If set to false, the matrix will
707  * be enlarged to the size of the image, but it will not be cropped if it
708  * has room enough (useful for FFT2D,...)
709  * \param x_min The starting "x" coordinate to extract (default=0=the
710  * first column)
711  * \param y_min The starting "y" coordinate to extract (default=0=the
712  * first row)
713  * \param x_max The final "x" coordinate (inclusive) to extract
714  * (default=-1=the last column)
715  * \param y_max The final "y" coordinate (inclusive) to extract
716  * (default=-1=the last row)
717  * \sa setFromRGBMatrices
718  */
719  void getAsRGBMatrices(
720  mrpt::math::CMatrixFloat& outMatrixR,
721  mrpt::math::CMatrixFloat& outMatrixG,
722  mrpt::math::CMatrixFloat& outMatrixB, bool doResize = true,
723  int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1) const;
724 
725  /** Returns the image as a matrix, where the image is "tiled" (repeated)
726  * the required number of times to fill the entire size of the matrix on
727  * input.
728  */
729  void getAsMatrixTiled(mrpt::math::CMatrixFloat& outMatrix) const;
730 
731  /** @} */
732 
733  /** @name External storage-mode methods
734  @{ */
735 
736  /** By using this method the image is marked as referenced to an external
737  * file, which will be loaded only under demand.
738  * A CImage with external storage does not consume memory until some
739  * method trying to access the image is invoked (e.g. getWidth(),
740  * isColor(),...)
741  * At any moment, the image can be unloaded from memory again by invoking
742  * unload.
743  * An image becomes of type "external storage" only through calling
744  * setExternalStorage. This property remains after serializing the object.
745  * File names can be absolute, or relative to the
746  * CImage::getImagesPathBase() directory. Filenames staring with "X:\" or
747  * "/"
748  * are considered absolute paths.
749  * By calling this method the current contents of the image are NOT saved
750  * to that file, because this method can be also called
751  * to let the object know where to load the image in case its contents
752  * are required. Thus, for saving images in this format (not when loading)
753  * the proper order of commands should be:
754  * \code
755  * img.saveToFile( fileName );
756  * img.setExternalStorage( fileName );
757  * \endcode
758  *
759  * \note Modifications to the memory copy of the image are not
760  * automatically saved to disk.
761  * \sa unload, isExternallyStored
762  */
763  void setExternalStorage(const std::string& fileName) noexcept;
764 
765  /** By default, "." \sa setExternalStorage */
766  static const std::string& getImagesPathBase();
767  static void setImagesPathBase(const std::string& path);
768 
769  /** See setExternalStorage(). */
770  bool isExternallyStored() const noexcept { return m_imgIsExternalStorage; }
771  /** Only if isExternallyStored() returns true. \sa
772  * getExternalStorageFileAbsolutePath */
773  inline std::string getExternalStorageFile() const noexcept
774  {
775  return m_externalFile;
776  }
777 
778  /** Only if isExternallyStored() returns true. \sa getExternalStorageFile */
779  void getExternalStorageFileAbsolutePath(std::string& out_path) const;
780 
781  /** Only if isExternallyStored() returns true. \sa getExternalStorageFile */
783  {
784  std::string tmp;
786  return tmp;
787  }
788 
789  /** For external storage image objects only, this method makes sure the
790  * image is loaded in memory. Note that usually images are loaded on-the-fly
791  * on first access and there's no need to call this.
792  * \unload
793  */
794  inline void forceLoad() const { makeSureImageIsLoaded(); }
795  /** For external storage image objects only, this method unloads the image
796  * from memory (or does nothing if already unloaded).
797  * It does not need to be called explicitly, unless the user wants to save
798  * memory for images that will not be used often.
799  * If called for an image without the flag "external storage", it is
800  * simply ignored.
801  * \sa setExternalStorage, forceLoad
802  */
803  void unload() const noexcept;
804 
805  /** @} */
806  // ================================================================
807 
808  // ================================================================
809  /** @name Set, load & save methods
810  @{ */
811 
812  /** Reads the image from raw pixels buffer in memory.
813  */
815  unsigned int width, unsigned int height, bool color,
816  unsigned char* rawpixels, bool swapRedBlue = false);
817 
818  /** Reads a color image from three raw pixels buffers in memory.
819  * bytesPerRow is the number of bytes per row per channel, i.e. the row
820  * increment.
821  */
823  unsigned int width, unsigned int height, unsigned int bytesPerRow,
824  unsigned char* red, unsigned char* green, unsigned char* blue);
825 
826  /** Set the image from a matrix, interpreted as grayscale intensity values,
827  *in the range [0,1] (normalized=true) or [0,255] (normalized=false)
828  * Matrix indexes are assumed to be in this order: M(row,column)
829  * \sa getAsMatrix
830  */
831  template <typename MAT>
832  void setFromMatrix(const MAT& m, bool matrix_is_normalized = true)
833  {
834  MRPT_START
835  const unsigned int lx = m.cols();
836  const unsigned int ly = m.rows();
837  this->resize(lx, ly, CH_GRAY);
838  if (matrix_is_normalized)
839  { // Matrix: [0,1]
840  for (unsigned int y = 0; y < ly; y++)
841  {
842  auto* pixels = ptrLine<uint8_t>(y);
843  for (unsigned int x = 0; x < lx; x++)
844  (*pixels++) = static_cast<uint8_t>(m.coeff(y, x) * 255);
845  }
846  }
847  else
848  { // Matrix: [0,255]
849  for (unsigned int y = 0; y < ly; y++)
850  {
851  auto* pixels = ptrLine<uint8_t>(y);
852  for (unsigned int x = 0; x < lx; x++)
853  (*pixels++) = static_cast<uint8_t>(m.coeff(y, x));
854  }
855  }
856  MRPT_END
857  }
858 
859  /** Set the image from RGB matrices, given the pixels in the range [0,1]
860  * (normalized=true) or [0,255] (normalized=false)
861  * Matrix indexes are assumed to be in this order: M(row,column)
862  * \sa getAsRGBMatrices
863  */
864  template <typename MAT>
866  const MAT& r, const MAT& g, const MAT& b,
867  bool matrix_is_normalized = true)
868  {
869  MRPT_START
870  makeSureImageIsLoaded(); // For delayed loaded images stored externally
871  ASSERT_((r.size() == g.size()) && (r.size() == b.size()));
872  const unsigned int lx = r.cols(), ly = r.rows();
873  this->resize(lx, ly, CH_RGB);
874 
875  if (matrix_is_normalized)
876  { // Matrix: [0,1]
877  for (unsigned int y = 0; y < ly; y++)
878  {
879  auto* pixels = ptrLine<uint8_t>(y);
880  for (unsigned int x = 0; x < lx; x++)
881  {
882  (*pixels++) = static_cast<uint8_t>(r.coeff(y, x) * 255);
883  (*pixels++) = static_cast<uint8_t>(g.coeff(y, x) * 255);
884  (*pixels++) = static_cast<uint8_t>(b.coeff(y, x) * 255);
885  }
886  }
887  }
888  else
889  { // Matrix: [0,255]
890  for (unsigned int y = 0; y < ly; y++)
891  {
892  auto* pixels = ptrLine<uint8_t>(y);
893  for (unsigned int x = 0; x < lx; x++)
894  {
895  (*pixels++) = static_cast<uint8_t>(r.coeff(y, x));
896  (*pixels++) = static_cast<uint8_t>(g.coeff(y, x));
897  (*pixels++) = static_cast<uint8_t>(b.coeff(y, x));
898  }
899  }
900  }
901  MRPT_END
902  }
903 
904  /** Reads the image from a binary stream containing a binary jpeg file.
905  * \exception std::exception On pixel coordinates out of bounds
906  */
908 
909  /** Load image from a file, whose format is determined from the extension
910  * (internally uses OpenCV).
911  * \param fileName The file to read from.
912  * \param isColor Specifies colorness of the loaded image:
913  * - if >0, the loaded image is forced to be color 3-channel image;
914  * - if 0, the loaded image is forced to be grayscale;
915  * - if <0, the loaded image will be loaded as is (with number of channels
916  * depends on the file).
917  * The supported formats are:
918  *
919  * - Windows bitmaps - BMP, DIB;
920  * - JPEG files - JPEG, JPG, JPE;
921  * - Portable Network Graphics - PNG;
922  * - Portable image format - PBM, PGM, PPM;
923  * - Sun rasters - SR, RAS;
924  * - TIFF files - TIFF, TIF.
925  *
926  * \return False on any error
927  * \sa saveToFile, setExternalStorage,loadFromXPM, loadTGA
928  */
929  bool loadFromFile(const std::string& fileName, int isColor = -1);
930 
931  /** Loads a TGA true-color RGBA image as two CImage objects, one for the RGB
932  * channels plus a separate gray-level image with A channel.
933  * \return true on success
934  */
935  static bool loadTGA(
936  const std::string& fileName, mrpt::img::CImage& out_RGB,
937  mrpt::img::CImage& out_alpha);
938 
939  /** Loads the image from an XPM array, as #include'd from a ".xpm" file.
940  * \param[in] swap_rb Swaps red/blue channels from loaded image. *Seems* to
941  * be always needed, so it's enabled by default.
942  * \sa loadFromFile
943  * \return false on any error */
944  bool loadFromXPM(const char* const* xpm_array, bool swap_rb = true);
945 
946  /** Save the image to a file, whose format is determined from the extension
947  * (internally uses OpenCV).
948  * \param fileName The file to write to.
949  *
950  * The supported formats are:
951  *
952  * - Windows bitmaps - BMP, DIB;
953  * - JPEG files - JPEG, JPG, JPE;
954  * - Portable Network Graphics - PNG;
955  * - Portable image format - PBM, PGM, PPM;
956  * - Sun rasters - SR, RAS;
957  * - TIFF files - TIFF, TIF.
958  *
959  * \param jpeg_quality Only for JPEG files, the quality of the compression
960  * in the range [0-100]. Larger is better quality but slower.
961  * \note jpeg_quality is only effective if MRPT is compiled against OpenCV
962  * 1.1.0 or newer.
963  * \return False on any error
964  * \sa loadFromFile
965  */
966  bool saveToFile(const std::string& fileName, int jpeg_quality = 95) const;
967 
968  /** Save image to binary stream as a JPEG (.jpg) compressed format.
969  * \exception std::exception On number of rows or cols equal to zero or
970  * other errors.
971  * \sa saveToJPEG
972  */
973  void saveToStreamAsJPEG(
974  mrpt::io::CStream& out, const int jpeg_quality = 95) const;
975 
976  /** @} */
977  // ================================================================
978 
979  // ================================================================
980  /** @name Color/Grayscale conversion
981  @{ */
982 
983  /** Returns a grayscale version of the image, or a shallow copy of itself if
984  * it is already a grayscale image.
985  */
986  CImage grayscale() const;
987 
988  /** \overload.
989  * In-place is supported by setting `ret=*this`.
990  * \return true if SSE2 version has been run (or if the image was already
991  * grayscale)
992  */
993  bool grayscale(CImage& ret) const;
994 
995  /** Returns a color (RGB) version of the grayscale image, or a shallow copy
996  * of itself if it is already a color image.
997  * \sa grayscale
998  */
999  CImage colorImage() const;
1000 
1001  /** \overload.
1002  * In-place is supported by setting `ret=*this`. */
1003  void colorImage(CImage& ret) const;
1004 
1005  /** @} */
1006 
1007  /** (DEPRECATED, DO NOT USE - Kept here only to interface opencv 2.4) */
1008  void getAsIplImage(IplImage* dest) const;
1009 
1010  protected:
1011  /** @name Data members
1012  @{ */
1013 
1014  /** PIMPL to cv::Mat object actually holding the image */
1015  struct Impl;
1017 
1018  /** Set to true only when using setExternalStorage.
1019  * \sa setExternalStorage
1020  */
1021  mutable bool m_imgIsExternalStorage{false};
1022 
1023  /** The file name of a external storage image. */
1025 
1026  /** @} */
1027 
1028  /** Checks if the image is of type "external storage", and if so and not
1029  * loaded yet, load it.
1030  * \exception CExceptionExternalImageNotFound */
1031  void makeSureImageIsLoaded() const;
1032  uint8_t* internal_get(int col, int row, uint8_t channel = 0) const;
1033  void internal_fromIPL(const IplImage* iplImage, copy_type_t c);
1034 }; // End of class
1035 } // namespace mrpt::img
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.
Definition: CImage.cpp:1183
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.
Definition: CImage.cpp:1159
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.
Definition: CImage.cpp:1146
CImage makeShallowCopy() const
Returns a shallow copy of the original image.
Definition: img/CImage.h:483
Shallow copy: the copied object is a reference to the original one.
Definition: img/CImage.h:74
bool loadFromXPM(const char *const *xpm_array, bool swap_rb=true)
Loads the image from an XPM array, as #include&#39;d from a ".xpm" file.
Used in mrpt::img::CImage.
Definition: img/CImage.h:81
ctor_CImage_ref_or_gray
For usage in one of the CImage constructors.
Definition: img/CImage.h:65
bool isEmpty() const
Returns true if the object is in the state after default constructor.
Definition: CImage.cpp:898
#define MRPT_START
Definition: exceptions.h:241
This virtual class defines the interface of any object accepting drawing primitives on it...
Definition: CCanvas.h:41
TPenStyle
Definition of pen styles.
Definition: CCanvas.h:55
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.
Definition: CImage.cpp:1749
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 ...
Definition: CImage.cpp:1465
static bool DISABLE_ZIP_COMPRESSION()
Definition: CImage.cpp:59
CImage scaleHalf(TInterpolationMethod interp) const
Returns a new image scaled down to half its original size.
Definition: img/CImage.h:313
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].
Definition: CImage.cpp:1269
const T * ptrLine(unsigned int row) const
Returns a pointer to the first pixel of the given line.
Definition: img/CImage.h:596
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:6604
void copyFromForceLoad(const CImage &o)
Copies from another image (shallow copy), and, if it is externally stored, the image file will be act...
Definition: CImage.cpp:185
spimpl::impl_ptr< T > pimpl
Definition: pimpl.h:15
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].
Definition: CImage.cpp:1326
static bool DISABLE_JPEG_COMPRESSION()
Definition: CImage.cpp:64
#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
Definition: glext.h:3727
copy_type_t
Define kind of copies.
Definition: img/CImage.h:71
CExceptionExternalImageNotFound(const std::string &s)
Definition: CImage.cpp:77
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1]. ...
Definition: CImage.cpp:950
void drawImage(int x, int y, const mrpt::img::CImage &img) override
Draws an image as a bitmap at a given position.
Definition: CImage.cpp:1171
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition: CImage.cpp:234
void flipHorizontal()
Flips the image horizontally.
Definition: CImage.cpp:1601
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
Definition: CImage.cpp:907
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:878
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 ...
Definition: CImage.cpp:1691
std::string getChannelsOrder() const
As of mrpt 2.0.0, this returns either "GRAY" or "BGR".
Definition: CImage.cpp:857
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...
Definition: CImage.cpp:1521
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:3606
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...
Definition: CImage.cpp:1208
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it...
Definition: CImage.cpp:1535
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...
Definition: CImage.cpp:1677
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
Definition: CImage.cpp:1840
bool isExternallyStored() const noexcept
See setExternalStorage().
Definition: img/CImage.h:770
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...
Definition: img/CImage.h:566
GLdouble s
Definition: glext.h:3682
Definition: img/CImage.h:22
void unload() const noexcept
For external storage image objects only, this method unloads the image from memory (or does nothing i...
Definition: CImage.cpp:1528
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.
Definition: CImage.cpp:922
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: io/CStream.h:28
GLenum GLsizei width
Definition: glext.h:3535
mrpt::pimpl< Impl > m_impl
Definition: img/CImage.h:1015
void swap(CImage &o)
Efficiently swap of two images.
Definition: CImage.cpp:178
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.
Definition: CImage.cpp:224
T & at(unsigned int col, unsigned int row, unsigned int channel=0)
Definition: img/CImage.h:573
void swapRB()
Swaps red and blue channels.
Definition: CImage.cpp:1609
CImage colorImage() const
Returns a color (RGB) version of the grayscale image, or a shallow copy of itself if it is already a ...
Definition: CImage.cpp:1814
GLuint color
Definition: glext.h:8459
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV)...
Definition: CImage.cpp:312
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:847
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...
Definition: CImage.cpp:1914
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...
Definition: CImage.cpp:254
unsigned char * operator()(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel information.
Definition: CImage.cpp:433
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process.
Definition: img/CImage.h:505
const GLubyte * c
Definition: glext.h:6406
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class...
GLint GLvoid * img
Definition: glext.h:3769
void internal_fromIPL(const IplImage *iplImage, copy_type_t c)
Definition: CImage.cpp:358
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.
Definition: img/CImage.h:512
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images...
Definition: CImage.cpp:1261
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:39
void flipVertical()
Flips the image vertically.
Definition: CImage.cpp:1593
GLubyte g
Definition: glext.h:6372
int val
Definition: mrpt_jpeglib.h:957
GLubyte GLubyte b
Definition: glext.h:6372
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...
Definition: img/CImage.h:832
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.
Definition: CImage.cpp:483
Parameters for the Brown-Conrady camera lens distortion model.
Definition: TCamera.h:25
void getAsIplImage(IplImage *dest) const
(DEPRECATED, DO NOT USE - Kept here only to interface opencv 2.4)
Definition: CImage.cpp:2133
std::string getExternalStorageFile() const noexcept
Only if isExternallyStored() returns true.
Definition: img/CImage.h:773
void loadFromStreamAsJPEG(mrpt::io::CStream &in)
Reads the image from a binary stream containing a binary jpeg file.
__int32 int32_t
Definition: glext.h:3455
void rectifyImageInPlace(void *mapX, void *mapY)
Rectify an image (undistorts and rectification) from a stereo pair according to a pair of precomputed...
Definition: CImage.cpp:1617
TImageSize getSize() const
Return the size of the image.
Definition: img/CImage.h:645
GLsizei const GLchar ** string
Definition: glext.h:4116
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:3606
void clear()
Resets the image to the state after a default ctor.
Definition: CImage.cpp:1515
uint8_t * internal_get(int col, int row, uint8_t channel=0) const
Definition: CImage.cpp:471
CImage grayscale() const
Returns a grayscale version of the image, or a shallow copy of itself if it is already a grayscale im...
Definition: CImage.cpp:962
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.
Definition: CImage.cpp:1385
CV_MAT asCvMat(copy_type_t copy_type) const
Definition: img/CImage.h:539
void setFromIplImageReadOnly(IplImage *iplImage)
Definition: img/CImage.h:521
void setPixel(int x, int y, size_t color) override
Changes the value of the pixel (x,y).
Definition: CImage.cpp:1105
T * ptr(unsigned int col, unsigned int row, unsigned int channel=0)
Definition: img/CImage.h:589
PixelDepth getPixelDepth() const
Definition: CImage.cpp:301
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...
Definition: CImage.cpp:1662
CImage()
Default constructor: initialize to empty image.
Definition: CImage.cpp:166
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...
Definition: img/CImage.h:189
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
CImage makeDeepCopy() const
Returns a deep copy of this image.
Definition: CImage.cpp:213
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
Definition: CImage.cpp:888
TInterpolationMethod
Interpolation methods for images.
Definition: img/CImage.h:49
bool isOriginTopLeft() const
Returns true (as of MRPT v2.0.0, it&#39;s fixed)
Definition: CImage.cpp:917
GLclampf green
Definition: glext.h:3529
mrpt::vision::TStereoCalibResults out
struct _IplImage IplImage
Definition: img/CImage.h:21
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
Definition: img/CImage.h:1021
Deep copy: the copied object has a duplicate of all data, becoming independent.
Definition: img/CImage.h:77
GLenum GLenum GLvoid * row
Definition: glext.h:3580
#define MRPT_END
Definition: exceptions.h:245
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.
Definition: img/CImage.h:582
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows...
Definition: CImage.cpp:868
GLuint in
Definition: glext.h:7391
CImage scaleDouble(TInterpolationMethod interp) const
Returns a new image scaled up to double its original size.
Definition: img/CImage.h:328
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...
Definition: CImage.cpp:1717
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
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)...
Definition: CImage.cpp:1195
GLenum GLint GLint y
Definition: glext.h:3542
#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)
Definition: img/CImage.h:602
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)...
Definition: CImage.cpp:337
TImageChannels
For use in mrpt::img::CImage.
Definition: img/CImage.h:58
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...
Definition: img/CImage.h:865
static int SERIALIZATION_JPEG_QUALITY()
Definition: CImage.cpp:72
GLuint interp
Definition: glext.h:7247
A RGB color - 8bit.
Definition: TColor.h:20
GLclampf GLclampf blue
Definition: glext.h:3529
GLenum GLint x
Definition: glext.h:3542
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...
Definition: CImage.cpp:1635
GLenum GLsizei GLsizei height
Definition: glext.h:3558
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
Definition: img/CImage.h:782
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.
Definition: img/CImage.h:1024
static void setImagesPathBase(const std::string &path)
Definition: CImage.cpp:84
void equalizeHist(CImage &out_img) const
Equalize the image histogram, saving the new image in the given output object.
Definition: CImage.cpp:1855
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory...
Definition: img/CImage.h:794
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...
Definition: CImage.cpp:2050
void setFromImageReadOnly(const CImage &o)
Definition: img/CImage.h:477
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147
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.
Definition: CImage.cpp:372
static const std::string & getImagesPathBase()
By default, ".".
Definition: CImage.cpp:83



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 4363012a5 Tue Nov 19 10:55:26 2019 +0100 at mar nov 19 11:00:13 CET 2019