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) {
644  return TImg(this->mData(roi));
645  }
646 
652  TImg operator()(const cv::Rect& roi) const {
653  return TImg(this->mData(roi));
654  }
655 
656 
660  TPixel& operator()(int x, int y) {
661  return this->castToMat()(y, x);
662  }
663 
667  const TPixel& operator()(int x, int y) const {
668  return this->castToMat()(y, x);
669  }
670 
674  TPixel& operator()(const cv::Point& p) {
675  return this->castToMat()(p);
676  }
677 
681  const TPixel& operator()(const cv::Point& p) const {
682  return this->castToMat()(p);
683  }
684 
685 public:
686 
689 
695  return iterator(&castToMat());
696  }
697 
704  iterator it(&castToMat());
705  it += this->total();
706  return it;
707  }
708 
714  return const_iterator(&castToMat());
715  }
716 
722  const_iterator end() const {
723  const_iterator it(&castToMat());
724  it += this->total();
725  return it;
726  }
727 
728 public:
729 
731 
732 
735  template<typename Derived>
738  }
739 
745  template<typename Derived>
748  // make sure that the type of the deserialized image matches
749  // to our type, otherwise throw exception
750  if (this->mData.type() != cv::DataType<TPixel>::type)
751  MIRA_THROW(XIO, "The deserialized image type "
752  "(depth: " << this->mData.depth() << ", channels: "
753  << this->mData.channels() << ") "
754  "does not match the type of the Img class "
755  "(depth: " << CV_MAT_DEPTH(cv::DataType<TPixel>::type)
756  << ", channels: " << CV_MAT_CN(cv::DataType<TPixel>::type)
757  << ")");
758  }
759 
765  }
766 
767 protected:
768 
769  TImg* This() {
770  return static_cast<TImg*> (this);
771  }
772 
773  const TImg* This() const {
774  return static_cast<const TImg*> (this);
775  }
776 
778  cv::Mat_<TPixel>& castToMat() {
779  return static_cast<cv::Mat_<TPixel>&> (this->mData);
780  }
781 
783  const cv::Mat_<TPixel>& castToMat() const {
784  return static_cast<const cv::Mat_<TPixel>&> (this->mData);
785  }
786 
787 };
788 
790 
796 template<typename T = void, int TChannels = 1>
797 class Img: public ImgTypedBase<Img<T, TChannels> , ImgPixel<T, TChannels> > {
798 public:
800 
801 protected:
802 
805 
806 protected:
807 
808  friend class ImgBase<Self> ;
809  friend class ImgTypedBase<Self, Pixel> ;
810 
811  // this must NOT be public, otherwise one could spoil our type safety
812  Img(const cv::Mat& data) :
813  Base(data) {
814  }
815 
816 public:
817 
819  enum { Channels = TChannels };
820 
821 public:
822 
823  Img() {
824  }
825 
832  Img(int width, int height) :
833  Base(width, height) {
834  }
840  Img(const Size2i& size) :
841  Base(size.width(), size.height()) {
842  }
843 
844 public:
852  Self& operator=(const Pixel& p) {
853  return Base::operator=(p);
854  }
855 };
856 
858 
864 template<typename T>
865 class Img<T, 1> : public ImgTypedBase<Img<T, 1> , T> {
866 public:
867  typedef T Pixel;
868 
869 protected:
870 
871  typedef Img<T, 1> Self;
873 
874 protected:
875 
876  friend class ImgBase<Self> ;
877  friend class ImgTypedBase<Self, Pixel> ;
878 
879  // this must not be public, otherwise one could spoil our type safety
880  Img(const cv::Mat& data) :
881  Base(data) {
882  }
883 
884 public:
885 
887  enum { Channels = 1 };
888 
889 public:
890 
891  Img() {
892  }
899  Img(int width, int height) :
900  Base(width, height) {
901  }
907  Img(const Size2i& size) :
908  Base(size.width(), size.height()) {
909  }
910 
911 public:
919  Self& operator=(const Pixel& p) {
920  return Base::operator=(p);
921  }
922 };
923 
925 
931 template<>
932 class Img<void, 1> : public ImgBase<Img<void, 1> > {
933  typedef Img<void, 1> Self;
934  typedef ImgBase<Self> Base;
935 
936 protected:
937  friend class ImgBase<Self> ;
938 
939 public:
940 
941  Img() {
942  }
951  Img(int width, int height, int type, int channels) :
952  Base(width, height, CV_MAKETYPE(type, channels)) {
953  }
961  Img(const Size2i& size, int type, int channels) :
962  Base(size.width(), size.height(), CV_MAKETYPE(type, channels)) {
963  }
964 
965  template<typename TImg>
966  Img(const ImgBase<TImg>& other) :
967  Base(other) {
968  }
969 
970 #if MIRA_USE_IPL_IMAGE > 0
971 
978  Img(const IplImage* img, bool copyData = false) :
979  Base(img, copyData) {
980  }
981 #endif
982 
986  Img(const cv::Mat& data) :
987  Base(data) {
988  }
989 
991  template<typename TImg>
992  Self& operator=(const ImgBase<TImg>& other) {
993  mData = other.getMat();
994  return *this;
995  }
996 
997 
1003  Img operator()(const cv::Rect& roi) {
1004  return Img(this->mData(roi));
1005  }
1006 
1012  Img operator()(const cv::Rect& roi) const {
1013  return Img(this->mData(roi));
1014  }
1015 
1020  template <typename TPixel, int TChannels>
1021  bool hasType() const
1022  {
1023  return cv::DataType<TPixel>::depth == this->depth() &&
1024  TChannels==this->channels();
1025  }
1026 
1027 public:
1028 
1031 
1033  return iterator(&this->mData);
1034  }
1035 
1036  iterator end() {
1037  iterator it(&this->mData);
1038  it.ptr = it.sliceEnd = (this->mData.data + this->mData.step*(this->mData.rows-1)) +
1039  this->mData.cols * this->mData.elemSize();
1040  return it;
1041  }
1042 
1044  return const_iterator(&this->mData);
1045  }
1046 
1047  const_iterator end() const {
1048  const_iterator it(&this->mData);
1049  it.ptr = it.sliceEnd = (this->mData.data + this->mData.step*(this->mData.rows-1)) +
1050  this->mData.cols * this->mData.elemSize();
1051  return it;
1052  }
1053 
1054 };
1055 
1056 
1057 
1065 template <typename TPixel, int TChannels>
1067 {
1068  // if other has the same type here, return typed shallow copy
1069  if(other.hasType<TPixel,TChannels>())
1070  return Img<TPixel,TChannels>::convertFrom(other);
1071 
1072  // otherwise cannot cast
1073  MIRA_THROW(XBadCast, "Cannot cast this untyped image with of type " <<
1074  other.depth() << "," << other.channels() <<
1075  " to channel of type " << cv::DataType<TPixel>::depth <<
1076  "," << TChannels);
1077 }
1078 
1079 
1081 template <typename TPixel, int TChannels>
1082 class IsNotMetaSerializable<Img<TPixel, TChannels>> : public std::true_type {};
1083 
1084 
1090 
1096 
1102 
1108 
1114 
1120 
1126 
1132 
1138 
1144 
1150 
1156 
1162 
1168 
1174 
1180 
1186 
1192 
1198 
1204 
1206 
1207 }//end namespace
1208 
1209 #endif /* _MIRA_IMG_H_ */
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
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:865
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:880
Img< uint16, 3 > Img16U3
Image: unsigned 16-bit integers, 3 channel.
Definition: Img.h:1125
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:799
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:1197
bool hasType() const
Returns true, if the untyped image internally has the specified type, i.e.
Definition: Img.h:1021
TImg operator()(const cv::Rect &roi)
returns a ROI out of the image Returns a new image with set ROI on the image data.
Definition: Img.h:643
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
Typedefs for OS independent basic data types.
TPixel & operator()(const cv::Point &p)
access to pixel given by point p
Definition: Img.h:674
std::size_t bytesPerLine() const
Returns the number of bytes per image line.
Definition: Img.h:349
UntypedImgIterator iterator
Definition: Img.h:1029
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:773
ImgIterator< TPixel > iterator
Definition: Img.h:687
Img< uint8, 4 > Img8U4
Image: unsigned 8-bit integers, 4 channel.
Definition: Img.h:1107
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:907
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:986
VersionType version(VersionType version, const T *caller=NULL)
Definition: BinarySerializer.h:267
General point class template.
Definition: Point.h:133
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:871
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:852
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:275
Img< int16, 1 > Img16S1
Image: 16-bit integers, 1 channel.
Definition: Img.h:1137
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:956
int depth
Definition: Img.h:102
Img< float, 1 > Img32F1
Image: floating-point numbers, 1 channel.
Definition: Img.h:1161
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:652
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:1012
Img< double, 2 > Img64F2
Image: double precision floating-point numbers, 2 channel.
Definition: Img.h:1191
Definition: Img.h:819
Img()
Definition: Img.h:891
Img operator()(const cv::Rect &roi)
returns a ROI out of the image Returns a new image with set ROI on the image data.
Definition: Img.h:1003
iterator begin()
Definition: Img.h:1032
Img(int width, int height)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:899
Self & operator=(const ImgBase< TImg > &other)
shallow copy
Definition: Img.h:992
Self & operator=(const Pixel &p)
assigns image with given Pixel assigns each pixel of the image to the given Pixel ...
Definition: Img.h:919
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:713
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
void reflect(BinarySerializer< Derived > &r)
reflect method for binaryStream serialization This method uses the reflect method of the ImageBase cl...
Definition: Img.h:736
Img(const ImgBase< TImg > &other)
Definition: Img.h:966
bool codec(const T &obj)
Encodes the specified object containing the data using a matching codec.
Definition: BinarySerializer.h:311
Img< float, 2 > Img32F2
Image: floating-point numbers, 2 channel.
Definition: Img.h:1167
Img()
Definition: Img.h:823
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:1185
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:681
Img< uint16, 1 > Img16U1
Image: unsigned 16-bit integers, 1 channel.
Definition: Img.h:1113
Img< uint16, 4 > Img16U4
Image: unsigned 16-bit integers, 4 channel.
Definition: Img.h:1131
Img< uint8, 3 > Img8U3
Image: unsigned 8-bit integers, 3 channel.
Definition: Img.h:1101
Img< float, 3 > Img32F3
Image: floating-point numbers, 3 channel.
Definition: Img.h:1173
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:722
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:694
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:951
Type trait that indicates whether a type does not support to gather meta information about it...
Definition: IsNotMetaSerializable.h:65
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:688
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:928
TPixel & operator()(int x, int y)
access pixel(x,y)
Definition: Img.h:660
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:1149
void reflect(BinaryDeserializer< Derived > &r)
reflect method for binaryStream deserialization This method uses the reflect method of the ImageBase ...
Definition: Img.h:746
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:778
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:797
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:1089
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:783
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:703
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:804
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:961
VersionType version(VersionType version, const T *caller=NULL)
Definition: BinarySerializer.h:935
Img< int16, 2 > Img16S2
Image: 16-bit integers, 2 channel.
Definition: Img.h:1143
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:1066
This class provides templatized multidimensional sizes for multidimensional geometric objects...
Img(const cv::Mat &data)
Definition: Img.h:812
Img()
Definition: Img.h:941
ImgIterator classes that wrap OpenCV iterators.
const_iterator end() const
Definition: Img.h:1047
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:763
bool codec(T &obj)
Decodes the specified object from the serialized data.
Definition: BinarySerializer.h:978
Img< T, TChannels > Self
Definition: Img.h:803
ImgTypedBase< Self, Pixel > Base
Definition: Img.h:872
TImg * This()
Definition: Img.h:769
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:871
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:840
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:952
UntypedImgConstIterator const_iterator
Definition: Img.h:1030
typedef Mat
untyped image class This class provides a fully dynamic image, where type and channels are not known ...
Definition: Img.h:932
Img< uint8, 2 > Img8U2
Image: unsigned 8-bit integers, 2 channels.
Definition: Img.h:1095
Img< uint16, 2 > Img16U2
Image: unsigned 16-bit integers, 2 channel.
Definition: Img.h:1119
int channels
Definition: Img.h:104
Img< int16, 4 > Img16S4
Image: 16-bit integers, 4 channel.
Definition: Img.h:1155
iterator end()
Definition: Img.h:1036
const_iterator begin() const
Definition: Img.h:1043
Img(int width, int height)
constructs a new image of given size note: the image data is allocated but not initialized ...
Definition: Img.h:832
cv::Mat mData
Definition: Img.h:518
const TPixel & operator()(int x, int y) const
const access pixel(x,y)
Definition: Img.h:667
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:1203
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:1179
uint8 * data(int y)
Returns pointer to underlying image data starting at scanline y.
Definition: Img.h:387
T Pixel
Definition: Img.h:867