SMIL  0.9.1
DImage.hxx
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _IMAGE_HXX
31 #define _IMAGE_HXX
32 
33 #include <iostream>
34 #include <string>
35 #include <iomanip>
36 
37 #include "Core/include/DCoreEvents.h"
38 #include "Base/include/private/DMeasures.hpp"
39 #include "Base/include/private/DImageArith.hpp"
40 #include "IO/include/private/DImageIO.hxx"
41 #include "Gui/include/DGuiInstance.h"
42 
43 #ifdef SMIL_WRAP_RGB
44 #include "NSTypes/RGB/include/DRGB.h"
45 #endif // SMIL_WRAP_RGB
46 
47 #ifdef SMIL_WRAP_BIT
48 #include "NSTypes/Bit/include/DBit.h"
49 #endif // SMIL_WRAP_BIT
50 
51 namespace smil
52 {
53 
54  template <class T>
56  : BaseImage("Image")
57  {
58  init();
59  }
60 
61  template <class T>
62  Image<T>::Image(size_t w, size_t h, size_t d)
63  : BaseImage("Image")
64  {
65  init();
66  setSize(w, h, d);
67  }
68 
69  template <class T>
70  Image<T>::Image(const Image<T> &rhs, bool cloneData)
71  : BaseImage(rhs)
72  {
73  init();
74  if (cloneData)
75  this->clone(rhs);
76  else this->setSize(rhs);
77  }
78 
79  template <class T>
80  Image<T>::Image(const ResImage<T> &rhs, bool cloneData)
81  : BaseImage(rhs)
82  {
83  init();
84  if (cloneData)
85  this->clone(rhs);
86  else this->setSize(rhs);
87  }
88 
89  template <class T>
90  template <class T2>
91  Image<T>::Image(const Image<T2> &rhs, bool cloneData)
92  : BaseImage(rhs)
93  {
94  init();
95  if (cloneData)
96  this->clone(rhs);
97  else setSize(rhs);
98  }
99 
100  template <class T>
101  Image<T>::Image(BaseImage *_im, bool stealIdentity)
102  : BaseImage("Image")
103  {
104  init();
105 
106  if (_im==NULL)
107  return;
108 
109  Image *im = castBaseImage(_im, T());
110  if (im==NULL)
111  return;
112 
113  if (!stealIdentity)
114  {
115  setSize(*im);
116  return;
117  }
118  else
119  drain(im, true);
120  }
121 
122 
123  template <class T>
124  void Image<T>::drain(Image<T> *im, bool deleteSrc)
125  {
126  if (allocated)
127  deallocate();
128 
129  this->width = im->width;
130  this->height = im->height;
131  this->depth = im->depth;
132 
133  this->sliceCount = im->sliceCount;
134  this->lineCount = im->lineCount;
135  this->pixelCount = im->pixelCount;
136 
137  this->pixels = im->pixels;
138  this->slices = im->slices;
139  this->lines = im->lines;
140 
141  this->allocated = im->allocated;
142  this->allocatedSize = im->allocatedSize;
143 
144  this->name = im->name;
145  this->viewer = im->viewer;
146 
147  im->allocated = false;
148 
149  if (deleteSrc)
150  delete im;
151  }
152 
153 
154  template <class T>
155  void Image<T>::clone(const Image<T> &rhs)
156  {
157  bool isAlloc = rhs.isAllocated();
158  this->setSize(rhs, isAlloc);
159  if (isAlloc)
160  copyLine<T>(rhs.getPixels(), getPixelCount(), this->pixels);
161  modified();
162  }
163 
164  template <class T>
165  template <class T2>
166  void Image<T>::clone(const Image<T2> &rhs)
167  {
168  bool isAlloc = rhs.isAllocated();
169  this->setSize(rhs, isAlloc);
170  if (isAlloc)
171  copy(rhs, *this);
172  modified();
173  }
174 
175  template <class T>
176  Image<T>::Image(const char *fileName)
177  : BaseImage("Image")
178  {
179  triggerEvents = true;
180  init();
181  read(fileName, *this);
182  }
183 
184  template <class T>
186  {
187  if (viewer)
188  delete viewer;
189  viewer = NULL;
190 
191  this->deallocate();
192  }
193 
194 
195 
196  template <class T>
197  void Image<T>::init()
198  {
199  this->slices = NULL;
200  this->lines = NULL;
201  this->pixels = NULL;
202 
203  this->dataTypeSize = sizeof(pixelType);
204 
205  this->viewer = NULL;
206 
207  parentClass::init();
208  }
209 
210  template <class T>
211  RES_T Image<T>::load(const char *fileName)
212  {
213  return read(fileName, *this);
214  }
215 
216  template <class T>
217  RES_T Image<T>::save(const char *fileName)
218  {
219  return write(*this, fileName);
220  }
221 
222  template <class T>
224  {
225  if (!this->updatesEnabled)
226  return;
227 
228  BaseImageEvent event(this);
229  onModified.trigger(&event);
230  }
231 
232 
233 
234  template <class T>
235  void Image<T>::setName(const char *_name)
236  {
237  parentClass::setName(_name);
238 
239  if (viewer)
240  viewer->setName(_name);
241  }
242 
243  template <class T>
245  {
246  if (viewer)
247  return;
248 
249  viewer = Gui::getInstance()->createDefaultViewer<T>(*this);
250 
251  }
252 
253  template <class T>
255  {
256  createViewer();
257  return viewer;
258  }
259 
260  template <class T>
262  {
263  return (viewer && viewer->isVisible());
264  }
265 
266  template <class T>
268  {
269  if (viewer)
270  viewer->hide();
271  }
272 
273  template <class T>
274  void Image<T>::show(const char *_name, bool labelImage)
275  {
276  if (isVisible())
277  return;
278 
279  if (!this->allocated)
280  {
281  ERR_MSG("Image isn't allocated !");
282  return;
283  }
284 
286 
287  createViewer();
288 
289  if (_name)
290  setName(_name);
291 
292  if (!viewer)
293  return;
294 
295  if (!labelImage)
296  viewer->show();
297  else
298  viewer->showLabel();
299 
300  }
301 
302  template <class T>
303  void Image<T>::showLabel(const char *_name)
304  {
305  show(_name, true);
306  }
307 
308  template <class T>
309  void Image<T>::showNormal(const char *_name)
310  {
311  if (_name)
312  setName(_name);
313  if (isVisible())
314  viewer->show();
315  else show(_name, false);
316  }
317 
318  template <class T>
319  RES_T Image<T>::setSize(size_t w, size_t h, size_t d, bool doAllocate)
320  {
321  if (w==this->width && h==this->height && d==this->depth)
322  return RES_OK;
323 
324  if (this->allocated)
325  this->deallocate();
326 
327  this->width = w;
328  this->height = h;
329  this->depth = d;
330 
331  this->sliceCount = d;
332  this->lineCount = d * h;
333  this->pixelCount = this->lineCount * w;
334 
335  if (doAllocate)
336  ASSERT((this->allocate()==RES_OK));
337 
338  if (viewer)
339  viewer->setImage(*this);
340 
341  this->modified();
342 
343  return RES_OK;
344  }
345 
346  template <class T>
348  {
349  if (this->allocated)
350  return RES_ERR_BAD_ALLOCATION;
351 
352  this->pixels = createAlignedBuffer<T>(pixelCount);
353  // pixels = new pixelType[pixelCount];
354 
355  ASSERT((this->pixels!=NULL), "Can't allocate image", RES_ERR_BAD_ALLOCATION);
356 
357  this->allocated = true;
358  this->allocatedSize = this->pixelCount*sizeof(T);
359 
360  this->restruct();
361 
362  return RES_OK;
363  }
364 
365  template <class T>
366  RES_T Image<T>::restruct(void)
367  {
368  if (this->slices)
369  delete[] this->slices;
370  if (this->lines)
371  delete[] this->lines;
372 
373  this->lines = new lineType[lineCount];
374  this->slices = new sliceType[sliceCount];
375 
376  sliceType cur_line = this->lines;
377  volType cur_slice = this->slices;
378 
379  size_t pixelsPerSlice = this->width * this->height;
380 
381  for (size_t k=0; k<depth; k++, cur_slice++)
382  {
383  *cur_slice = cur_line;
384 
385  for (size_t j=0; j<height; j++, cur_line++)
386  *cur_line = pixels + k*pixelsPerSlice + j*width;
387  }
388 
389 
390  return RES_OK;
391  }
392 
393 
394  template <class T>
396  {
397  if (!this->allocated)
398  return RES_OK;
399 
400  if (this->slices)
401  delete[] this->slices;
402  if (this->lines)
403  delete[] this->lines;
404  if (this->pixels)
405  deleteAlignedBuffer<T>(pixels);
406 
407  this->slices = NULL;
408  this->lines = NULL;
409  this->pixels = NULL;
410 
411  this->allocated = false;
412  this->allocatedSize = 0;
413 
414  return RES_OK;
415  }
416 
417 #ifndef SWIGPYTHON
418  template <class T>
419  void Image<T>::toArray(T outArray[])
420  {
421  for (size_t i=0;i<pixelCount;i++)
422  outArray[i] = pixels[i];
423  }
424 
425  template <class T>
426  void Image<T>::fromArray(const T inArray[])
427  {
428  for (size_t i=0;i<pixelCount;i++)
429  pixels[i] = inArray[i];
430  modified();
431  }
432 
433  template <class T>
434  void Image<T>::toCharArray(signed char outArray[])
435  {
436  for (size_t i=0;i<pixelCount;i++)
437  outArray[i] = pixels[i];
438  }
439 
440  template <class T>
441  void Image<T>::fromCharArray(const signed char inArray[])
442  {
443  for (size_t i=0;i<pixelCount;i++)
444  pixels[i] = inArray[i];
445  modified();
446  }
447 
448  template <class T>
449  void Image<T>::toIntArray(int outArray[])
450  {
451  for (size_t i=0;i<pixelCount;i++)
452  outArray[i] = pixels[i];
453  }
454 
455  template <class T>
456  void Image<T>::fromIntArray(const int inArray[])
457  {
458  for (size_t i=0;i<pixelCount;i++)
459  pixels[i] = inArray[i];
460  modified();
461  }
462 #endif // SWIGPYTHON
463 
464  template <class T>
465  vector<int> Image<T>::toIntVector()
466  {
467  vector<int> vec;
468  for (size_t i=0;i<pixelCount;i++)
469  vec.push_back(pixels[i]);
470  return vec;
471  }
472 
473  template <class T>
474  void Image<T>::fromIntVector(vector<int> inVector)
475  {
476  ASSERT((inVector.size()==pixelCount), "Vector length doesn't match image size.", );
477  for (size_t i=0;i<min(pixelCount, inVector.size());i++)
478  pixels[i] = inVector[i];
479  modified();
480  }
481 
482  template <class T>
484  {
485  string buf;
486  for (size_t i=0;i<pixelCount;i++)
487  buf.push_back(pixels[i]);
488  return buf;
489  }
490 
491  template <class T>
492  void Image<T>::fromString(string pixVals)
493  {
494  ASSERT((pixVals.size()==pixelCount), "String length doesn't match image size.", );
495  for (size_t i=0;i<pixelCount;i++)
496  pixels[i] = pixVals[i];
497  modified();
498  }
499 
500  template <class T>
501  void Image<T>::printSelf(ostream &os, bool displayPixVals, bool hexaGrid, string indent) const
502  {
503  #if DEBUG_LEVEL > 1
504  cout << "Image::printSelf: " << this << endl;
505  #endif // DEBUG_LEVEL > 1
506  if (name!="")
507  os << indent << "Image name: " << name << endl;
508 
509  if (depth>1)
510  os << "3D image" << endl;
511  else
512  os << "2D image" << endl;
513 
514  T *dum = NULL;
515  os << "Data type: " << getDataTypeAsString<T>(dum) << endl;
516 
517  if (depth>1)
518  os << "Size: " << width << "x" << height << "x" << depth << endl;
519  else
520  os << "Size: " << width << "x" << height << endl;
521 
522  if (allocated) os << "Allocated (" << displayBytes(allocatedSize) << ")" << endl;
523  else os << "Not allocated" << endl;
524 
525 
526  if (displayPixVals)
527  {
528  std::stringstream tStr;
529  tStr << (long)ImDtTypes<T>::max();
530  size_t tSsize = tStr.str().size();
531  if (hexaGrid)
532  tSsize = size_t(tSsize * 1.5);
533 
534 
535  os << "Pixel values:" << endl;
536  size_t i, j, k;
537 
538  for (k=0;k<depth;k++)
539  {
540  for (j=0;j<height;j++)
541  {
542  if (hexaGrid && j%2)
543  os << setw(tSsize/2+1) << " ";
544  for (i=0;i<width;i++)
545  os << setw(tSsize+1) << ImDtTypes<T>::toString(getPixel(i,j,k)) << ",";
546  os << endl;
547  }
548  os << endl;
549  }
550  os << endl;
551  }
552 
553  os << endl;
554  }
555 
556 
557  template <class T>
558  SharedImage<T> Image<T>::getSlice(size_t sliceNum) const
559  {
560  if (sliceNum>=this->depth)
561  {
562  ERR_MSG("sliceNum > image depth");
563  return SharedImage<T>();
564  }
565  return SharedImage<T>(*this->getSlices()[sliceNum], this->width, this->height, 1);
566  }
567 
568  // OPERATORS
569 
570  template <class T>
571  void operator << (ostream &os, const Image<T> &im)
572  {
573  im.printSelf(os);
574  }
575 
576  template <class T>
577  Image<T>& Image<T>::operator << (const char *s)
578  {
579  read(s, *this);
580  return *this;
581  }
582 
583  template <class T>
584  Image<T>& Image<T>::operator >> (const char *s)
585  {
586  write(*this, s);
587  return *this;
588  }
589 
590  template <class T>
592  {
593  copy(rhs, *this);
594  return *this;
595  }
596 
597  template <class T>
599  {
600  fill(*this, value);
601  return *this;
602  }
603 
604  template <class T>
606  {
607  ResImage<T>im(*this);
608  inv(*this, im);
609  return im;
610  }
611 
612  template <class T>
614  {
615  ResImage<T>im(*this);
616  inv(*this, im);
617  return im;
618  }
619 
620  template <class T>
622  {
623  ResImage<T> im(*this);
624  add(*this, rhs, im);
625  return im;
626  }
627 
628  template <class T>
630  {
631  ResImage<T> im(*this);
632  add(*this, value, im);
633  return im;
634  }
635 
636  template <class T>
638  {
639  add(*this, rhs, *this);
640  return *this;
641  }
642 
643  template <class T>
645  {
646  add(*this, value, *this);
647  return *this;
648  }
649 
650  template <class T>
652  {
653  ResImage<T>im(*this);
654  sub(*this, rhs, im);
655  return im;
656  }
657 
658  template <class T>
660  {
661  ResImage<T>im(*this);
662  sub(*this, value, im);
663  return im;
664  }
665 
666  template <class T>
668  {
669  sub(*this, rhs, *this);
670  return *this;
671  }
672 
673  template <class T>
675  {
676  sub(*this, value, *this);
677  return *this;
678  }
679 
680  template <class T>
682  {
683  ResImage<T>im(*this);
684  mul(*this, rhs, im);
685  return im;
686  }
687 
688  template <class T>
690  {
691  ResImage<T>im(*this);
692  mul(*this, value, im);
693  return im;
694  }
695 
696  template <class T>
698  {
699  mul(*this, rhs, *this);
700  return *this;
701  }
702 
703  template <class T>
705  {
706  mul(*this, value, *this);
707  return *this;
708  }
709 
710  template <class T>
712  {
713  ResImage<T>im(*this);
714  div(*this, rhs, im);
715  return im;
716  }
717 
718  template <class T>
720  {
721  ResImage<T>im(*this);
722  div(*this, value, im);
723  return im;
724  }
725 
726  template <class T>
728  {
729  div(*this, rhs, *this);
730  return *this;
731  }
732 
733  template <class T>
735  {
736  div(*this, value, *this);
737  return *this;
738  }
739 
740  template <class T>
742  {
743  ResImage<T>im(*this);
744  equ(*this, rhs, im);
745  return im;
746  }
747 
748  template <class T>
750  {
751  ResImage<T>im(*this);
752  diff(*this, rhs, im);
753  return im;
754  }
755 
756  template <class T>
758  {
759  ResImage<T>im(*this);
760  low(*this, rhs, im);
761  return im;
762  }
763 
764  template <class T>
766  {
767  ResImage<T>im(*this);
768  low(*this, value, im);
769  return im;
770  }
771 
772  template <class T>
774  {
775  ResImage<T>im(*this);
776  lowOrEqu(*this, rhs, im);
777  return im;
778  }
779 
780  template <class T>
782  {
783  ResImage<T>im(*this);
784  lowOrEqu(*this, value, im);
785  return im;
786  }
787 
788  template <class T>
790  {
791  ResImage<T>im(*this);
792  grt(*this, rhs, im);
793  return im;
794  }
795 
796  template <class T>
798  {
799  ResImage<T>im(*this);
800  grt(*this, value, im);
801  return im;
802  }
803 
804  template <class T>
806  {
807  ResImage<T>im(*this);
808  grtOrEqu(*this, rhs, im);
809  return im;
810  }
811 
812  template <class T>
814  {
815  ResImage<T>im(*this);
816  grtOrEqu(*this, value, im);
817  return im;
818  }
819 
820  template <class T>
822  {
823  ResImage<T>im(*this);
824  sup(*this, rhs, im);
825  return im;
826  }
827 
828  template <class T>
829  ResImage<T>Image<T>::operator | (const T &value)
830  {
831  ResImage<T>im(*this);
832  sup(*this, value, im);
833  return im;
834  }
835 
836  template <class T>
838  {
839  sup(*this, rhs, *this);
840  return *this;
841  }
842 
843  template <class T>
844  Image<T>& Image<T>::operator |= (const T &value)
845  {
846  sup(*this, value, *this);
847  return *this;
848  }
849 
850  template <class T>
852  {
853  ResImage<T>im(*this);
854  inf(*this, rhs, im);
855  return im;
856  }
857 
858  template <class T>
859  ResImage<T>Image<T>::operator & (const T &value)
860  {
861  ResImage<T>im(*this);
862  inf(*this, value, im);
863  return im;
864  }
865 
866  template <class T>
868  {
869  inf(*this, rhs, *this);
870  return *this;
871  }
872 
873  template <class T>
874  Image<T>& Image<T>::operator &= (const T &value)
875  {
876  inf(*this, value, *this);
877  return *this;
878  }
879 
880  template <class T>
882  {
883  return vol(*this)==ImDtTypes<T>::max()*pixelCount;
884  }
885 
886  template <class T>
887  Image<T>& Image<T>::operator << (const lineType &tab)
888  {
889  for (size_t i=0;i<pixelCount;i++)
890  pixels[i] = tab[i];
891  modified();
892  return *this;
893  }
894 
895  template <class T>
897  {
898  typename vector<T>::iterator it = vect.begin();
899  typename vector<T>::iterator it_end = vect.end();
900 
901  for (size_t i=0;i<pixelCount;i++, it++)
902  {
903  if (it==it_end)
904  break;
905  pixels[i] = *it;
906  }
907  modified();
908  return *this;
909  }
910 
911  template <class T>
913  {
914  vect.clear();
915  for (size_t i=0;i<pixelCount;i++)
916  {
917  vect.push_back(pixels[i]);
918  }
919  return *this;
920  }
921 
922  typedef Image<UINT8> Image_UINT8;
923  typedef Image<UINT16> Image_UINT16;
924  typedef Image<UINT32> Image_UINT32;
925  typedef Image<bool> Image_bool;
926 
927 
928 } // namespace smil
929 
930 #if defined SWIGPYTHON && defined USE_NUMPY && defined(SWIG_WRAP_CORE)
931 #include "Core/include/DNumpy.h"
932 
933 namespace smil {
934 
935  template <class T>
936  PyObject * Image<T>::getNumArray(bool c_contigous)
937  {
938  npy_intp d[3];
939  int dim = this->getDimension();
940  if (dim==3)
941  {
942  d[0] = this->getDepth();
943  d[1] = this->getHeight();
944  d[2] = this->getWidth();
945  }
946  else
947  {
948  d[0] = this->getHeight();
949  d[1] = this->getWidth();
950  }
951  PyObject *array = PyArray_SimpleNewFromData(dim, d, getNumpyType(*this), this->getPixels());
952 
953  if (c_contigous)
954  {
955  return array;
956  }
957  else
958  {
959  npy_intp t2[] = { 1, 0 };
960  npy_intp t3[] = { 2, 1, 0 };
961  PyArray_Dims trans_dims;
962  if (dim==3)
963  trans_dims.ptr = t3;
964  else
965  trans_dims.ptr = t2;
966  trans_dims.len = dim;
967 
968  PyObject *res = PyArray_Transpose((PyArrayObject*) array, &trans_dims);
969  Py_DECREF(array);
970  return res;
971  }
972  }
973 
974  template <class T>
975  void Image<T>::fromNumArray(PyObject *obj)
976  {
977  PyArrayObject *arr = NULL;
978  PyArray_Descr *descr = NULL;
979 
980  if (PyArray_GetArrayParamsFromObject(obj, NULL, 1, &descr, NULL, NULL, &arr, NULL) != 0)
981  {
982  ERR_MSG("Input must be a NumPy array");
983  return;
984  }
985  descr = PyArray_DESCR(arr);
986  if (descr && descr->type_num!=getNumpyType(*this))
987  {
988  ERR_MSG("Wrong input NumPy array data type");
989  return;
990  }
991  npy_intp *dims = PyArray_DIMS(arr);
992  setSize(dims[0], dims[1], dims[2]);
993  T *data = (T*)PyArray_DATA(arr);
994  if (data)
995  {
996  for (size_t i=0;i<pixelCount;i++)
997  pixels[i] = data[i];
998  }
999  modified();
1000  }
1001 
1002 } // namespace smil
1003 
1004 
1005 #endif // defined SWIGPYTHON && defined USE_NUMPY
1006 
1007 #endif // _IMAGE_HXX
void toArray(T outArray[])
Copy pixel values to a given array.
ResImage< T > operator>=(const Image< T > &rhs)
Greater or equal boolean operator (see grt())
Definition: DImage.hxx:805
virtual bool isVisible()
Check if the image is visible.
Definition: DImage.hxx:261
virtual RES_T deallocate()
Deallocate image.
Definition: DImage.hxx:395
ResImage< T > operator<=(const Image< T > &rhs)
Lower or equal boolean operator (see lowOrEqu())
Definition: DImage.hxx:773
Definition: DColorConvert.h:38
void fromString(string pixVals)
Import pixel values from string.
Definition: DImage.hxx:492
RES_T sub(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Subtraction.
Definition: DImageArith.hpp:446
RES_T grt(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Greater operator.
Definition: DImageArith.hpp:650
RES_T copy(const Image< T1 > &imIn, size_t startX, size_t startY, size_t startZ, size_t sizeX, size_t sizeY, size_t sizeZ, Image< T2 > &imOut, size_t outStartX=0, size_t outStartY=0, size_t outStartZ=0)
Copy image.
Definition: DImageArith.hpp:114
double vol(const Image< T > &imIn)
Volume of an image.
Definition: DMeasures.hpp:96
RES_T equ(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Equality operator.
Definition: DImageArith.hpp:572
Definition: DImage.hpp:50
ResImage< T > operator<(const Image< T > &rhs)
Lower boolean operator (see low())
Definition: DImage.hxx:757
void toIntArray(int outArray[])
Copy pixel values to a given int array.
ResImage< T > operator>(const Image< T > &rhs)
Greater boolean operator (see grt())
Definition: DImage.hxx:789
void fromIntArray(const int inArray[])
Copy pixel values from a given int array.
lineType getPixels() const
Get the pixels as a 1D array.
Definition: DImage.hpp:110
RES_T inv(const Image< T > &imIn, Image< T > &imOut)
Invert an image.
Definition: DImageArith.hpp:375
SharedImage< T > getSlice(size_t sliceNum) const
Get a 2D slice of a 3D image. It doesn&#39;t create an image, but returns a 2D SharedImage using the same...
Definition: DImage.hxx:558
Image< T > & operator>>(vector< T > &vect)
Export image data to a vector.
Definition: DImage.hxx:912
virtual RES_T setSize(size_t w, size_t h, size_t d=1, bool doAllocate=true)
Set the size of image.
Definition: DImage.hxx:319
void fromIntVector(const vector< int > inVector)
Copy pixel values from a given int vector.
Definition: DImage.hxx:474
string toString()
Export pixel values to a string.
Definition: DImage.hxx:483
void printSelf(ostream &os, bool displayPixVals, bool hexaGrid=false, string indent="") const
Print a description of the image.
Definition: DImage.hxx:501
T getPixel(size_t x, size_t y, size_t z=0) const
Return the value of the pixel at pos x,y(,z)
Definition: DImage.hpp:127
void fromCharArray(const signed char inArray[])
Copy pixel values from a given char array.
RES_T fill(Image< T > &imOut, const T &value)
Fill an image with a given value.
Definition: DImageArith.hpp:62
virtual RES_T allocate()
Allocate image.
Definition: DImage.hxx:347
RES_T sup(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Sup of two images.
Definition: DImageArith.hpp:505
bool isAllocated() const
Check if the image is allocated.
Definition: DBaseImage.h:163
RES_T add(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Addition.
Definition: DImageArith.hpp:393
void fromArray(const T inArray[])
Copy pixel values from a given array.
vector< int > toIntVector()
Copy pixel values to a given int vector.
Definition: DImage.hxx:465
ResImage< T > operator~() const
Negate image.
Definition: DImage.hxx:605
virtual void hide()
Hide image.
Definition: DImage.hxx:267
Image that uses an existing (1D) data pointer.
Definition: DImage.hpp:53
ResImage< T > operator==(const Image< T > &rhs)
Equal boolean operator (see equ()).
Definition: DImage.hxx:741
size_t getHeight() const
Get image height.
Definition: DBaseImage.h:91
virtual void show(const char *=NULL, bool=false)
Show the image (viewer)
Definition: DBaseImage.cpp:56
RES_T low(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Lower operator.
Definition: DImageArith.hpp:692
virtual void modified()
Trigger modified event (allows to force display update)
Definition: DImage.hxx:223
ResImage< T > operator/(const Image< T > &rhs)
Divide by image.
Definition: DImage.hxx:711
ResImage< T > operator+(const Image< T > &rhs)
Add image.
Definition: DImage.hxx:621
virtual void setName(const char *_name)
Set the name of the image.
Definition: DImage.hxx:235
void drain(Image< T > *im, bool deleteSrc=false)
Replace container. Drain memory from image im to this.
Definition: DImage.hxx:124
Base image viewer.
Definition: DBaseImage.h:45
ResImage< T > operator!=(const Image< T > &rhs)
Diff boolean operator (see equ()).
Definition: DImage.hxx:749
virtual RES_T save(const char *fileName)
Save to file.
Definition: DImage.hxx:217
size_t getWidth() const
Get image width.
Definition: DBaseImage.h:87
RES_T lowOrEqu(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Lower or equal operator.
Definition: DImageArith.hpp:713
RES_T grtOrEqu(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Greater or equal operator.
Definition: DImageArith.hpp:671
size_t getPixelCount() const
Get the number of pixels.
Definition: DBaseImage.h:150
Base Image class.
Definition: DBaseImage.h:50
Image()
Default constructor.
Definition: DImage.hxx:55
virtual void show(const char *_name=NULL, bool labelImage=false)
Show the default viewer associated with the image.
Definition: DImage.hxx:274
Definition: DCoreEvents.h:42
Definition: DTypes.hpp:78
Main Image class.
Definition: DQVtkViewer.hpp:44
virtual RES_T load(const char *fileName)
Load from file.
Definition: DImage.hxx:211
RES_T inf(const Image< T > &imIn1, const T &value, Image< T > &imOut)
Inf of two images.
Definition: DImageArith.hpp:538
RES_T mul(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Multiply.
Definition: DImageArith.hpp:770
ResImage< T > operator*(const Image< T > &rhs)
Multiply by image.
Definition: DImage.hxx:681
Image< T > & operator*=(const Image< T > &rhs)
Image multiplication assignment.
Definition: DImage.hxx:697
UINT getDimension() const
Get dimension (2D or 3D)
Definition: DBaseImage.h:105
virtual ImageViewer< T > * getViewer()
Get the image viewer (create one if needed)
Definition: DImage.hxx:254
volType getSlices() const
Get an array containing the start offset of each slice.
Definition: DImage.hpp:118
size_t getDepth() const
Get image depth (Z)
Definition: DBaseImage.h:95
Image< T > & operator-=(const Image< T > &rhs)
Image subtraction assignment.
Definition: DImage.hxx:667
Image< T > & operator+=(const Image< T > &rhs)
Image addition assignment.
Definition: DImage.hxx:637
RES_T read(const char *filename, Image< T > &image)
Read image file.
Definition: DImageIO.hxx:112
RES_T diff(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Difference between two images.
Definition: DImageArith.hpp:615
virtual void clone(const Image< T > &rhs)
Clone from a given image (set same size and copy content)
Definition: DImage.hxx:155
RES_T div(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Division.
Definition: DImageArith.hpp:734
Image< T > & operator<<(const Image< T > &rhs)
Copy image.
Definition: DImage.hxx:591
Image< T > & operator/=(const Image< T > &rhs)
Image division assignment.
Definition: DImage.hxx:727
RES_T write(const Image< T > &image, const char *filename)
Write image file.
Definition: DImageIO.hxx:192
virtual void showLabel(const char *_name=NULL)
Show the default viewer associated with the image using a color lookup table.
Definition: DImage.hxx:303