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 */
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  * \sa mrpt::vision::CUndistortMap
411  */
412  void undistort(
413  CImage& out_img, const mrpt::img::TCamera& cameraParams) const;
414 
415  /** Rectify an image (undistorts and rectification) from a stereo pair
416  * according to a pair of precomputed rectification maps
417  * \param mapX, mapY [IN] The pre-computed maps of the rectification
418  * (should be computed beforehand)
419  * \sa mrpt::vision::CStereoRectifyMap,
420  * mrpt::vision::computeStereoRectificationMaps
421  */
422  void rectifyImageInPlace(void* mapX, void* mapY);
423 
424  /** Filter the image with a Median filter with a window size WxW, returning
425  * the filtered image in out_img. For inplace operation, set out_img to
426  * this. */
427  void filterMedian(CImage& out_img, int W = 3) const;
428 
429  /** Filter the image with a Gaussian filter with a window size WxH,
430  * replacing "this" image by the filtered one. For inplace operation, set
431  * out_img to this. */
432  void filterGaussian(
433  CImage& out_img, int W = 3, int H = 3, double sigma = 1.0) const;
434 
435  /** Draw onto this image the detected corners of a chessboard. The length of
436  * cornerCoords must be the product of the two check_sizes.
437  *
438  * \param cornerCoords [IN] The pixel coordinates of all the corners.
439  * \param check_size_x [IN] The number of squares, in the X direction
440  * \param check_size_y [IN] The number of squares, in the Y direction
441  *
442  * \return false if the length of cornerCoords is inconsistent (nothing is
443  * drawn then).
444  *
445  * \sa mrpt::vision::findChessboardCorners
446  */
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);
451 
452  /** Joins two images side-by-side horizontally. Both images must have the
453  * same number of rows and be of the same type (i.e. depth and color mode)
454  *
455  * \param im1 [IN] The first image.
456  * \param im2 [IN] The other image.
457  */
458  void joinImagesHorz(const CImage& im1, const CImage& im2);
459 
460  /** Compute the KLT response at a given pixel (x,y) - Only for grayscale
461  * images (for efficiency it avoids converting to grayscale internally).
462  * See KLT_response() for more details on the internal
463  * optimizations of this method, but this graph shows a general view:
464  * <img src="KLT_response_performance_SSE2.png" >
465  */
466  float KLT_response(
467  const unsigned int x, const unsigned int y,
468  const unsigned int half_window_size) const;
469 
470  /** @} */
471 
472  /** @name Copy, move & swap operations
473  @{ */
474  [[deprecated("Use makeShallowCopy() instead")]] inline void
476  {
477  *this = o.makeShallowCopy();
478  }
479 
480  /** Returns a shallow copy of the original image */
481  inline CImage makeShallowCopy() const
482  {
483  CImage r = *this;
484  return r;
485  }
486 
487  /** Returns a deep copy of this image.
488  * If the image is externally-stored, there is no difference with a shallow
489  * copy. \sa makeShallowCopy() */
490  CImage makeDeepCopy() const;
491 
492  /** Copies from another image (shallow copy), and, if it is externally
493  * stored, the image file will be actually loaded into memory in "this"
494  * object. \sa operator = \exception CExceptionExternalImageNotFound If the
495  * external image couldn't be loaded.
496  */
497  void copyFromForceLoad(const CImage& o);
498 
499  /** Moves an image from another object, erasing the origin image in the
500  * process.
501  * \sa operator =
502  */
503  [[deprecated("Use a=std::move(b); instead ")]] inline void copyFastFrom(
504  CImage& o)
505  {
506  *this = std::move(o);
507  }
508 
509  /** Assigns from an image in IplImage format */
510  inline void loadFromIplImage(
511  const IplImage* iplImage, copy_type_t c = DEEP_COPY)
512  {
513  internal_fromIPL(iplImage, c);
514  }
515 
516  [[deprecated(
517  "Prefer a ctor from a cv::Mat instead or use loadFromIplImage() "
518  "explicitly specifying the kind of copy to be done")]] inline void
520  {
521  internal_fromIPL(iplImage, SHALLOW_COPY);
522  }
523 
524  /** Efficiently swap of two images */
525  void swap(CImage& o);
526 
527  /** @} */
528 
529  /** @name Access to image contents (OpenCV data structure, and raw pixels)
530  @{ */
531 
532  /** Makes a shallow or deep copy of this image into the provided cv::Mat.
533  * \sa asCvMatRef */
534  void asCvMat(cv::Mat& out_img, copy_type_t copy_type) const;
535 
536  template <typename CV_MAT>
537  CV_MAT asCvMat(copy_type_t copy_type) const
538  {
539  CV_MAT ret;
540  asCvMat(ret, copy_type);
541  return ret;
542  }
543 
544  /** Get a reference to the internal cv::Mat, which can be resized, etc. and
545  * changes will be reflected in this CImage object. */
546  cv::Mat& asCvMatRef();
547 
548  /** \overload */
549  const cv::Mat& asCvMatRef() const;
550 
551  /** Access to pixels without checking boundaries - Use normally the ()
552  operator better, which checks the coordinates.
553  \sa CImage::operator()
554  */
555  [[deprecated("Use at<>(), ptr<>() or ptrLine() instead ")]] uint8_t*
556  get_unsafe(
557  unsigned int col, unsigned int row, uint8_t channel = 0) const;
558 
559  /** Access to pixels without checking boundaries, and doing a
560  * reinterpret_cast<> of the data as the given type.
561  *\sa The CImage::operator() which does check for coordinate limits.
562  */
563  template <typename T>
564  const T& at(
565  unsigned int col, unsigned int row, unsigned int channel = 0) const
566  {
567  return *reinterpret_cast<const T*>(internal_get(col, row, channel));
568  }
569  /** \overload Non-const case */
570  template <typename T>
571  T& at(unsigned int col, unsigned int row, unsigned int channel = 0)
572  {
573  return *reinterpret_cast<T*>(internal_get(col, row, channel));
574  }
575 
576  /** Returns a pointer to a given pixel, without checking for boundaries.
577  *\sa The CImage::operator() which does check for coordinate limits.
578  */
579  template <typename T>
580  const T* ptr(
581  unsigned int col, unsigned int row, unsigned int channel = 0) const
582  {
583  return reinterpret_cast<const T*>(internal_get(col, row, channel));
584  }
585  /** \overload Non-const case */
586  template <typename T>
587  T* ptr(unsigned int col, unsigned int row, unsigned int channel = 0)
588  {
589  return reinterpret_cast<T*>(internal_get(col, row, channel));
590  }
591 
592  /** Returns a pointer to the first pixel of the given line.\sa ptr, at */
593  template <typename T>
594  const T* ptrLine(unsigned int row) const
595  {
596  return reinterpret_cast<const T*>(internal_get(0, row, 0));
597  }
598  /** \overload Non-const case */
599  template <typename T>
600  T* ptrLine(unsigned int row)
601  {
602  return reinterpret_cast<T*>(internal_get(0, row, 0));
603  }
604 
605  /** Returns the contents of a given pixel at the desired channel, in float
606  * format: [0,255]->[0,1]
607  * The coordinate origin is pixel(0,0)=top-left corner of the image.
608  * \exception std::exception On pixel coordinates out of bounds
609  * \sa operator()
610  */
611  float getAsFloat(
612  unsigned int col, unsigned int row, unsigned int channel) const;
613 
614  /** Returns the contents of a given pixel (for gray-scale images, in color
615  * images the gray scale equivalent is computed for the pixel), in float
616  * format: [0,255]->[0,1]
617  * The coordinate origin is pixel(0,0)=top-left corner of the image.
618  * \exception std::exception On pixel coordinates out of bounds
619  * \sa operator()
620  */
621  float getAsFloat(unsigned int col, unsigned int row) const;
622 
623  /** Returns a pointer to a given pixel information.
624  * The coordinate origin is pixel(0,0)=top-left corner of the image.
625  * \exception std::exception On pixel coordinates out of bounds
626  */
627  unsigned char* operator()(
628  unsigned int col, unsigned int row, unsigned int channel = 0) const;
629 
630  /** @} */
631 
632  /** @name Query image properties
633  @{ */
634 
635  /** Returns the width of the image in pixels \sa getSize */
636  size_t getWidth() const override;
637  /** Returns the height of the image in pixels \sa getSize */
638  size_t getHeight() const override;
639 
640  /** Return the size of the image \sa getWidth, getHeight */
641  void getSize(TImageSize& s) const;
642  /** Return the size of the image \sa getWidth, getHeight */
643  inline TImageSize getSize() const
644  {
645  TImageSize ret;
646  getSize(ret);
647  return ret;
648  }
649 
650  /** Returns the row stride of the image: this is the number of *bytes*
651  * between two consecutive rows. You can access the pointer to the first row
652  * with ptrLine(0)
653  * \sa getSize, as, ptr, ptrLine */
654  size_t getRowStride() const;
655 
656  /** As of mrpt 2.0.0, this returns either "GRAY" or "BGR". */
658 
659  /** Return the maximum pixel value of the image, as a float value in the
660  * range [0,1]
661  * \sa getAsFloat */
662  float getMaxAsFloat() const;
663 
664  /** Returns true if the image is RGB, false if it is grayscale */
665  bool isColor() const;
666 
667  /** Returns true if the object is in the state after default constructor */
668  bool isEmpty() const;
669 
670  /** Returns true (as of MRPT v2.0.0, it's fixed) */
671  bool isOriginTopLeft() const;
672 
673  /** Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
674  * \sa isColor
675  */
677 
678  /** Returns the image as a matrix with pixel grayscale values in the range
679  * [0,1]. Matrix indexes in this order: M(row,column)
680  * \param doResize If set to true (default), the output matrix will be
681  * always the size of the image at output. If set to false, the matrix will
682  * be enlarged to the size of the image, but it will not be cropped if it
683  * has room enough (useful for FFT2D,...)
684  * \param x_min The starting "x" coordinate to extract (default=0=the
685  * first column)
686  * \param y_min The starting "y" coordinate to extract (default=0=the
687  * first row)
688  * \param x_max The final "x" coordinate (inclusive) to extract
689  * (default=-1=the last column)
690  * \param y_max The final "y" coordinate (inclusive) to extract
691  * (default=-1=the last row)
692  * \param normalize_01 Normalize the image values such that they fall in the
693  * range [0,1] (default: true). If set to false, the matrix will hold
694  * numbers in the range [0,255]. \sa setFromMatrix
695  */
696  void getAsMatrix(
697  mrpt::math::CMatrixFloat& outMatrix, bool doResize = true,
698  int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1,
699  bool normalize_01 = true) const;
700 
701  /** Returns the image as RGB matrices with pixel values in the range [0,1].
702  * Matrix indexes in this order: M(row,column)
703  * \param doResize If set to true (default), the output matrix will be
704  * always the size of the image at output. If set to false, the matrix will
705  * be enlarged to the size of the image, but it will not be cropped if it
706  * has room enough (useful for FFT2D,...)
707  * \param x_min The starting "x" coordinate to extract (default=0=the
708  * first column)
709  * \param y_min The starting "y" coordinate to extract (default=0=the
710  * first row)
711  * \param x_max The final "x" coordinate (inclusive) to extract
712  * (default=-1=the last column)
713  * \param y_max The final "y" coordinate (inclusive) to extract
714  * (default=-1=the last row)
715  * \sa setFromRGBMatrices
716  */
717  void getAsRGBMatrices(
718  mrpt::math::CMatrixFloat& outMatrixR,
719  mrpt::math::CMatrixFloat& outMatrixG,
720  mrpt::math::CMatrixFloat& outMatrixB, bool doResize = true,
721  int x_min = 0, int y_min = 0, int x_max = -1, int y_max = -1) const;
722 
723  /** Returns the image as a matrix, where the image is "tiled" (repeated)
724  * the required number of times to fill the entire size of the matrix on
725  * input.
726  */
727  void getAsMatrixTiled(mrpt::math::CMatrixFloat& outMatrix) const;
728 
729  /** @} */
730 
731  /** @name External storage-mode methods
732  @{ */
733 
734  /** By using this method the image is marked as referenced to an external
735  * file, which will be loaded only under demand.
736  * A CImage with external storage does not consume memory until some
737  * method trying to access the image is invoked (e.g. getWidth(),
738  * isColor(),...)
739  * At any moment, the image can be unloaded from memory again by invoking
740  * unload.
741  * An image becomes of type "external storage" only through calling
742  * setExternalStorage. This property remains after serializing the object.
743  * File names can be absolute, or relative to the
744  * CImage::getImagesPathBase() directory. Filenames staring with "X:\" or
745  * "/"
746  * are considered absolute paths.
747  * By calling this method the current contents of the image are NOT saved
748  * to that file, because this method can be also called
749  * to let the object know where to load the image in case its contents
750  * are required. Thus, for saving images in this format (not when loading)
751  * the proper order of commands should be:
752  * \code
753  * img.saveToFile( fileName );
754  * img.setExternalStorage( fileName );
755  * \endcode
756  *
757  * \note Modifications to the memory copy of the image are not
758  * automatically saved to disk.
759  * \sa unload, isExternallyStored
760  */
761  void setExternalStorage(const std::string& fileName) noexcept;
762 
763  /** By default, "." \sa setExternalStorage */
764  static const std::string& getImagesPathBase();
765  static void setImagesPathBase(const std::string& path);
766 
767  /** See setExternalStorage(). */
768  bool isExternallyStored() const noexcept { return m_imgIsExternalStorage; }
769  /** Only if isExternallyStored() returns true. \sa
770  * getExternalStorageFileAbsolutePath */
771  inline std::string getExternalStorageFile() const noexcept
772  {
773  return m_externalFile;
774  }
775 
776  /** Only if isExternallyStored() returns true. \sa getExternalStorageFile */
777  void getExternalStorageFileAbsolutePath(std::string& out_path) const;
778 
779  /** Only if isExternallyStored() returns true. \sa getExternalStorageFile */
781  {
782  std::string tmp;
784  return tmp;
785  }
786 
787  /** For external storage image objects only, this method makes sure the
788  * image is loaded in memory. Note that usually images are loaded on-the-fly
789  * on first access and there's no need to call this.
790  * \unload
791  */
792  inline void forceLoad() const { makeSureImageIsLoaded(); }
793  /** For external storage image objects only, this method unloads the image
794  * from memory (or does nothing if already unloaded).
795  * It does not need to be called explicitly, unless the user wants to save
796  * memory for images that will not be used often.
797  * If called for an image without the flag "external storage", it is
798  * simply ignored.
799  * \sa setExternalStorage, forceLoad
800  */
801  void unload() const noexcept;
802 
803  /** @} */
804  // ================================================================
805 
806  // ================================================================
807  /** @name Set, load & save methods
808  @{ */
809 
810  /** Reads the image from raw pixels buffer in memory.
811  */
813  unsigned int width, unsigned int height, bool color,
814  unsigned char* rawpixels, bool swapRedBlue = false);
815 
816  /** Reads a color image from three raw pixels buffers in memory.
817  * bytesPerRow is the number of bytes per row per channel, i.e. the row
818  * increment.
819  */
821  unsigned int width, unsigned int height, unsigned int bytesPerRow,
822  unsigned char* red, unsigned char* green, unsigned char* blue);
823 
824  /** Set the image from a matrix, interpreted as grayscale intensity values,
825  *in the range [0,1] (normalized=true) or [0,255] (normalized=false)
826  * Matrix indexes are assumed to be in this order: M(row,column)
827  * \sa getAsMatrix
828  */
829  template <typename MAT>
830  void setFromMatrix(const MAT& m, bool matrix_is_normalized = true)
831  {
832  MRPT_START
833  const unsigned int lx = m.cols();
834  const unsigned int ly = m.rows();
835  this->resize(lx, ly, CH_GRAY);
836  if (matrix_is_normalized)
837  { // Matrix: [0,1]
838  for (unsigned int y = 0; y < ly; y++)
839  {
840  auto* pixels = ptrLine<uint8_t>(y);
841  for (unsigned int x = 0; x < lx; x++)
842  (*pixels++) = static_cast<uint8_t>(m.coeff(y, x) * 255);
843  }
844  }
845  else
846  { // Matrix: [0,255]
847  for (unsigned int y = 0; y < ly; y++)
848  {
849  auto* pixels = ptrLine<uint8_t>(y);
850  for (unsigned int x = 0; x < lx; x++)
851  (*pixels++) = static_cast<uint8_t>(m.coeff(y, x));
852  }
853  }
854  MRPT_END
855  }
856 
857  /** Set the image from RGB matrices, given the pixels in the range [0,1]
858  * (normalized=true) or [0,255] (normalized=false)
859  * Matrix indexes are assumed to be in this order: M(row,column)
860  * \sa getAsRGBMatrices
861  */
862  template <typename MAT>
864  const MAT& r, const MAT& g, const MAT& b,
865  bool matrix_is_normalized = true)
866  {
867  MRPT_START
868  makeSureImageIsLoaded(); // For delayed loaded images stored externally
869  ASSERT_((r.size() == g.size()) && (r.size() == b.size()));
870  const unsigned int lx = r.cols(), ly = r.rows();
871  this->resize(lx, ly, CH_RGB);
872 
873  if (matrix_is_normalized)
874  { // Matrix: [0,1]
875  for (unsigned int y = 0; y < ly; y++)
876  {
877  auto* pixels = ptrLine<uint8_t>(y);
878  for (unsigned int x = 0; x < lx; x++)
879  {
880  (*pixels++) = static_cast<uint8_t>(r.coeff(y, x) * 255);
881  (*pixels++) = static_cast<uint8_t>(g.coeff(y, x) * 255);
882  (*pixels++) = static_cast<uint8_t>(b.coeff(y, x) * 255);
883  }
884  }
885  }
886  else
887  { // Matrix: [0,255]
888  for (unsigned int y = 0; y < ly; y++)
889  {
890  auto* pixels = ptrLine<uint8_t>(y);
891  for (unsigned int x = 0; x < lx; x++)
892  {
893  (*pixels++) = static_cast<uint8_t>(r.coeff(y, x));
894  (*pixels++) = static_cast<uint8_t>(g.coeff(y, x));
895  (*pixels++) = static_cast<uint8_t>(b.coeff(y, x));
896  }
897  }
898  }
899  MRPT_END
900  }
901 
902  /** Reads the image from a binary stream containing a binary jpeg file.
903  * \exception std::exception On pixel coordinates out of bounds
904  */
906 
907  /** Load image from a file, whose format is determined from the extension
908  * (internally uses OpenCV).
909  * \param fileName The file to read from.
910  * \param isColor Specifies colorness of the loaded image:
911  * - if >0, the loaded image is forced to be color 3-channel image;
912  * - if 0, the loaded image is forced to be grayscale;
913  * - if <0, the loaded image will be loaded as is (with number of channels
914  * depends on the file).
915  * The supported formats are:
916  *
917  * - Windows bitmaps - BMP, DIB;
918  * - JPEG files - JPEG, JPG, JPE;
919  * - Portable Network Graphics - PNG;
920  * - Portable image format - PBM, PGM, PPM;
921  * - Sun rasters - SR, RAS;
922  * - TIFF files - TIFF, TIF.
923  *
924  * \return False on any error
925  * \sa saveToFile, setExternalStorage,loadFromXPM, loadTGA
926  */
927  bool loadFromFile(const std::string& fileName, int isColor = -1);
928 
929  /** Loads a TGA true-color RGBA image as two CImage objects, one for the RGB
930  * channels plus a separate gray-level image with A channel.
931  * \return true on success
932  */
933  static bool loadTGA(
934  const std::string& fileName, mrpt::img::CImage& out_RGB,
935  mrpt::img::CImage& out_alpha);
936 
937  /** Loads the image from an XPM array, as #include'd from a ".xpm" file.
938  * \param[in] swap_rb Swaps red/blue channels from loaded image. *Seems* to
939  * be always needed, so it's enabled by default.
940  * \sa loadFromFile
941  * \return false on any error */
942  bool loadFromXPM(const char* const* xpm_array, bool swap_rb = true);
943 
944  /** Save the image to a file, whose format is determined from the extension
945  * (internally uses OpenCV).
946  * \param fileName The file to write to.
947  *
948  * The supported formats are:
949  *
950  * - Windows bitmaps - BMP, DIB;
951  * - JPEG files - JPEG, JPG, JPE;
952  * - Portable Network Graphics - PNG;
953  * - Portable image format - PBM, PGM, PPM;
954  * - Sun rasters - SR, RAS;
955  * - TIFF files - TIFF, TIF.
956  *
957  * \param jpeg_quality Only for JPEG files, the quality of the compression
958  * in the range [0-100]. Larger is better quality but slower.
959  * \note jpeg_quality is only effective if MRPT is compiled against OpenCV
960  * 1.1.0 or newer.
961  * \return False on any error
962  * \sa loadFromFile
963  */
964  bool saveToFile(const std::string& fileName, int jpeg_quality = 95) const;
965 
966  /** Save image to binary stream as a JPEG (.jpg) compressed format.
967  * \exception std::exception On number of rows or cols equal to zero or
968  * other errors.
969  * \sa saveToJPEG
970  */
971  void saveToStreamAsJPEG(
972  mrpt::io::CStream& out, const int jpeg_quality = 95) const;
973 
974  /** @} */
975  // ================================================================
976 
977  // ================================================================
978  /** @name Color/Grayscale conversion
979  @{ */
980 
981  /** Returns a grayscale version of the image, or a shallow copy of itself if
982  * it is already a grayscale image.
983  */
984  CImage grayscale() const;
985 
986  /** \overload.
987  * In-place is supported by setting `ret=*this`.
988  * \return true if SSE2 version has been run (or if the image was already
989  * grayscale)
990  */
991  bool grayscale(CImage& ret) const;
992 
993  /** Returns a color (RGB) version of the grayscale image, or a shallow copy
994  * of itself if it is already a color image.
995  * \sa grayscale
996  */
997  CImage colorImage() const;
998 
999  /** \overload.
1000  * In-place is supported by setting `ret=*this`. */
1001  void colorImage(CImage& ret) const;
1002 
1003  /** @} */
1004 
1005  protected:
1006  /** @name Data members
1007  @{ */
1008 
1009  /** PIMPL to cv::Mat object actually holding the image */
1010  struct Impl;
1012 
1013  /** Set to true only when using setExternalStorage.
1014  * \sa setExternalStorage
1015  */
1016  mutable bool m_imgIsExternalStorage{false};
1017 
1018  /** The file name of a external storage image. */
1020 
1021  /** @} */
1022 
1023  /** Checks if the image is of type "external storage", and if so and not
1024  * loaded yet, load it.
1025  * \exception CExceptionExternalImageNotFound */
1026  void makeSureImageIsLoaded() const;
1027  uint8_t* internal_get(int col, int row, uint8_t channel = 0) const;
1028  void internal_fromIPL(const IplImage* iplImage, copy_type_t c);
1029 }; // End of class
1030 } // 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:1180
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:1156
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:1143
CImage makeShallowCopy() const
Returns a shallow copy of the original image.
Definition: img/CImage.h:481
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:897
#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:1748
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:1463
static bool DISABLE_ZIP_COMPRESSION()
Definition: CImage.cpp:58
unsigned char red[10]
Definition: PbMapMaker.cpp:810
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:1267
const T * ptrLine(unsigned int row) const
Returns a pointer to the first pixel of the given line.
Definition: img/CImage.h:594
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:184
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:1324
static bool DISABLE_JPEG_COMPRESSION()
Definition: CImage.cpp:63
#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:76
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1]. ...
Definition: CImage.cpp:949
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:1168
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition: CImage.cpp:233
void flipHorizontal()
Flips the image horizontally.
Definition: CImage.cpp:1599
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
Definition: CImage.cpp:906
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:877
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:1690
std::string getChannelsOrder() const
As of mrpt 2.0.0, this returns either "GRAY" or "BGR".
Definition: CImage.cpp:856
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:1519
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:1205
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it...
Definition: CImage.cpp:1533
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:1676
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally.
Definition: CImage.cpp:1839
bool isExternallyStored() const noexcept
See setExternalStorage().
Definition: img/CImage.h:768
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:564
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:1526
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:921
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:1010
void swap(CImage &o)
Efficiently swap of two images.
Definition: CImage.cpp:177
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:223
unsigned char uint8_t
Definition: rptypes.h:44
T & at(unsigned int col, unsigned int row, unsigned int channel=0)
Definition: img/CImage.h:571
void swapRB()
Swaps red and blue channels.
Definition: CImage.cpp:1607
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:1813
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:311
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:846
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:1913
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:253
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:432
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process.
Definition: img/CImage.h:503
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:357
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:510
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images...
Definition: CImage.cpp:1259
A pair (x,y) of pixel coordinates (integer resolution).
Definition: TPixelCoord.h:39
void flipVertical()
Flips the image vertically.
Definition: CImage.cpp:1591
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:830
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:482
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:25
std::string getExternalStorageFile() const noexcept
Only if isExternallyStored() returns true.
Definition: img/CImage.h:771
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...
Definition: CImage.cpp:1615
TImageSize getSize() const
Return the size of the image.
Definition: img/CImage.h:643
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:1513
uint8_t * internal_get(int col, int row, uint8_t channel=0) const
Definition: CImage.cpp:470
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:961
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:1383
CV_MAT asCvMat(copy_type_t copy_type) const
Definition: img/CImage.h:537
void setFromIplImageReadOnly(IplImage *iplImage)
Definition: img/CImage.h:519
void setPixel(int x, int y, size_t color) override
Changes the value of the pixel (x,y).
Definition: CImage.cpp:1102
__int32 int32_t
Definition: rptypes.h:49
T * ptr(unsigned int col, unsigned int row, unsigned int channel=0)
Definition: img/CImage.h:587
PixelDepth getPixelDepth() const
Definition: CImage.cpp:300
#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...
Definition: CImage.cpp:1661
CImage()
Default constructor: initialize to empty image.
Definition: CImage.cpp:165
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:212
bool isColor() const
Returns true if the image is RGB, false if it is grayscale.
Definition: CImage.cpp:887
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:916
GLclampf green
Definition: glext.h:3529
struct _IplImage IplImage
Definition: img/CImage.h:21
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage.
Definition: img/CImage.h:1016
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:580
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows...
Definition: CImage.cpp:867
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:1716
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:1192
GLenum GLint GLint y
Definition: glext.h:3542
T * ptrLine(unsigned int row)
Definition: img/CImage.h:600
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:336
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:863
static int SERIALIZATION_JPEG_QUALITY()
Definition: CImage.cpp:71
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:1633
GLenum GLsizei GLsizei height
Definition: glext.h:3558
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true.
Definition: img/CImage.h:780
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:1019
static void setImagesPathBase(const std::string &path)
Definition: CImage.cpp:83
void equalizeHist(CImage &out_img) const
Equalize the image histogram, saving the new image in the given output object.
Definition: CImage.cpp:1854
void forceLoad() const
For external storage image objects only, this method makes sure the image is loaded in memory...
Definition: img/CImage.h:792
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:2049
void setFromImageReadOnly(const CImage &o)
Definition: img/CImage.h:475
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:371
static const std::string & getImagesPathBase()
By default, ".".
Definition: CImage.cpp:82



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ce1a28c9f Fri Aug 23 08:02:09 2019 +0200 at vie ago 23 08:10:11 CEST 2019