MIRA
Img.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_IMG_H_
48 #define _MIRA_IMG_H_
49 
50 #include <opencv2/core/core.hpp>
51 #include <opencv2/imgproc/imgproc.hpp>
52 
53 #include <platform/Types.h>
54 #include <geometry/Polygon.h>
55 #include <geometry/Size.h>
59 
60 #include <image/ImgPixel.h>
61 #include <image/ImgIterator.h>
62 
64 #if CV_MAJOR_VERSION >= 4
65 # define MIRA_USE_IPL_IMAGE 0
66 #endif
67 #ifndef MIRA_USE_IPL_IMAGE
70 # define MIRA_USE_IPL_IMAGE 0
71 #endif
72 
73 namespace mira {
74 
76 
84 template<typename TImg>
85 class ImgBase {
86 public:
90  struct ImgFormat
91  {
92  ImgFormat(int depth, const std::string& type, int channels)
94  {}
95 
97  r.member("Depth", depth, "The data type's depth (bits/channel)");
98  r.member("Channels", channels, "The number of channels");
99  r.member("Type", type, "The data type (signed/unsigned/float)");
100  }
101 
102  int depth;
103  std::string type;
104  int channels;
105  };
106 
107 protected:
113  }
114 
122  ImgBase(const cv::Mat& data) :
123  mData(data) {
124  }
125 
131  ImgBase(int width, int height, int type) :
132  mData(height, width, type) {
133  }
134 
135 #if MIRA_USE_IPL_IMAGE > 0
136 
142  ImgBase(const IplImage* img, bool copyData = false) {
143  mData = cv::cvarrToMat(img, copyData);
144  }
145 #endif
146 
154  ImgBase(const ImgBase& other) :
155  mData(other.mData) {
156  }
157 
158 public:
160  operator const cv::Mat&() const {
161  return mData;
162  }
163 
165  operator cv::Mat&() {
166  return mData;
167  }
168 
169 #if ((CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 3) || CV_MAJOR_VERSION >= 3)
170  operator const cv::_OutputArray() const {
172  return mData;
173  }
174 
176  operator cv::_OutputArray() {
177  return mData;
178  }
179 
181  operator cv::_InputArray() {
182  return mData;
183  }
184 
186  operator const cv::_InputArray() const {
187  return mData;
188  }
189 #endif
190 
191 #if MIRA_USE_IPL_IMAGE > 0
192  operator IplImage() {
194  return (IplImage) mData;
195  }
196 
198  operator const IplImage() const {
199  return (IplImage) mData;
200  }
201 #endif
202 
203 public:
204 
208  ImgBase& operator=(const ImgBase& other) {
209  mData = other;
210  return *this;
211  }
212 
218  void assignROI(const cv::Rect& roi, const ImgBase& other)
219  {
220  cv::Mat roiMat = this->mData(roi);
221 
222  if(roiMat.cols!=other.width()||roiMat.rows!=other.height())
223  MIRA_THROW(XLogical, "Target roi and source image width and height must match");
224 
225  // make sure, that type, channels and depth match !
226  assert(CV_MAT_TYPE(other.mData.flags) == CV_MAT_TYPE(roiMat.flags)&&
227  CV_MAT_CN(other.mData.flags) == CV_MAT_CN(roiMat.flags) &&
228  CV_MAT_DEPTH(other.mData.flags) == CV_MAT_DEPTH(roiMat.flags));
229 
230  // copy roi data scanline by scanline
231  std::size_t bpl = other.bytesPerLine();
232  for(int y=0; y<roi.height; ++y)
233  memcpy(roiMat.data+y*(size_t)roiMat.step, other.data(y),bpl);
234  }
235 
241  void assignMask(const cv::Rect& roi, const ImgBase& other, const cv::Mat& mask)
242  {
243  cv::Mat roiMat = this->mData(roi);
244 
245  if(roiMat.cols!=other.width()||roiMat.rows!=other.height())
246  MIRA_THROW(XLogical, "Target roi and source image width and height must match");
247 
248  if(mask.cols!=other.width()||mask.rows!=other.height())
249  MIRA_THROW(XLogical, "Mask and image width and height must match");
250 
251  // make sure, that type, channels and depth match !
252  assert(CV_MAT_TYPE(other.mData.flags) == CV_MAT_TYPE(roiMat.flags)&&
253  CV_MAT_CN(other.mData.flags) == CV_MAT_CN(roiMat.flags) &&
254  CV_MAT_DEPTH(other.mData.flags) == CV_MAT_DEPTH(roiMat.flags));
255 
256  other.mData.copyTo(roiMat, mask);
257  }
258 
267  void assignPolygon(const cv::Rect& roi, const ImgBase& other, const Polygon2i& poly)
268  {
269  if(poly.empty())
270  MIRA_THROW(XLogical, "Need at least 1 polygon point");
271 
272  std::vector<cv::Point> v;
273  foreach (const Point2i& p, poly)
274  v.emplace_back(p.x(), p.y());
275 
276  cv::Mat mask(roi.height, roi.width, CV_8U);
277  mask = cv::Scalar(0);
278  const cv::Point* vv[1] = { v.data() };
279  int n[1] = { int(v.size()) };
280  cv::fillPoly(mask, vv, n, 1, cv::Scalar(1));
281 
282  assignMask(roi, other, mask);
283  }
284 
285 public:
286 
287 
293  bool operator==(const cv::Mat& other) const {
294 
295  if (other.cols != mData.cols || other.rows != mData.rows)
296  return false; // not even dimensions are equal
297 
298  if (CV_MAT_TYPE(other.flags) != CV_MAT_TYPE(mData.flags) ||
299  CV_MAT_CN(other.flags) != CV_MAT_CN(mData.flags) ||
300  CV_MAT_DEPTH(other.flags) != CV_MAT_DEPTH(mData.flags)) // also flags must match
301  return false;
302 
303  // compare scanline by scanline, byte by byte
304  for (int y = 0; y < other.rows; ++y) {
305  const uint8* a = other.ptr(y);
306  const uint8* b = mData.ptr(y);
307  for (int x = 0; x < other.cols; ++x) {
308  if (a[x] != b[x])
309  return false; // we found a difference
310  }
311  }
312 
313  // if we reach here, both were equal
314  return true;
315  }
316 
320  bool operator!=(const cv::Mat& other) const {
321  return !ImgBase::operator==(other);
322  }
323 
324 public:
326  const cv::Mat& getMat() const {
327  return mData;
328  }
329 
331  bool empty() const {
332  return mData.empty();
333  }
334 
335  int width() const {
336  return mData.cols;
337  }
338 
339  int height() const {
340  return mData.rows;
341  }
342 
344  std::size_t step() const {
345  return (size_t)mData.step;
346  }
347 
349  std::size_t bytesPerLine() const {
350  return mData.elemSize() * mData.cols;
351  }
352 
354  Size2i size() const {
355  return Size2i(mData.size());
356  }
357 
362  int depth() const {
363  return mData.depth();
364  }
365 
370  int channels() const {
371  return mData.channels();
372  }
373 
375  bool isEmpty() const {
376  return mData.empty();
377  }
378 
380  uint8* data() { return mData.data; }
381 
383  const uint8* data() const { return mData.data; }
384 
385 
387  uint8* data(int y) { return mData.data + y*step(); }
388 
390  const uint8* data(int y) const { return mData.data + y*step(); }
391 
393  ImgFormat format() const {
394  static const char types[8] = {'U', 'S', 'U', 'S', 'S', 'F', 'F', '?'};
395  return ImgFormat(8*mData.elemSize1(),
396  std::string(types+CV_MAT_DEPTH(mData.flags), 1),
397  mData.channels());
398  }
399 
400 public:
401 
408  void resize(const Size2i& s) {
409  if(s==size())
410  return; // no need to resize
411  // create new matrix with requested size but same type
412  mData = cv::Mat(s.height(), s.width(), mData.type());
413  }
414 
416  void resize(int width, int height) {
418  }
419 
420 public:
421 
425  void clear()
426  {
427  std::size_t bpl = bytesPerLine();
428  for(int y=0; y<height(); ++y)
429  memset(data(y), 0, bpl);
430  }
431 
432 
433 public:
435  TImg clone() const {
436  return TImg(mData.clone());
437  }
438 
439 public:
441  std::size_t total() const {
442  return mData.rows * mData.cols;
443  }
444 
445 public:
446 
448 
449 
453  template<typename Derived>
455  r.version(2, this);
456 
457  // try to serialize with codec, if any
458  if(r.codec(mData))
459  return;
460 
461  r.member("Width", mData.cols, "The width of the image");
462  r.member("Height", mData.rows, "The height of the image");
463  int type = mData.type();
464  r.member("Type", type, "The data type including number of channels");
465 
466  std::size_t bpl = bytesPerLine();
467 
468  // serialize the image data line by line
469  const uchar* data = mData.data;
470  for (int i = 0; i < mData.rows; ++i, data += mData.step)
471  r.write(data, bpl);
472 
473  }
474 
479  template<typename Derived>
481  int cols, rows, type;
482 
483  if(r.version(2, this) > 1) {
484  // try to deserialize with codec, if any
485  if(r.codec(mData))
486  return;
487  }
488 
489  r.member("Width", cols, "The width of the image");
490  r.member("Height", rows, "The height of the image");
491  r.member("Type", type, "The data type including number of channels");
492 
493  // create the empty image
494  mData.create(rows, cols, type);
495 
496  std::size_t bpl = bytesPerLine();
497 
498  // and deserialize the image line by line
499  uchar* data = mData.data;
500  for (int i = 0; i < mData.rows; ++i, data += mData.step)
501  r.read(data, bpl);
502  }
503 
510  Size2i size(mData.cols, mData.rows);
511  r.member("Size", size, "The image size", REFLECT_CTRLFLAG_TEMP_TRACKING);
512 
513  ImgFormat f = format();
514  r.member("Format", f, "The storage format", REFLECT_CTRLFLAG_TEMP_TRACKING);
515  }
516 
517 protected:
519 };
520 
522 
529 template<typename TImg, typename TPixel>
530 class ImgTypedBase: public ImgBase<TImg> {
531  typedef ImgBase<TImg> Base;
532 
533 protected:
534  friend class ImgBase<TImg> ;
535 
537  Base(data) {
538  }
539 
544  this->mData.flags = (this->mData.flags & ~CV_MAT_TYPE_MASK) | cv::DataType<TPixel>::type;
545  }
546 
553  Base(width, height, cv::DataType<TPixel>::type) {
554  }
555 
556 public:
568  static TImg convertFrom(const cv::Mat& other, bool alwaysCopy = false) {
569  int targetType = cv::DataType<TPixel>::type;
570 
571  // if channels and type equals and we don't want to copy - just return the image
572  if (!alwaysCopy && (CV_MAKETYPE(other.type(), other.channels()) == targetType))
573  return TImg(other);
574 
575  cv::Mat otherData = other;
576  cv::Mat data(otherData.rows, otherData.cols, targetType);
577 
578  if (other.channels() != data.channels()) {
579  // we need to convert the number of channels
580 
581  // create a temporary image that has the type of the other
582  // image but the number of channels of our target type
583  cv::Mat tmp(otherData.rows, otherData.cols,
584  CV_MAKETYPE(otherData.type(), data.channels()));
585 
586  // use MixChannels and build fromTo-mapping first
587  std::vector<int> fromTo(data.channels() * 2);
588 
589  int srcChannel = 0;
590  for (int k = 0; k < data.channels(); ++k, ++srcChannel) {
591  fromTo[2 * k] = (srcChannel < otherData.channels() ? srcChannel : 0);
592  fromTo[2 * k + 1] = k;
593  }
594 
595  cv::mixChannels(&otherData, 1, &tmp, 1, fromTo.data(),
596  data.channels());
597 
598  otherData = tmp;
599  }
600 
601 #if ((CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >= 3) || CV_MAJOR_VERSION >= 3)
602  otherData.convertTo(data, targetType);
603 #else
604  // Since this:
605  //otherData.convertTo(data, targetType);
606  // is buggy in the OpenCV 2.0-2.1, we have to use the
607  // C-interface:
608  CvMat src = otherData;
609  CvMat dest = data;
610  cvConvertScale(&src, &dest);
611 #endif
612  return TImg(data);
613  }
614 
615 public:
617  TImg& operator=(const TPixel& p) {
618  castToMat() = p;
619  return *This();
620  }
621 
626  TPixel* operator[](int y) {
627  return this->castToMat()[y];
628  }
629 
634  const TPixel* operator[](int y) const {
635  return this->castToMat()[y];
636  }
637 
643  TImg operator()(const cv::Rect& roi) const {
644  return TImg(this->mData(roi));
645  }
646 
647 
651  TPixel& operator()(int x, int y) {
652  return this->castToMat()(y, x);
653  }
654 
658  const TPixel& operator()(int x, int y) const {
659  return this->castToMat()(y, x);
660  }
661 
665  TPixel& operator()(const cv::Point& p) {
666  return this->castToMat()(p);
667  }
668 
672  const TPixel& operator()(const cv::Point& p) const {
673  return this->castToMat()(p);
674  }
675 
676 public:
677 
680 
686  return iterator(&castToMat());
687  }
688 
695  iterator it(&castToMat());
696  it += this->total();
697  return it;
698  }
699 
705  return const_iterator(&castToMat());
706  }
707 
713  const_iterator end() const {
714  const_iterator it(&castToMat());
715  it += this->total();
716  return it;
717  }
718 
719 public:
720 
722 
723 
726  template<typename Derived>
729  }
730 
736  template<typename Derived>
739  // make sure that the type of the deserialized image matches
740  // to our type, otherwise throw exception
741  if (this->mData.type() != cv::DataType<TPixel>::type)
742  MIRA_THROW(XIO, "The deserialized image type "
743  "(depth: " << this->mData.depth() << ", channels: "
744  << this->mData.channels() << ") "
745  "does not match the type of the Img class "
746  "(depth: " << CV_MAT_DEPTH(cv::DataType<TPixel>::type)
747  << ", channels: " << CV_MAT_CN(cv::DataType<TPixel>::type)
748  << ")");
749  }
750 
756  }
757 
758 protected:
759 
760  TImg* This() {
761  return static_cast<TImg*> (this);
762  }
763 
764  const TImg* This() const {
765  return static_cast<const TImg*> (this);
766  }
767 
769  cv::Mat_<TPixel>& castToMat() {
770  return static_cast<cv::Mat_<TPixel>&> (this->mData);
771  }
772 
774  const cv::Mat_<TPixel>& castToMat() const {
775  return static_cast<const cv::Mat_<TPixel>&> (this->mData);
776  }
777 
778 };
779 
781 
787 template<typename T = void, int TChannels = 1>
788 class Img: public ImgTypedBase<Img<T, TChannels> , ImgPixel<T, TChannels> > {
789 public:
791 
792 protected:
793 
796 
797 protected:
798 
799  friend class ImgBase<Self> ;
800  friend class ImgTypedBase<Self, Pixel> ;
801 
802  // this must NOT be public, otherwise one could spoil our type safety
803  Img(const cv::Mat& data) :
804  Base(data) {
805  }
806 
807 public:
808 
810  enum { Channels = TChannels };
811 
812 public:
813 
814  Img() {
815  }
816 
823  Img(int width, int height) :
824  Base(width, height) {
825  }
831  Img(const Size2i& size) :
832  Base(size.width(), size.height()) {
833  }
834 
835 public:
843  Self& operator=(const Pixel& p) {
844  return Base::operator=(p);
845  }
846 };
847 
849 
855 template<typename T>
856 class Img<T, 1> : public ImgTypedBase<Img<T, 1> , T> {
857 public:
858  typedef T Pixel;
859 
860 protected:
861 
862  typedef Img<T, 1> Self;
864 
865 protected:
866 
867  friend class ImgBase<Self> ;
868  friend class ImgTypedBase<Self, Pixel> ;
869 
870  // this must not be public, otherwise one could spoil our type safety
871  Img(const cv::Mat& data) :
872  Base(data) {
873  }
874 
875 public:
876 
878  enum { Channels = 1 };
879 
880 public:
881 
882  Img() {
883  }
890  Img(int width, int height) :
891  Base(width, height) {
892  }
898  Img(const Size2i& size) :
899  Base(size.width(), size.height()) {
900  }
901 
902 public:
910  Self& operator=(const Pixel& p) {
911  return Base::operator=(p);
912  }
913 };
914 
916 
922 template<>
923 class Img<void, 1> : public ImgBase<Img<void, 1> > {
924  typedef Img<void, 1> Self;
925  typedef ImgBase<Self> Base;
926 
927 protected:
928  friend class ImgBase<Self> ;
929 
930 public:
931 
932  Img() {
933  }
942  Img(int width, int height, int type, int channels) :
943  Base(width, height, CV_MAKETYPE(type, channels)) {
944  }
952  Img(const Size2i& size, int type, int channels) :
953  Base(size.width(), size.height(), CV_MAKETYPE(type, channels)) {
954  }
955 
956  template<typename TImg>
957  Img(const ImgBase<TImg>& other) :
958  Base(other) {
959  }
960 
961 #if MIRA_USE_IPL_IMAGE > 0
962 
969  Img(const IplImage* img, bool copyData = false) :
970  Base(img, copyData) {
971  }
972 #endif
973 
977  Img(const cv::Mat& data) :
978  Base(data) {
979  }
980 
982  template<typename TImg>
983  Self& operator=(const ImgBase<TImg>& other) {
984  mData = other.getMat();
985  return *this;
986  }
987 
993  Img operator()(const cv::Rect& roi) const {
994  return Img(this->mData(roi));
995  }
996 
1001  template <typename TPixel, int TChannels>
1002  bool hasType() const
1003  {
1004  return cv::DataType<TPixel>::depth == this->depth() &&
1005  TChannels==this->channels();
1006  }
1007 
1008 public:
1009 
1012 
1014  return iterator(&this->mData);
1015  }
1016 
1017  iterator end() {
1018  iterator it(&this->mData);
1019  it.ptr = it.sliceEnd = (this->mData.data + this->mData.step*(this->mData.rows-1)) +
1020  this->mData.cols * this->mData.elemSize();
1021  return it;
1022  }
1023 
1025  return const_iterator(&this->mData);
1026  }
1027 
1028  const_iterator end() const {
1029  const_iterator it(&this->mData);
1030  it.ptr = it.sliceEnd = (this->mData.data + this->mData.step*(this->mData.rows-1)) +
1031  this->mData.cols * this->mData.elemSize();
1032  return it;
1033  }
1034 
1035 };
1036 
1037 
1038 
1046 template <typename TPixel, int TChannels>
1048 {
1049  // if other has the same type here, return typed shallow copy
1050  if(other.hasType<TPixel,TChannels>())
1051  return Img<TPixel,TChannels>::convertFrom(other);
1052 
1053  // otherwise cannot cast
1054  MIRA_THROW(XBadCast, "Cannot cast this untyped image with of type " <<
1055  other.depth() << "," << other.channels() <<
1056  " to channel of type " << cv::DataType<TPixel>::depth <<
1057  "," << TChannels);
1058 }
1059 
1060 
1062 template <typename TPixel, int TChannels>
1063 class IsNotMetaSerializable<Img<TPixel, TChannels>> : public std::true_type {};
1064 
1065 
1071 
1077 
1083 
1089 
1095 
1101 
1107 
1113 
1119 
1125 
1131 
1137 
1143 
1149 
1155 
1161 
1167 
1173 
1179 
1185 
1187 
1188 }//end namespace
1189 
1190 #endif /* _MIRA_IMG_H_ */
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:95
This object can use object tracking internally, but the object tracking system&#39;s state remains unchan...
Definition: ReflectControlFlags.h:82
specialized typed image with 1 channel This template class provides convenient way to create an image...
Definition: Img.h:856
bool operator!=(const cv::Mat &other) const
Returns true if two images are different.
Definition: Img.h:320
Img(const cv::Mat &data)
Definition: Img.h:871
Img< uint16, 3 > Img16U3
Image: unsigned 16-bit integers, 3 channel.
Definition: Img.h:1106
std::size_t total() const
Returns the total size of the matrix (rows*cols)
Definition: Img.h:441
ImgPixel< T, TChannels > Pixel
Definition: Img.h:790
Image storage format description (used e.g.
Definition: Img.h:90
Img< double, 3 > Img64F3
Image: double precision floating-point numbers, 3 channel.
Definition: Img.h:1178
bool hasType() const
Returns true, if the untyped image internally has the specified type, i.e.
Definition: Img.h:1002
bool isEmpty() const
returns true if internal Mat is empty
Definition: Img.h:375
Untyped image iterator, that allows to iterate over images or image regions pixel by pixel similar to...
Definition: ImgIterator.h:415
TPixel & operator()(const cv::Point &p)
access to pixel given by point p
Definition: Img.h:665
std::size_t bytesPerLine() const
Returns the number of bytes per image line.
Definition: Img.h:349
UntypedImgIterator iterator
Definition: Img.h:1010
void assignROI(const cv::Rect &roi, const ImgBase &other)
Copies the content of other into the specified region of interest (ROI) of THIS image.
Definition: Img.h:218
Classes to access pixels of images with variable type and channels.
const TImg * This() const
Definition: Img.h:764
ImgIterator< TPixel > iterator
Definition: Img.h:678
Img< uint8, 4 > Img8U4
Image: unsigned 8-bit integers, 4 channel.
Definition: Img.h:1088
Size2i size() const
Returns size of image data.
Definition: Img.h:354
ImgTypedBase()
standard constructor
Definition: Img.h:543
std::string type
Definition: Img.h:103
Img(const Size2i &size)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:898
ImgBase(const ImgBase &other)
Copy constructor, that creates a shallow copy.
Definition: Img.h:154
bool empty() const
returns true if internal Mat is empty
Definition: Img.h:331
Img(const cv::Mat &data)
constructor from cv::Mat constructor is public, since we do not have a type safe image ...
Definition: Img.h:977
VersionType version(VersionType version, const T *caller=NULL)
Definition: BinarySerializer.h:267
General point class template.
Definition: Point.h:140
TPixel * operator[](int y)
access to image row
Definition: Img.h:626
ImgBase(const cv::Mat &data)
constructor to initialize internal data from cv::Mat
Definition: Img.h:122
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
bool operator==(const cv::Mat &other) const
Returns true if two images are equal.
Definition: Img.h:293
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:947
void assignMask(const cv::Rect &roi, const ImgBase &other, const cv::Mat &mask)
Copies the content of other into the specified region of interest (ROI) of THIS image, where mask has non-zero values.
Definition: Img.h:241
Self & operator=(const Pixel &p)
assigns image with given Pixel assigns each pixel of the image to the given Pixel ...
Definition: Img.h:843
ImgBase & operator=(const ImgBase &other)
Assignment operator, that usually makes a shallow copy of "other".
Definition: Img.h:208
Size< int, 2 > Size2i
The size type for 2D objects in integer precision.
Definition: Size.h:277
Img< int16, 1 > Img16S1
Image: 16-bit integers, 1 channel.
Definition: Img.h:1118
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
int depth
Definition: Img.h:102
Img< float, 1 > Img32F1
Image: floating-point numbers, 1 channel.
Definition: Img.h:1142
int channels() const
Returns the number of channels of this image.
Definition: Img.h:370
TImg operator()(const cv::Rect &roi) const
returns a ROI out of the image Returns a new image with set ROI on the image data.
Definition: Img.h:643
Img operator()(const cv::Rect &roi) const
returns a ROI out of the image Returns a new image with set ROI on the image data.
Definition: Img.h:993
Img< double, 2 > Img64F2
Image: double precision floating-point numbers, 2 channel.
Definition: Img.h:1172
Definition: Img.h:810
Img()
Definition: Img.h:882
iterator begin()
Definition: Img.h:1013
Img(int width, int height)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:890
Self & operator=(const ImgBase< TImg > &other)
shallow copy
Definition: Img.h:983
Self & operator=(const Pixel &p)
assigns image with given Pixel assigns each pixel of the image to the given Pixel ...
Definition: Img.h:910
ImgFormat(int depth, const std::string &type, int channels)
Definition: Img.h:92
const_iterator begin() const
Returns an const iterator to the beginning of this image (image region)
Definition: Img.h:704
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
void reflect(BinarySerializer< Derived > &r)
reflect method for binaryStream serialization This method uses the reflect method of the ImageBase cl...
Definition: Img.h:727
Img(const ImgBase< TImg > &other)
Definition: Img.h:957
bool codec(const T &obj)
Encodes the specified object containing the data using a matching codec.
Definition: BinarySerializer.h:307
Img< float, 2 > Img32F2
Image: floating-point numbers, 2 channel.
Definition: Img.h:1148
Img()
Definition: Img.h:814
int depth() const
Returns the bit-depth of the image E.g.
Definition: Img.h:362
Img< double, 1 > Img64F1
Image: double precision floating-point numbers, 1 channel.
Definition: Img.h:1166
Base class for typed images.
Definition: Img.h:530
ImgTypedBase(const cv::Mat &data)
Definition: Img.h:536
const TPixel & operator()(const cv::Point &p) const
const access to pixel given by point p
Definition: Img.h:672
Img< uint16, 1 > Img16U1
Image: unsigned 16-bit integers, 1 channel.
Definition: Img.h:1094
Img< uint16, 4 > Img16U4
Image: unsigned 16-bit integers, 4 channel.
Definition: Img.h:1112
Img< uint8, 3 > Img8U3
Image: unsigned 8-bit integers, 3 channel.
Definition: Img.h:1082
Img< float, 3 > Img32F3
Image: floating-point numbers, 3 channel.
Definition: Img.h:1154
const_iterator end() const
Returns an const iterator to the end of this image (image region) Note that the end iterator is NOT p...
Definition: Img.h:713
void assignPolygon(const cv::Rect &roi, const ImgBase &other, const Polygon2i &poly)
Copies the content of other into the specified region of interest (ROI) of THIS image, in area covered by polygon.
Definition: Img.h:267
iterator begin()
Returns an iterator to the beginning of this image (image region)
Definition: Img.h:685
Img(int width, int height, int type, int channels)
constructs a new image of given size and type note: the image data is allocated but not initialized ...
Definition: Img.h:942
Type trait that indicates whether a type does not support to gather meta information about it...
Definition: IsNotMetaSerializable.h:67
Type trait that indicates whether a type does not support to gather meta information about it...
ImgTypedBase(int width, int height)
constructs a new image using width and height and type from Template type.
Definition: Img.h:552
void reflect(BinarySerializer< Derived > &r)
reflect method for binaryStream serialization This method implements the reflection of width...
Definition: Img.h:454
Binary serializer and deserializer.
ImgFormat format() const
Return the storage format description.
Definition: Img.h:393
ImgConstIterator< TPixel > const_iterator
Definition: Img.h:679
static TImg convertFrom(const cv::Mat &other, bool alwaysCopy=false)
Converts a typed image into another typed image If the channels and/or type of the new image and the ...
Definition: Img.h:568
const TPixel * operator[](int y) const
const access to image row
Definition: Img.h:634
Deserializer that uses BinaryIstream to deserialize the objects from binary format.
Definition: BinarySerializer.h:925
TPixel & operator()(int x, int y)
access pixel(x,y)
Definition: Img.h:651
void resize(int width, int height)
Same as above method.
Definition: Img.h:416
void reflect(JSONSerializer &r)
Definition: Img.h:96
boost::geometry::model::ring< Point2i > Polygon2i
A 2D polygon with integer precision.
Definition: Polygon.h:128
ImgBase()
base constructor internal data is empty.
Definition: Img.h:112
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
Img< int16, 3 > Img16S3
Image: 16-bit integers, 3 channel.
Definition: Img.h:1130
uint8_t uint8
Definition: Types.h:62
void reflect(BinaryDeserializer< Derived > &r)
reflect method for binaryStream deserialization This method uses the reflect method of the ImageBase ...
Definition: Img.h:737
const uint8 * data() const
Returns const pointer to underlying image data.
Definition: Img.h:383
void reflect(JSONSerializer &r)
reflect method for json serialization This method implements the reflection of general data like widt...
Definition: Img.h:509
cv::Mat_< TPixel > & castToMat()
operator for convenience access to image data as Mat
Definition: Img.h:769
TImg & operator=(const TPixel &p)
assigns a specific type to the image data (used to set pixel values)
Definition: Img.h:617
class for typed images.
Definition: Img.h:788
Const image iterator that allows to iterate over images or image regions pixel by pixel similar to it...
Definition: ImgIterator.h:287
int height() const
Definition: Img.h:339
Img< uint8, 1 > Img8U1
Image: unsigned 8-bit integers, 1 channel.
Definition: Img.h:1070
void write(const T *data, std::size_t count)
Definition: BinarySerializer.h:284
int width() const
Definition: Img.h:335
const cv::Mat_< TPixel > & castToMat() const
operator for convenience const access to image data as Mat
Definition: Img.h:774
iterator end()
Returns an iterator to the end of this image (image region) Note that the end iterator is NOT part of...
Definition: Img.h:694
ImgBase(int width, int height, int type)
constructor initialize internal data with width, height, and type note: the image data is allocated b...
Definition: Img.h:131
Simple Wrapper for Boost::geometry polygon.
ImgTypedBase< Self, Pixel > Base
Definition: Img.h:795
void reflect(BinaryDeserializer< Derived > &r)
reflect method for binaryStream deserialization This method implements the reflection for width...
Definition: Img.h:480
void resize(const Size2i &s)
Resizes the image to the specified dimensions (without changing its type, i.e.
Definition: Img.h:408
Img(const Size2i &size, int type, int channels)
constructs a new image of given size and type note: the image data is allocated but not initialized ...
Definition: Img.h:952
VersionType version(VersionType version, const T *caller=NULL)
Definition: BinarySerializer.h:932
Img< int16, 2 > Img16S2
Image: 16-bit integers, 2 channel.
Definition: Img.h:1124
Img< TPixel, TChannels > img_cast(Img<> &other)
Casts an untyped Img<> into a typed image with the specified pixel type and channel count...
Definition: Img.h:1047
This class provides templatized multidimensional sizes for multidimensional geometric objects...
Img(const cv::Mat &data)
Definition: Img.h:803
Img()
Definition: Img.h:932
ImgIterator classes that wrap OpenCV iterators.
const_iterator end() const
Definition: Img.h:1028
uint8 * data()
Returns pointer to underlying image data.
Definition: Img.h:380
void reflect(JSONSerializer &r)
reflect method for json serialization This method uses the reflect method of the ImageBase class ...
Definition: Img.h:754
bool codec(T &obj)
Decodes the specified object from the serialized data.
Definition: BinarySerializer.h:971
Img< T, TChannels > Self
Definition: Img.h:794
ImgTypedBase< Self, Pixel > Base
Definition: Img.h:863
TImg * This()
Definition: Img.h:760
const cv::Mat & getMat() const
Returns const access to internal data.
Definition: Img.h:326
Definition: BinarySerializer.h:257
Untyped const image iterator, that allows to iterate over images or image regions pixel by pixel simi...
Definition: ImgIterator.h:374
Img< T, 1 > Self
Definition: Img.h:862
const uint8 * data(int y) const
Returns const pointer to underlying image data starting at scanline y.
Definition: Img.h:390
ImgBase class.
Definition: Img.h:85
TImg clone() const
Deep copy of image data.
Definition: Img.h:435
#define MIRA_NO_GENERIC_REFLECT_MEMBER(Type)
Exception that is thrown, if a certain type does not support the specified reflector/serializer/deser...
Definition: NoGenericReflect.h:85
Img(const Size2i &size)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:831
std::size_t step() const
Number of bytes from one row to the next.
Definition: Img.h:344
dynamic ImgPixel class template ImgPixel class providing flexible types and channels.
Definition: ImgPixel.h:110
const uchar * sliceEnd
Definition: ImgIterator.h:160
void read(T *data, std::size_t count)
Definition: BinarySerializer.h:949
UntypedImgConstIterator const_iterator
Definition: Img.h:1011
typedef Mat
untyped image class This class provides a fully dynamic image, where type and channels are not known ...
Definition: Img.h:923
Img< uint8, 2 > Img8U2
Image: unsigned 8-bit integers, 2 channels.
Definition: Img.h:1076
Img< uint16, 2 > Img16U2
Image: unsigned 16-bit integers, 2 channel.
Definition: Img.h:1100
int channels
Definition: Img.h:104
Img< int16, 4 > Img16S4
Image: 16-bit integers, 4 channel.
Definition: Img.h:1136
iterator end()
Definition: Img.h:1017
const_iterator begin() const
Definition: Img.h:1024
Img(int width, int height)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:823
cv::Mat mData
Definition: Img.h:518
const TPixel & operator()(int x, int y) const
const access pixel(x,y)
Definition: Img.h:658
void clear()
Sets each pixel and each channel to zero.
Definition: Img.h:425
Img< double, 4 > Img64F4
Image: double precision floating-point numbers, 4 channel.
Definition: Img.h:1184
Image iterator that allows to iterate over images or image regions pixel by pixel similar to iterator...
Definition: ImgIterator.h:324
const uchar * ptr
Definition: ImgIterator.h:158
Provides the MIRA_NO_GENERIC_REFLECT macros.
Img< float, 4 > Img32F4
Image: floating-point numbers, 4 channel.
Definition: Img.h:1160
uint8 * data(int y)
Returns pointer to underlying image data starting at scanline y.
Definition: Img.h:387
T Pixel
Definition: Img.h:858