Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageBase.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 #include "ImageBase.hh"
22 #include <Base/Common/W32Compat.hh>
23 #include "Image.hh" // required for static_casting
24 
25 
26 #ifdef WIN32
27 # define _USE_MATH_DEFINES
28 #endif //WIN32
29 
30 #include <math.h>
31 #include <string>
32 #include <sstream>
33 #include <algorithm>
34 
35 using std::string;
36 using std::stringstream;
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 
43 {
44  if (ImageDataArray_ != NULL) {
45  delete[] (char**)ImageDataArray_;
46  ImageDataArray_ = NULL;
47  }
48  if (ImageData_!=NULL && shouldReleaseData_){
49  delete[] (char*)ImageData_;
50  }
51  ImageData_ = NULL;
52 }
53 
54 
55 
57  : Debug(), Roi_(), shouldReleaseData_(true)
58 {
59 #ifdef BIAS_DEBUG
60  BIASGDOUT(D_IMAGE_TRACE, "called ImageBase::ImageBase()");
61 #endif
62  ImageData_ = NULL;
63  ImageDataArray_ = NULL;
64  ChannelCount_ = 0;
65  Width_ = 0;
66  Height_ =0;
67  Depth_ = 0;
68  BitDepth_ = 0;
69  WidthStep_ = 0;
72  InterleavedDataOrder_ = true;
73  _UID=BIAS::UUID();
75 }
76 
77 ImageBase::ImageBase(const ImageBase& im) : shouldReleaseData_(true)
78 {
79 #ifdef BIAS_DEBUG
80  BIASGDOUT(D_IMAGE_TRACE, "called ImageBase::ImageBase(const ImageBase& im)");
81 #endif
82  ImageData_ = NULL;
83  ImageDataArray_ = NULL;
84  Width_ = 0;
85  Height_ = 0;
86  ChannelCount_ = 0;
88  // StorageType_ = im.StorageType_; //otherwise the =operator will fail.
89  (*this) = im;
90 }
91 
92 
93 ImageBase::ImageBase(unsigned int width, unsigned int height,
94  unsigned int channels, enum EStorageType storageType,
95  bool interleaved) : shouldReleaseData_(true)
96 {
97 #ifdef BIAS_DEBUG
98  BIASGDOUT(D_IMAGE_TRACE, "called ImageBase::ImageBase(width, height,"
99  <<" channels, storageType, interleaved ");
100 #endif
101 
102  ImageData_ = NULL;
103  ImageDataArray_ = NULL;
104 
106  InterleavedDataOrder_ = interleaved;
107 
108  Init(width,height,channels,storageType);
109 
110  Roi_.Resize(width, height);
111  Roi_.UnsetROI();
112 }
113 
114 
115 int ImageBase::GetStorageSizeByte(const unsigned int & width, const unsigned int & height,
116  const unsigned int nChannels,
117  const enum EStorageType storageType
118  /* ,const EColorModel colormodel*/
119  )
120 {
121  const int nPixel = width * height;
122  const int nBytePerPixel = nChannels * GetSizeByte(storageType);
123  // the nr. of Byte does not depend on colormodel, currently
124  // as the number of channels is set according to nr. of Byte,
125  // not number of values (jw, bartczak 11/2007)
126  return nPixel * nBytePerPixel;
127 }
128 
129 
130 
131 void ImageBase::ReInit(const unsigned int & width, const unsigned int & height,
132  const unsigned int nChannels,
133  const enum EStorageType storageType,
134  const bool interleaved,
135  const EColorModel colormodel)
136 {
137  const int current_nBytes = GetStorageSizeByte(width, height,
138  nChannels, storageType /* ,colormodel */);
139  const int required_nBytes = GetStorageSizeByte(GetWidth(), GetHeight(),
140  GetChannelCount(), GetStorageType() /* ,GetColorModel() */);
141  if (current_nBytes != required_nBytes){
142  // need allocation
143  if (!IsEmpty())
144  Release();
145  Init(width, height, nChannels, storageType, IsInterleaved() );
146  } else {
147  // no allocation, keep existing data area
148  // take over descripive tags for data area
149  SetStorageType(storageType);
150  SetInterleaved(interleaved);
151  SetColorModel(colormodel);
152  }
153 }
154 
155 void ImageBase::InitWithForeignData(unsigned int Width, unsigned int Height,
156  unsigned int nChannels,
157  void* data,
158  enum EStorageType storageType,
159  bool interleaved,
160  const bool shouldRelease) {
161 // if ((ImageData_!=NULL) || (ImageDataArray_ !=NULL)){
162 // BIASERR("Image<StorageType>::Init should only be called once"<<
163 // "\nuse Release if you want to reinit");
164 // }
165 
166  if (!IsEmpty()) { Release(); }
167 
168  //BIASASSERT(ImageData_==NULL);
169  //BIASASSERT(ImageDataArray_==NULL);
170 
171 #ifdef DISABLE_MODULO_4_SIZE
172  if (((sizeof(StorageType)*Width) % 4) != 0){
173  BIASERR("Because IplImage always uses aligned image data\n"
174  << " Image only supports images with \n"
175  << " (width * sizeof(StorageType)) modulo 4 = 0.\n"
176  << " Please choose a width which is divisible by four\n"
177  << " if multiplied with sizeof(StorageType) or use either\n"
178  << " the CopyIn function (internal only) or\n"
179  << " the ImportImage function.\n");
180  return; // error
181  };
182 
183 # if USE_OPENCV == true
184  BIASERR("you cannot use -DDISABLE_MODULO_4_SIZE and -DUSE_OPENCV together");
185 # endif // USE_OPENCV == true
186 #endif // DISABLE_MODULO_4_SIZE
187 
188  Width_ = Width;
189  Height_ = Height;
190  ChannelCount_ = nChannels;
191  StorageType_ = storageType;
192  Roi_.Resize(Width, Height);
193  Roi_.UnsetROI();
194  Depth_ = GetSizeByte( this->GetStorageType() );
195  BitDepth_=8*Depth_; // default, might be smaller, e.g. save 12 bit image in 16 bit ushort
196  InterleavedDataOrder_ = interleaved;
197 
198  if (shouldReleaseData_)
199  delete[] (char**)ImageData_;
200  ImageData_ = data;
201  shouldReleaseData_ = shouldRelease;
202 
203  switch (nChannels){
204  case 4:
206  break;
207  case 3:
209  break;
210  case 2:
212  break;
213  case 1:
215  break;
216  default:
218  break;
219  };
220 
223  else
225 
227 }
228 
229 void ImageBase::Init(unsigned int Width, unsigned int Height,
230  unsigned int nChannels, enum EStorageType storageType,
231  bool interleaved)
232 {
233 // if ((ImageData_!=NULL) || (ImageDataArray_ !=NULL)){
234 // BIASERR("Image<StorageType>::Init should only be called once"<<
235 // "\nuse Release if you want to reinit");
236 // }
237 
238  if (!IsEmpty()) { Release(); }
239 
240  //BIASASSERT(ImageData_==NULL);
241  //BIASASSERT(ImageDataArray_==NULL);
242 
243 #ifdef DISABLE_MODULO_4_SIZE
244  if (((sizeof(StorageType)*Width) % 4) != 0){
245  BIASERR("Because IplImage always uses aligned image data\n"
246  << " Image only supports images with \n"
247  << " (width * sizeof(StorageType)) modulo 4 = 0.\n"
248  << " Please choose a width which is divisible by four\n"
249  << " if multiplied with sizeof(StorageType) or use either\n"
250  << " the CopyIn function (internal only) or\n"
251  << " the ImportImage function.\n");
252  return; // error
253  };
254 
255 # if USE_OPENCV == true
256  BIASERR("you cannot use -DDISABLE_MODULO_4_SIZE and -DUSE_OPENCV together");
257 # endif // USE_OPENCV == true
258 #endif // DISABLE_MODULO_4_SIZE
259 
260  Width_ = Width;
261  Height_ = Height;
262  ChannelCount_ = nChannels;
263  StorageType_ = storageType;
264  Roi_.Resize(Width, Height);
265  Roi_.UnsetROI();
266  Depth_ = GetSizeByte( this->GetStorageType() );
267  BitDepth_=8*Depth_; // default, might be smaller, e.g. save 12 bit image in 16 bit ushort
268  InterleavedDataOrder_ = interleaved;
269 
270  if (shouldReleaseData_)
271  delete[] (char**)ImageData_;
272  ImageData_ = (void*) new char[ GetSizeByte() ];
273  shouldReleaseData_ = true;
274 
275  switch (nChannels){
276  case 4:
278  break;
279  case 3:
281  break;
282  case 2:
284  break;
285  case 1:
287  break;
288  default:
290  break;
291  };
292 
295  else
297 
299 }
300 
301 
303 {
304  // catch the IsEmpty NULL data case: JW
305  if (IsEmpty() || GetPixelCount()==0)
306  {
307  if (ImageDataArray_ != NULL) {
308  delete[] ImageDataArray_;
309  ImageDataArray_ = NULL;
310  }
311  // nothing to point to because no data pixels available
312  return 0;
313  }
314 
315  // we have ImageData
316  BIASASSERT( !IsEmpty() );
317  BIASASSERT( GetPixelCount()>0 );
318  BIASASSERT( GetWidth()>0 );
319  BIASASSERT( GetHeight()>0 );
320  BIASASSERT( GetChannelCount()>0 );
321 
322  const unsigned height=(IsPlanar())?
323  (GetHeight()*GetChannelCount()) : (GetHeight());
324  if (ImageDataArray_ != NULL) {
325  delete[] ImageDataArray_;
326  ImageDataArray_=NULL;
327  }
328  ImageDataArray_ = (void**) new char*[height];
330 #ifdef BIAS_DEBUG
331  unsigned int tmpstep;
333  tmpstep = Width_ * Depth_ * ChannelCount_;
334  else
335  tmpstep = Width_ * Depth_;
336  if ( tmpstep!=WidthStep_) {
337  BIASERR("Congratulations! You found a major bug in BIAS."
338  <<" Inconsistency in image dimension data.");
339  BIASABORT;
340  }
341 #endif
342  for (register unsigned int i=1; i < height; i++) {
343  ImageDataArray_[i] = (void*)((char*)(ImageDataArray_[i-1]) +
344  WidthStep_);
345  };
346  return 0;
347 }
348 
349 
350 void ImageBase::Release(const bool reset_storage_type)
351 {
352  //cout << "ImageBase::Release()" << endl;
353 #ifdef BIAS_DEBUG
354  if (IsEmpty()) {
355  BIASERR("ImageBase::Release called with empty image !");
356  }
357 #endif
358  // check if we really need to delete the mem
359  if (ImageDataArray_!=NULL) {
360  delete[] (char**)ImageDataArray_;
361  ImageDataArray_ = NULL;
362  }
363  if (ImageData_!=NULL) {
364  if (shouldReleaseData_)
365  delete[] (char*)ImageData_;
366  ImageData_=NULL;
367  }
368  ChannelCount_ = 0;
369  Width_ = Height_ = Depth_ = 0;
370  WidthStep_ = 0;
372  if (reset_storage_type){
373  //cout << "ImageBase::Release() has to reset storage type" << endl;
374  // ImageBase::Release() is also implicitly called for templated images
375  // when releasing the storage type here, it becomes possible to assign
376  // a float image to an unsigned char image via ImageBase
377  // use
378  // Image<float> f;
379  // Image<unsigned char> uc;
380  // f.Release();
381  // // also happens when calling a function which expects an ImageBase
382  // // with and Image<StorageType> implicitly
383  // ImageBase *ibf= dynamic_cast<ImageBase *>(f);
384 
385  // (*ibf) = uc;
386  BitDepth_ = 0;
388  }
389 
390  Roi_.Release();
391 
392  _MetaData.clear();
393 }
394 
396  if (source.IsEmpty()) {
397  BIASERR("tried to steal empty image");
398  return -1;
399  }
400  if (!IsEmpty())
401  Release();
402  ImageData_ = source.GetImageData();
404  ChannelCount_ = source.GetChannelCount();
405  ColorModel_ = source.GetColorModel();
406  StorageType_ = source.GetStorageType();
408 
409  Width_ = source.GetWidth();
410  Height_ = source.GetHeight();
411  Depth_ = source.GetDepth();
412  BitDepth_ = source.GetBitDepth();
413  WidthStep_ = source.GetWidthStep();
414 
415  Roi_ = *source.GetROI();
416 
417  source.ImageData_=NULL;
418  source.ImageDataArray_=NULL;
419  // copy(_MetaData.begin(), _MetaData.end(), source._MetaData.begin());
420  _MetaData.resize(source._MetaData.size());
421  copy(source._MetaData.begin(), source._MetaData.end(), _MetaData.begin());
422 
423  source._MetaData.clear();
424 
425  return 0;
426 }
427 
428 int ImageBase::GetChannel(const ImageBase &source, const unsigned int channel)
429 {
430  if (IsEmpty())
431  Init(source.GetWidth(), source.GetHeight(), 1,source.GetStorageType());
432 
433 #ifdef BIAS_DEBUG
434  if ( (source.GetHeight() != GetHeight()) ||
435  ( (source.GetWidth() != GetWidth()) &&
436  (source.GetWidth() != GetWidth()/2) ) )
437  BIASERR("ImageConvert<StorageType>::GetChannel() invalid size of image");
438  if ( GetChannelCount() != 1 )
439  BIASERR("ImageConvert<StorageType>::GetChannel() should be called with one"
440  <<" channel image");
441  if ( source.GetChannelCount() == 1 )
442  BIASERR("ImageConvert<StorageType>::GetChannel() only makes sense with"
443  <<" color images");
444 #endif
445 
446  if (source.GetColorModel()==CM_YUYV422){
447  switch (channel){
448  case 0:
449  memcpy(GetImageData(), source.GetImageData(),
450  source.GetPixelCount() * source.GetDepth());
451  break;
452  case 1:
453  memcpy(GetImageData(), (char*)(source.GetImageData()) +
454  source.GetPixelCount()*source.GetDepth(),
455  source.GetPixelCount() * source.GetDepth() / 2);
456  break;
457  case 2:
458  memcpy(GetImageData(),
459  (char*)(source.GetImageData()) + source.GetDepth()*
460  (source.GetPixelCount() + source.GetPixelCount()/2),
461  source.GetPixelCount() * source.GetDepth() / 2);
462  break;
463  default:
464  BIASERR("ImageConvert<StorageType>::GetChannel() invalid Channel");
465  return -1;
466  break;
467  }
468  } else { // if
469  if (source.IsPlanar()){
470  switch (channel){
471  case 0:
472  memcpy(GetImageData(), source.GetImageData(),
473  source.GetPixelCount() * source.GetDepth());
474  break;
475  case 1:
476  memcpy(GetImageData(),
477  (char*)(source.GetImageData()) +
478  source.GetPixelCount()*source.GetDepth(),
479  source.GetPixelCount() * source.GetDepth());
480  break;
481  case 2:
482  memcpy(GetImageData(),
483  (char*)(source.GetImageData()) + 2 * source.GetPixelCount()*
484  source.GetDepth(),
485  source.GetPixelCount() * source.GetDepth());
486  break;
487  default:
488  BIASERR("ImageConvert<StorageType>::GetChannel() invalid Channel");
489  return -1;
490  break;
491  }
492  } else { // interleaved
493 #ifdef BIAS_DEBUG
494  if ((channel<0) || (channel>2)){
495  BIASERR("ImageConvert<StorageType>::GetChannel() invalid Channel");
496  BIASBREAK;
497  return -1;
498  }
499 #endif
500  char *src=(char *)source.GetImageData();
501  char *dst=(char *)GetImageData();
502  char *end=dst+GetPixelCount()*GetDepth();
503  register int depth=GetDepth();
504  register int depth2=depth<<1;
505  switch (channel){
506  case 0:
507  while (dst<end){
508  for (int i=0; i<depth; i++) *dst++=*src++;
509  src+=depth2;
510  }
511  break;
512  case 1:
513  while (dst<end){
514  src+=depth;
515  for (int i=0; i<depth; i++) *dst++=*src++;
516  src+=depth;
517  }
518  break;
519  case 2:
520  while (dst<end){
521  src+=depth2;
522  for (int i=0; i<depth; i++) *dst++=*src++;
523  }
524  break;
525  default: break;
526  }
527  } // end if IsPlanar()
528 
529  } // end if
530 
531  return 0;
532 }
533 
534 
536 {
537 #ifdef BIAS_DEBUG
538  if (IsPlanar() && GetChannelCount()>1) {
539  BIASERR("only implemented for interleaved images...");
540  BIASABORT;
541  }
542 #endif
543  char **dst, **src;
544  register int y;
545  int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
546  GetROI()->GetCorners(ROIUpperLeftX, ROIUpperLeftY,
547  ROILowerRightX, ROILowerRightY);
548  if (!copy.IsEmpty()) copy.Release();
549  copy.Init(ROILowerRightX - ROIUpperLeftX + 1,
550  ROILowerRightY - ROIUpperLeftY + 1, GetChannelCount(),
551  GetStorageType());
553 
554  // following line must be changed if methods is extendend
555  src = (char**)GetImageDataArray();
556  dst = (char**)copy.GetImageDataArray();
557 
558  int length = (ROILowerRightX-ROIUpperLeftX + 1)
559  * GetChannelCount() * GetDepth();
560  for (y = ROIUpperLeftY; y <= ROILowerRightY; y++){
561  memcpy(&(dst[y-ROIUpperLeftY][0]),
562  &(src[y][ROIUpperLeftX*GetChannelCount()*GetDepth()]), length);
563  }
564  return 0;
565 
566 }
567 
569 {
570 #ifdef BIAS_DEBUG
571  if (IsPlanar() && GetChannelCount()>1) {
572  BIASERR("only implemented for interleaved images...");
573  BIASABORT;
574  }
575 #endif
576  char **dst, **src;
577  register int y;
578  int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
579  GetROI()->GetCorners(ROIUpperLeftX, ROIUpperLeftY,
580  ROILowerRightX, ROILowerRightY);
581 
582  if (!copy.IsEmpty()) copy.Release();
583  copy.Init(ROILowerRightX - ROIUpperLeftX,
584  ROILowerRightY - ROIUpperLeftY, GetChannelCount(),
585  GetStorageType());
587 
588  // following line must be changed if methods is extendend
589  src = (char**)GetImageDataArray();
590  dst = (char**)copy.GetImageDataArray();
591 
592  const int length =
593  (ROILowerRightX-ROIUpperLeftX) * GetChannelCount() * GetDepth();
594 
595  for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
596  memcpy(&(dst[y-ROIUpperLeftY][0]),
597  &(src[y][ROIUpperLeftX*GetChannelCount()*GetDepth()]), length);
598  }
599  return 0;
600 }
601 
602 
604 {
605 #ifdef BIAS_DEBUG
606  if (IsPlanar() && GetChannelCount()>1) {
607  BIASERR("only implemented for interleaved images...");
608  BIASABORT;
609  }
610 #endif
611  int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
612  GetROI()->GetCorners(ROIUpperLeftX, ROIUpperLeftY,
613  ROILowerRightX, ROILowerRightY);
614 
615  if ( ((int)Image.GetWidth() != (ROILowerRightX - ROIUpperLeftX)) ||
616  ((int)Image.GetHeight() != (ROILowerRightY - ROIUpperLeftY)) ){
617  BIASERR("ImageBase:Paste2ROI(): ROI size in destination is not equal "<<
618  "to image size in source, aborting! ROI:WxH "
619  <<(ROILowerRightX - ROIUpperLeftX)<<"x"
620  <<(ROILowerRightY - ROIUpperLeftY)<<" Im:WxH "
621  <<Image.GetWidth()<<"x"<<Image.GetHeight());
622  BIASABORT;
623  return(-1);
624  }
625  if (Image.GetColorModel() != GetColorModel()){
626  BIASERR("ImageBase::Paste2ROI(): ColorModels do not match, aborting!");
627  BIASABORT;
628  return(-1);
629  }
630 
631  char **dst, **src;
632  register int y;
633 
634  dst = (char**)GetImageDataArray();
635  src = (char**)Image.GetImageDataArray();
636  int length= (ROILowerRightX-ROIUpperLeftX)*GetChannelCount()*GetDepth();
637  //copy image line-wise with memcopy
638  for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
639  memcpy(&(dst[y][ROIUpperLeftX*GetChannelCount()*GetDepth()]),
640  &(src[y-ROIUpperLeftY][0]),length);
641  }
642  return 0;
643 }
644 
645 
647 {
648  int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
649  GetROI()->GetCorners(ROIUpperLeftX, ROIUpperLeftY,
650  ROILowerRightX, ROILowerRightY);
651 
652  const int bytesInRow= (ROILowerRightX-ROIUpperLeftX)*
654  char *dst = new char[(ROILowerRightY - ROIUpperLeftY)*bytesInRow];
655  char **src = (char**)GetImageDataArray();
656 
657  register int y;
658  int start=ROIUpperLeftX*GetChannelCount()*GetDepth();
659 
660  for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
661  memcpy(dst+(y-ROIUpperLeftY)*bytesInRow, &(src[y][start]),
662  bytesInRow);
663  }
664 
665  Width_ = ROILowerRightX - ROIUpperLeftX;
666  Height_ = ROILowerRightY - ROIUpperLeftY;
669  UnsetROI();
671  RedirectImageDataPointer((void*)dst);
672  return 0;
673 }
674 
676 {
677  switch (GetROI()->GetROIType()){
678  case ROI_Corners:
679  {
680  // just for debugging
681  //ImageBase tmp = *this;
682 
683  char *id = (char *)GetImageData();
684  unsigned ulx, uly, lrx, lry;
685  GetROI()->GetCorners(ulx, uly, lrx, lry);
686  // top
687  unsigned size = uly*GetWidthStep();
688  memset((void *)id, 0, size);
689  // and bottom
690  size = (GetHeight()-lry)*GetWidthStep();
691  memset((void *)(&id[lry*GetWidthStep()]), 0, size);
692  // left and right
693  unsigned left_size, right_offs, right_size, y_offs;
694  left_size = ulx*GetChannelCount()*GetDepth();
695  right_offs = lrx*GetChannelCount()*GetDepth();
696  right_size = (GetWidth()-lrx)*GetChannelCount()*GetDepth();
697  for (unsigned y=uly; y<lry; y++){
698  y_offs = y*GetWidthStep();
699  memset((void *)(&id[y_offs]), 0, left_size);
700  memset((void *)(&id[y_offs+right_offs]), 0, right_size);
701  }
702 
703  /* just for debugging from here
704  id = (char *)tmp.GetImageData();
705  for (unsigned y=0; y<GetHeight(); y++){
706  for (unsigned x=0; x<GetWidth(); x++){
707  if (!GetROI()->IsInROI(x, y))
708  memset((void *)
709  (&id[y*GetWidthStep()+x*GetChannelCount()*GetDepth()]),
710  0, GetChannelCount()*GetDepth());
711  }
712  }
713  size = GetWidth()*GetHeight()*GetChannelCount()*GetDepth();
714  for (unsigned i=0; i<size; i++){
715  if (((char *)tmp.GetImageData())[i] !=
716  ((char *)GetImageData())[i]){
717  ABORT;
718  } else if (i%25==0){
719  cout << "." << flush;
720  }
721  }*/
722  }
723  break;
724  default:
725  {
726  char *id = (char *)GetImageData();
727  for (unsigned y=0; y<GetHeight(); y++){
728  for (unsigned x=0; x<GetWidth(); x++){
729  if (!GetROI()->IsInROI(x, y))
730  memset((void *)
731  (&id[y*GetWidthStep()+x*GetChannelCount()*GetDepth()]),
732  0, GetChannelCount()*GetDepth());
733  }
734  }
735  }
736  break;
737  }
738 }
739 
740 //////////////////////////////////////////////////////////////////////////////
741 //
742 // Assignment Operator
743 //
744 //////////////////////////////////////////////////////////////////////////////
746 {
747  //cout << "ImageBase operator= " << endl;
748  /// always copy the members that do not depend on image data
749  /// to allow feeding Image* into ImageBase*. JW 01/2005
750 #ifdef BIAS_DEBUG
751  _liDebugLevel = Source.GetDebugLevel();
752  BIASGDOUT(D_IMAGE_TRACE,
753  "called ImageBase::operator=(const ImageBase& Source)"
754  <<" source->GetStorageType = "<<Source.GetStorageType()
755  <<" this->GetStorageType = "<<GetStorageType()
756  <<" source->GetColorModel = "<<Source.GetColorModel()
757  <<" this->GetColorModel = "<<GetColorModel()
758  );
759 #endif
760 
761  bool skipAlloc=false;
762  // determine if we can keep the data area or need to realllcoate JW:
763  if ( !(this->IsEmpty()) && (Source.IsEmpty()) ){
764  // src is empty, so should be this.
765  /* cout << "JW calls Release() now: Source empty? " << boolalpha << Source.IsEmpty()
766  << ", this empty? " << boolalpha << IsEmpty() << endl;*/
767  Release();
768  // not done because the members need to be set.
769  //return *this;
770  skipAlloc=true;
771  };
772 
773  // skip allocation if there is no data in source image,
774  // required for STL vector allocation
775  if (Source.IsEmpty()) {
776  skipAlloc=true;
777  }
778 
779  if (GetStorageType()!=ST_invalid){
780  /* cout << "ImageBase operator=(): storage type source = " << Source.GetStorageType()
781  << ", this = " << GetStorageType() << endl;*/
782  if (Source.GetStorageType()!=GetStorageType()){
783  BEXCEPTION("Can not assign images of different storage type! Call Release(true) on destination image, if this is intented.");
784  }
785  }
786 
787  if ((!this->IsEmpty()) && (!SamePixelAndChannelCount(Source) )) {
788  // sizes or type don't match, realloc
789  Release();
790  };
791 
792  if (this->IsEmpty() && !skipAlloc){
793  Init(Source.GetWidth(), Source.GetHeight(), Source.GetChannelCount(),
794  Source.GetStorageType());
795  }
796 
797  if (!Source.IsEmpty()){
798  // copy image data:
799  memcpy(this->GetImageData(), // dest
800  Source.GetImageData(), //src
801  Source.GetPixelCount() * Source.GetDepth() *
802  Source.GetChannelCount());
803  }
804 
805 
806  // copy remaining member values:
807  StorageType_ = Source.GetStorageType();
808  ColorModel_ = Source.GetColorModel();
809  ChannelCount_ = Source.GetChannelCount();
810  Depth_ = Source.GetDepth();
811  BitDepth_ = Source.GetBitDepth();
812  Width_ = Source.GetWidth();
813  Height_ = Source.GetHeight();
814  InterleavedDataOrder_ = ! Source.IsPlanar();
815  WidthStep_ = Source.WidthStep_;
816  _UID = Source.GetUID();
817  _MetaData = Source._MetaData;
818  Roi_ = *Source.GetROI();
819  shouldReleaseData_ = true;
820  // update pointers to begin of line for new allocated image data area.
822 
823  return *this;
824 }
825 
826 
827 void ImageBase::CopyIn_NoInit(void *data)
828 {
829  BIASDOUT(D_COPYIN," entering CopyIn_NoInit()");
830  memcpy(GetImageData(), data, GetPixelCount()*GetChannelCount()*GetDepth());
831 }
832 
833 
835 {
836  int size=GetPixelCount() * GetChannelCount() * GetDepth(); // in byte
837  if (size<=0) return -1;
838 
839  char *newData = NULL;
840  //TODO: this is causing a bad allocation on OpenGL screenshot... (JW DBG)
841  //try {
842  newData = new char[size];
843  //} catch( bad_alloc &ba) {
844  // BIASERR( ba.what() );
845  // return -1;
846  //};
847 
848 
849  register unsigned int length = GetWidth() * GetChannelCount() * GetDepth();
850  if (InterleavedDataOrder_) {
851  register char *targetData = newData + size - length;
852  for (register unsigned int i=0; i < Height_; i++) {
853  memcpy(targetData,(char*)(ImageDataArray_[i]),length);
854  targetData -= length;
855  }
856  }
857  else { // planar
858  BIASERR("Flip not implemented for planar images.");
859  /*
860  register int rowSize=Width_*sizeof(StorageType);
861  register StorageType *targetData = newData+
862  (Height_-1)*rowSize;
863  register StorageType *sourceData = ImageData_;
864  for (int channel=0;channel<ChannelCount_;channel++) {
865  for (register int i=0; i < Height_; i++) {
866  memcpy(targetData,sourceData,rowSize);
867  targetData-=rowSize;
868  sourceData+=rowSize;
869  }
870  targetData+=(2*Height_-1)*rowSize;
871  } */
872  }
874  RedirectImageDataPointer((void*)newData);
875  return 0;
876 }
877 
879 {
880  int size=GetPixelCount() * GetChannelCount() * GetDepth(); // in byte
881  if (size<=0) return -1;
882  int pixelsize=GetChannelCount() * GetDepth();
883  char *newData = new char[size];
884  if (InterleavedDataOrder_) {
885  register char *targetData;
886  register char *srcData;
887  for (register unsigned int i=0; i < Height_; i++) {
888  targetData = newData + (i+1)*WidthStep_ - pixelsize;
889  srcData = (char *)(ImageDataArray_[i]);
890  for (register int x=0; x<(int)Width_; x++){
891  memcpy(targetData-x*pixelsize, srcData+x*pixelsize, pixelsize);
892  }
893  }
894  } else { // planar
895  BIASERR("FlipHorizontal not implemented for planar images.");
896  }
898  RedirectImageDataPointer((void*)newData);
899  return 0;
900 }
901 
902 
903 
904 
905 void ImageBase::PrintHeader(ostream& os) const
906 {
907  os
908  << "\nVersion_ : \t\t" << Version_
909  << "\nStorageType_ : \t\tImageBase::"<<StorageType_
910  << "\nColorModel_ : \t\tImageBase::"<< ColorModel_
911  << " ("<<(int)ColorModel_<<")"
912  << "\nWidth_: \t\t" << Width_
913  << "\nHeight_: \t\t" << Height_
914  << "\nnChannelCount_: \t" << ChannelCount_
915  << "\nWidthStep_: \t\t" << WidthStep_
916  << "\nDepth_: \t\t" << Depth_
917  << "\nBitDepth_: \t\t" << BitDepth_
918  << "\nPixelCount_: \t\t" << GetPixelCount()
919  << "\nInterleavedDataOrder_: \t" << InterleavedDataOrder_
920  << "\nROI: \t" << Roi_
921  << "\nUUID: \t\t\t"<<GetUID()
922  << " ("<<(GetUID().IsValid()?"valid":"invalid")<<")";
923  os<<"\nImageData_ ptr: \t\t"
924  //<<hex
925  <<(long)ImageData_;
926  os<< "\nImageDataArray_ ptr: :\t\t"
927  //<<hex
928  <<(long)ImageDataArray_;
929 #ifdef BIASDEBUG
930  os << "\nDebuglevel_:\t" << Debuglevel_;
931 #endif
932  os<<"\n"<<dec;
933 }
934 
935 
936 
937 
938 // JW 09/2003
939 bool
941  //unsigned int w2, h2;
942  //return PowerOfTwoSize(w2,h2);
943  int w=(int)GetWidth();
944  int h=(int)GetHeight();
945  return IsPowerOfTwoSize(w, h);
946 }
947 
948 // static JW
949 bool
950 ImageBase::IsPowerOfTwoSize(const unsigned int w,
951  const unsigned int h)
952 {
953  // JW 09/03: more efficient is this with bitmasks :-)
954  return (((w&(w-1))==0) && ((h&(h-1))==0));
955 }
956 
957 
958 
959 // Jan Woetzel
960 bool
961 ImageBase::PowerOfTwoSize(unsigned int & width2, unsigned int & height2) const {
962  // next pow2 sizes:
963  width2 = PowerOfTwoSize( GetWidth() );
964  height2 = PowerOfTwoSize( GetHeight() );
965 
966  return ( (GetWidth()==width2) && (GetHeight()==height2));
967 }
968 
969 // Jan Woetzel
970 unsigned int
971 ImageBase::PowerOfTwoSize(const unsigned int & val) {
972  // special case
973  if (val==0)
974  return 0;
975 
976  // loop is faster than ldexp etc...
977  unsigned int res = 1;
978  while (res < val)
979  res <<= 1;
980  return res;
981 }
982 
983 
984 // JW
985 bool ImageBase::DimensionMatch(const BIAS::ImageBase & other) const {
986  // return treu of width and height matches. don't are about types or channel count
987  return ( (this->GetWidth() == other.GetWidth())
988  && (this->GetHeight() == other.GetHeight()) );
989 }
990 
991 
992 bool ImageBase::FormatMatch(const BIAS::ImageBase & d ) const {
993  if (!DimensionMatch(d))
994  return false;
995  // check twice just to be sure.
996  if (GetWidth() != d.GetWidth())
997  return false;
998  if (GetHeight() != d.GetHeight())
999  return false;
1000  if (GetDepth() != d.GetDepth())
1001  return false;
1002  if (GetBitDepth() != d.GetBitDepth())
1003  return false;
1004  if (GetChannelCount() != d.GetChannelCount())
1005  return false;
1006  if (GetSizeByte() != d.GetSizeByte())
1007  return false;
1008  if (GetColorModel() != d.GetColorModel())
1009  return false;
1010  if (GetWidthStep() != d.GetWidthStep())
1011  return false;
1012  //if (s.GetPixelFormat() != d.GetPixelFormat())
1013  // return false;
1014 
1015  return true; // fits.
1016 }
1017 
1018 
1019 void *ImageBase::PixelValueBase(unsigned x, unsigned y, unsigned channel)
1020 {
1021  BIASERR("warnig, PixelValueBase is deprecated and will be removed in the "
1022  "future,\nuse GetImageDataArray() instead!");
1024  return (void *)(&((char*)ImageData_)[(y*WidthStep_*Depth_+
1026  channel)]);
1027  else
1028  return (void *)(&((char*)ImageData_)[channel*Width_*Height_*Depth_+
1029  y*Width_*Depth_+x*Depth_]);
1030 }
1031 
1032 /// JW: there's no reason to drop this interface - be API backward compatible!
1033 int ImageBase::SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY,
1034  unsigned int LowerRightX, unsigned int LowerRightY)
1035 {
1036  return SetROICorners(
1037  UpperLeftX, UpperLeftY,
1038  LowerRightX, LowerRightY);
1039 }
1040 
1041 int
1042 ImageBase::SetROI(const ROI& roi) {
1043  *GetROI() = roi;
1044  return 0;
1045 }
1046 
1047 
1048 int ImageBase::SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY,
1049  unsigned int LowerRightX, unsigned int LowerRightY)
1050 {
1051  return GetROI()->SetCorners(
1052  UpperLeftX, UpperLeftY,
1053  LowerRightX, LowerRightY);
1054 }
1055 
1056 
1058 {
1059  GetROI()->UnsetROI();
1060 }
1061 
1062 void ImageBase::GetROI(unsigned int& UpperLeftX, unsigned int& UpperLeftY,
1063  unsigned int& LowerRightX, unsigned int& LowerRightY) const
1064 {
1065  GetROICorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1066 }
1067 void ImageBase::GetROICorners(unsigned int& UpperLeftX, unsigned int& UpperLeftY,
1068  unsigned int& LowerRightX, unsigned int& LowerRightY) const
1069 {
1070  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1071 }
1072 
1073 
1074 void ImageBase::GetROI( int& UpperLeftX, int& UpperLeftY,
1075  int& LowerRightX, int& LowerRightY) const
1076 {
1077  GetROICorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1078 }
1079 void ImageBase::GetROICorners(int& UpperLeftX, int& UpperLeftY,
1080  int& LowerRightX, int& LowerRightY) const
1081 {
1082  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1083 }
1084 
1085 
1086 
1087 void ImageBase::PrintROI(std::ostream& os) const
1088 {
1089  os << *GetROI();
1090 }
1091 
1092 const unsigned int ImageBase::GetROIUpperLeftX() const
1093 {
1094  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1095  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1096  return UpperLeftX;
1097 }
1098 
1099 const unsigned int ImageBase::GetROIUpperLeftY() const
1100 {
1101  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1102  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1103  return UpperLeftY;
1104 }
1105 
1106 const unsigned int ImageBase::GetROILowerRightX() const
1107 {
1108  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1109  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1110  return LowerRightX;
1111 }
1112 
1113 const unsigned int ImageBase::GetROILowerRightY() const
1114 {
1115  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1116  GetROI()->GetCorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1117  return LowerRightY;
1118 }
1119 
1120 
1121 // JW
1122 int ImageBase::ZeroPad(const unsigned int newwidth,
1123  const unsigned int newheight,
1124  unsigned char bgcolor )
1125 {
1126  return this->Pad(newwidth, newheight, bgcolor );
1127 }
1128 
1129 
1130 // JW
1131 int ImageBase::PadToPowerOfTwo(const int & padVal)
1132 {
1133  unsigned int w2, h2;
1134  // do nothing if image is already correct size
1135  if (PowerOfTwoSize(w2,h2)) {
1136  // do nothing.
1137  return 0;
1138  }
1139 
1140  // create a temporary
1141  // to use the existing out of place impl.
1142  ImageBase img;
1143  int result=PadToPowerOfTwo( img, padVal );
1144 
1145  // assignment to emulaet in-place
1146  *this = img;
1147 
1148  return result;
1149 }
1150 
1151 
1152 // JW
1153 int
1155  const int & padVal) const
1156 {
1157 #ifdef BIAS_DEBUG
1158  if (!IsInterleaved()) {
1159  BIASERR("PadToPowerOfTwo just for interleaved format implemented!");
1160  };
1161 #endif
1162  BIASASSERT( IsInterleaved() );
1163 
1164  unsigned int w2, h2; // desired dest size
1165  if (PowerOfTwoSize(w2,h2))
1166  {
1167  // is already a power of two - just copy, no padding
1168  // constructor is always safe, operator= not
1169  dest=ImageBase( *this );
1170  return 0;
1171  };
1172 
1173  // call general Padding routine
1174  return Pad(dest, w2, h2, padVal);
1175 }
1176 
1177 
1178 
1179 
1180 // JW
1181 int
1182 ImageBase::Pad(const unsigned int & newwidth,
1183  const unsigned int & newheight,
1184  const int & padVal)
1185 {
1186  // do nothing if image is already correct size
1187  if ((newwidth==GetWidth()) && (newheight==GetHeight()))
1188  {
1189  // do nothing.
1190  return 0;
1191  }
1192 
1193  // create a temporary
1194  // to use the existing out of place impl.
1195  ImageBase img;
1196  int result=Pad( img, newwidth, newheight, padVal );
1197 
1198  // assignment to emulaet in-place
1199  *this = img;
1200 
1201  return result;
1202 }
1203 
1204 
1205 // JW
1206 int
1208  const unsigned int & newwidth,
1209  const unsigned int & newheight,
1210  const int & padVal) const
1211 {
1212 
1213  if (!IsInterleaved())
1214  {
1215  BIASERR("can work on interleaved images, only. Sorry.");
1216  return -1;
1217  }
1218  if (newwidth < GetWidth() || newheight < GetHeight() )
1219  {
1220  BIASERR("can only increase image size. Sorry.");
1221  return -1;
1222  }
1223  BIASASSERT( IsInterleaved() );
1224  BIASASSERT( GetWidth() <= newwidth );
1225  BIASASSERT( GetHeight() <= newheight );
1226 
1227  //
1228  // OK
1229  //
1230 
1231  // pad and copy from upper left origin
1232  dest=ImageBase(newwidth, newheight, GetChannelCount(), GetStorageType(),
1233  IsInterleaved() );
1234  dest.SetColorModel( GetColorModel() );
1235  dest.SetBitDepth( GetBitDepth() );
1236 
1237  // compute bytes per row for src and dest:
1238  const unsigned int src_BytePerRow = GetDepth() * GetWidth() * GetChannelCount();
1239  const unsigned int dest_BytePerRow = GetDepth() * dest.GetWidth() * dest.GetChannelCount();
1240 
1241  //
1242  // dest image is:
1243  // SSS R
1244  // BBBBB
1245  //
1246  // S,R: for all source rows
1247  // copy overlap part from left and init non-overlap data.
1248  for (unsigned int ys=0; ys<GetHeight(); ys++)
1249  {
1250  // S:
1251  // copy: dest* , src*, n
1252  memcpy(
1253  (void*) dest.GetImageDataArray()[ys],
1254  (void*) GetImageDataArray()[ys],
1255  src_BytePerRow );
1256 
1257  // R:
1258  // for all lines of orig image: pad right part
1259  if (dest_BytePerRow > src_BytePerRow) {
1260  // set remainder of row to zero in dest img.
1261  // set dest*, val, n
1262  memset(
1263  (void*) (& ((unsigned char*)(dest.GetImageDataArray()[ys]))[src_BytePerRow])
1264  ,padVal
1265  ,dest_BytePerRow-src_BytePerRow );
1266  };
1267  };
1268 
1269  // B: bottom rectangle
1270  if (GetHeight()<dest.GetHeight())
1271  {
1272  // set dest*, val, n
1273  memset((void*) dest.GetImageDataArray()[GetHeight()],
1274  padVal,
1275  dest_BytePerRow*(dest.GetHeight()-GetHeight()) );
1276  };
1277  return 0;
1278 }
1279 
1280 
1281 // JW
1282 int ImageBase::PadToPowerOfTwoAndFlip(const int & padVal)
1283 {
1284  /// \todo replace with linewise memmov
1285  if (0==Flip())
1286  {
1287  return PadToPowerOfTwo(padVal);
1288  } else {
1289  BIASERR("could not flip. skipped padding.");
1290  return -1;
1291  };
1292 }
1293 
1294 
1295 // JW
1296 // static
1298 {
1299  switch (storagetype)
1300  {
1303  //BIASASSERT(sizeof(char)==1);
1304  return sizeof(char);
1307  //BIASASSERT(sizeof(short int)==2);
1308  return sizeof(short int);
1311  //BIASASSERT(sizeof(int)==4);
1312  return sizeof(int);
1314  //BIASASSERT(sizeof(float)==4);
1315  return sizeof(float);
1317  //BIASASSERT(sizeof(double)==8);
1318  return sizeof(double);
1320  // useful e.g. for creating vector of empty images
1321  return 0;
1322  default:
1323  BIASERR( "unsupported StorageType:"<<storagetype);
1324  BIASBREAK;
1325  };
1326  return 0;
1327 }
1328 
1330  switch (colormodel)
1331  {
1334  return 4;
1335 
1339  BIASWARN("you are possibly treating a HSV/HSL/hsL as RGB.");
1342  return 3;
1343 
1345  return 2;
1346 
1348  return 1;
1349 
1354  return 1; // packed: 3 values in 1 Bytes
1356  return 3; // packed: 9 values in 3 Bytes
1357 
1358  default:
1359  BIASERR( "unsupported/unknown color model "<<colormodel);
1360  };
1361  return 0;
1362 }
1363 
1364 
1365 // JW
1367 {
1368  switch (colormodel)
1369  {
1372  return 4;
1373 
1377  BIASWARN("you are possibly treating a HSV/HSL/hsL as RGB.");
1380  return 3;
1381 
1383  return 2;
1384 
1386  return 1;
1387 
1392  //BIASWARN("you are possibly treating a Bayer image as RGB.");
1393  return 3;
1395  // 3 Bytes/channels containing 9 packed values
1396  // nChannels is determined by raw data size,
1397  // not descriptive meta tags such as ColorModel
1398  return 3;
1399 
1400 
1401  default:
1402  BIASERR( "unsupported/unknown color model "<<colormodel);
1403  };
1404  return 0;
1405 }
1406 
1407 
1408 #ifdef BIAS_HAVE_OPENCV
1409 // JW
1410 #include "WrapBias2Ipl.hh"
1411 
1412 
1413 
1414 int ImageBase::Display(const std::string & DestWin,
1415  const bool & autoresize,
1416  const bool & moveToTopLeft,
1417  const bool & waitForKey,
1418  const unsigned int & delayMsec,
1419  const float &scale,
1420  const bool & allowAlphaWindow
1421  ) const
1422 {
1423  // TODO: avoid copy for const
1424  //ImageBase tmp(*this);
1425  //WrapBias2Ipl wrap (&tmp);
1426 
1427  const WrapBias2Ipl wrap (this);
1428  return wrap.Display(
1429  DestWin,
1430  autoresize,
1431  moveToTopLeft,
1432  waitForKey,
1433  delayMsec,
1434  scale,
1435  allowAlphaWindow
1436  );
1437 }
1438 
1439 
1440 int ImageBase::Display(const std::string & DestWin) const
1441 {
1442  // wait just one msec for update, do not nlock program run.
1443  return this->Display(
1444  DestWin
1445  ,true // autoresize
1446  ,false // moveToTopLeft
1447  ,false // don't waitForKey
1448  ,1 // delayMsec
1449  );
1450 }
1451 
1452 int ImageBase::Display(const bool & waitForKey,
1453  const unsigned int & delayMsec,
1454  const float &scale ) const
1455 {
1456  return this->Display(
1457  string( DEFAULT_WrapBias2Ipl_WINNAME ),
1458  true, false,
1459  waitForKey, delayMsec, scale );
1460 }
1461 
1462 
1464 {
1465  return this->Display(
1466  true, /* waitforkey*/
1467  DEFAULT_Display_delay, /* delay*/
1468  DEFAULT_32to8_scale /*float scale */
1469  );
1470 }
1471 #endif // BIAS_HAVE_OPENCV
1472 
1473 
1474 // fixes for building dlls
1475 namespace BIAS {
1476 
1477  std::ostream& operator<<(std::ostream& os, const ImageBase& img2)
1478  {
1479  // TODO: remove dirty const_cast by making req. function in ImageBase const
1480  // to use reinterpret_cast<> we first have to unconst:
1481  ImageBase &img = const_cast<ImageBase&>(img2);
1482 
1483  //enum BIAS::ImageBase::EStorageType storageType = img.GetStorageType();
1484  int Version = img.GetVersionNumber();
1485  int depthondisk;
1486  // added in Version 300 to identify mipimage on disk similar to magic number
1487  os.write(IDENTIFIER, IDENTIFIER_LENGTH);
1488  os.write(reinterpret_cast<char*>(&img.StorageType_), sizeof(BIAS::ImageBase::EStorageType));
1489  os.write(reinterpret_cast<char*>(&Version), sizeof(int));
1490  os.write(reinterpret_cast<char*>(&img.ChannelCount_), sizeof(int));
1491  os.write(reinterpret_cast<char*>(&img.Width_), sizeof(int));
1492  os.write(reinterpret_cast<char*>(&img.Height_), sizeof(int));
1493  os.write(reinterpret_cast<char*>(&img.ColorModel_), sizeof(BIAS::ImageBase::EColorModel));
1494  depthondisk = img.Depth_ * 8;
1495  os.write(reinterpret_cast<char*>(& depthondisk), sizeof(int));
1496  os.write(reinterpret_cast<char*>(&img.BitDepth_), sizeof(int));
1497  os.write(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1498  int PixelCount = img.GetPixelCount();
1499  os.write(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1500  os.write(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1501 
1502  // version 311: now writing unique image id as a string,
1503  // make sure that id is valid, since IsValid_ is not written
1504 #ifdef BIAS_DEBUG
1505 # ifdef BIAS_EXTRA_WARN
1506  if (!img.GetUID().IsValid()) {
1507  BIASERR("Writing invalid UID! Generate a valid one before writing image !");
1508  img.GetUID().clear();
1509  }
1510 # endif //BIAS_EXTRA_WARN
1511 #endif //BIAS_DEBUG
1512  std::string id;
1513  img._UID.GetString(id);
1514  os.write(id.c_str(), 36);
1515  if (img.GetROI()->WriteBinary(os)!=0){
1516  BIASERR("error writing ROI");
1517  }
1518 
1519  // finally write image data:
1520  BIASASSERT(img.GetImageData()!=NULL); // jw
1521  // TOOD seems to cause access to uninitialized value(s) by valgrind
1522  // Syscall param write(buf) points to uninitialized Bytes( ExampleMetaData
1523  //( JW)
1524  os.write(
1525  reinterpret_cast<char*>(img.GetImageData()),
1526  img.GetPixelCount() * img.GetChannelCount() * img.Depth_
1527  );
1528 
1529  return os;
1530  }
1531 
1532  std::ostream& operator<<(std::ostream& os,
1533  const ImageBase::EStorageType &st)
1534  {
1535  switch (st)
1536  {
1537  case ImageBase::ST_invalid: os<< "ST_invalid"; break;
1538  case ImageBase::ST_unsignedchar: os<< "ST_unsignedchar"; break;
1539  case ImageBase::ST_char: os<< "ST_char"; break;
1540  case ImageBase::ST_unsignedshortint: os<< "ST_unsignedshortint"; break;
1541  case ImageBase::ST_shortint: os<< "ST_shortint"; break;
1542  case ImageBase::ST_unsignedint: os<< "ST_unsignedint"; break;
1543  case ImageBase::ST_int: os<< "ST_int"; break;
1544  case ImageBase::ST_float: os<< "ST_float"; break;
1545  case ImageBase::ST_double: os<< "ST_double"; break;
1546  default: os<<"unknown StorageType"; break;
1547  }
1548  return os;
1549  }
1550 
1551 
1552  std::ostream& operator<<(std::ostream& os,
1553  const ImageBase::EColorModel &st)
1554  {
1555  switch (st)
1556  {
1557  case ImageBase::CM_invalid: os<< "CM_invalid"; break;
1558  case ImageBase::CM_Grey: os<< "CM_Grey"; break;
1559  case ImageBase::CM_RGB: os<< "CM_RGB"; break;
1560  case ImageBase::CM_BGR: os<< "CM_BGR"; break;
1561  case ImageBase::CM_YUYV422: os<< "CM_YUYV422"; break;
1562  case ImageBase::CM_UYVY422: os<< "CM_UYVY422"; break;
1563  case ImageBase::CM_YUV420P: os<< "CM_YUV420P"; break;
1564  case ImageBase::CM_YUV444: os<< "CM_YUV444"; break;
1565  case ImageBase::CM_YUV411: os<< "CM_YUV411"; break;
1566  case ImageBase::CM_HSV: os<< "CM_HSV"; break;
1567  case ImageBase::CM_HSI_OBS: os<< "CM_HSI is obsolete use HSL"; break;
1568  case ImageBase::CM_DV: os<< "CM_DV"; break;
1569  case ImageBase::CM_RGBA: os<< "CM_RGBA"; break;
1570  case ImageBase::CM_GreyA: os<< "CM_Bayer_GreyA"; break;
1571  case ImageBase::CM_Bayer_RGGB: os<< "CM_Bayer_RGGB"; break;
1572  case ImageBase::CM_Bayer_GBRG: os<< "CM_Bayer_GBRG"; break;
1573  case ImageBase::CM_Bayer_GRBG: os<< "CM_Bayer_GRBG"; break;
1574  case ImageBase::CM_Bayer_BGGR: os<< "CM_Bayer_BGGR"; break;
1575  case ImageBase::CM_HSL: os << "CM_HSL"; break;
1576  case ImageBase::CM_hsL: os << "CM_hsL"; break;
1577  case ImageBase::CM_SymTensor2x2: os << "CM_SymTensor2x2"; break;
1578  case ImageBase::CM_BGRA: os << "CM_BGRA"; break;
1579  case ImageBase::CM_RGBE: os << "CM_RGBE"; break;
1580  case ImageBase::CM_PGR_XB3_F7M3_GBRG: os << "CM_PGR_XB3_F7M3_GBRG"; break;
1581  case ImageBase::CM_DepthAndVariance: os << "CM_DepthAndVariance";break;
1582  case ImageBase::CM_Disparity: os << "CM_Disparity";break;
1583  case ImageBase::CM_Depth: os << "CM_Depth";break;
1584  case ImageBase::CM_YUYV: os<< "CM_YUYV"; break;
1585  case ImageBase::CM_LUV: os << "CM_LUV";break;
1586  case ImageBase::CM_XYZ: os << "CM_XYZ";break;
1587  case ImageBase::CM_LAB: os << "CM_LAB";break;
1588  case ImageBase::CM_DOES_NOT_EXIST: os << "CM_DOES_NOT_EXIST (end of list marker)"; break;
1589 
1590  default: os<<"unknown ColorModel"; break;
1591  }
1592  return os;
1593  }
1594 
1595  void ImageBase::StringToColorModel(const std::string& str,
1597  {
1598 
1600  if(str=="CM_Grey") cm = ImageBase::CM_Grey ;
1601  if(str=="CM_RGB") cm = ImageBase::CM_RGB;
1602  if(str=="CM_BGR") cm = ImageBase::CM_BGR;
1603  if(str=="CM_YUYV422") cm = ImageBase::CM_YUYV422;
1604  if(str=="CM_UYVY422") cm = ImageBase::CM_UYVY422;
1605  if(str=="CM_YUV420P") cm =ImageBase::CM_YUV420P;
1606  if(str=="CM_YUV444") cm =ImageBase::CM_YUV444;
1607  if(str=="CM_YUV411") cm = ImageBase::CM_YUV411;
1608  if(str=="CM_HSV") cm = ImageBase::CM_HSV;
1609  if(str=="CM_HSI is obsolete use HSL") cm =ImageBase::CM_HSI_OBS;
1610  if(str=="CM_DV") cm = ImageBase::CM_DV;
1611  if(str=="CM_RGBA") cm = ImageBase::CM_RGBA;
1612  if(str=="CM_Bayer_GreyA") cm = ImageBase::CM_GreyA;
1613  if(str=="CM_Bayer_RGGB") cm = ImageBase::CM_Bayer_RGGB;
1614  if(str=="CM_Bayer_GBRG") cm = ImageBase::CM_Bayer_GBRG;
1615  if(str=="CM_Bayer_GRBG") cm = ImageBase::CM_Bayer_GRBG;
1616  if(str=="CM_Bayer_BGGR") cm = ImageBase::CM_Bayer_BGGR;
1617  if(str=="CM_HSL") cm = ImageBase::CM_HSL;
1618  if(str=="CM_hsL") cm = ImageBase::CM_hsL;
1619  if(str=="CM_SymTensor2x2") cm = ImageBase::CM_SymTensor2x2;
1620  if(str=="CM_BGRA") cm = ImageBase::CM_BGRA;
1621  if(str=="CM_RGBE") cm = ImageBase::CM_RGBE;
1622  if(str=="CM_PGR_XB3_F7M3_GBRG") cm = ImageBase::CM_PGR_XB3_F7M3_GBRG;
1623  if(str== "CM_DepthAndVariance") cm = ImageBase::CM_DepthAndVariance;
1624  if(str== "CM_Disparity") cm = ImageBase::CM_Disparity;
1625  if(str== "CM_Depth") cm = ImageBase::CM_Depth;
1626  if(str== "CM_YUYV") cm = ImageBase::CM_YUYV;
1627  if(str== "CM_LUV") cm = ImageBase::CM_LUV;
1628  if(str== "CM_XYZ") cm = ImageBase::CM_XYZ;
1629  if(str== "CM_LAB") cm = ImageBase::CM_LAB;
1630  }
1631 
1632  void ImageBase::StringToStorageType(const std::string& str,
1634  {
1635  st=ST_invalid;
1636  if(str=="ST_unsignedchar") st = ImageBase::ST_unsignedchar;
1637  if(str=="ST_char") st = ImageBase::ST_char;
1638  if(str=="ST_unsignedshortint") st = ImageBase::ST_unsignedshortint;
1639  if(str=="ST_shortint") st = ImageBase::ST_shortint;
1640  if(str=="ST_unsignedint") st = ImageBase::ST_unsignedint;
1641  if(str=="ST_int") st = ImageBase::ST_int;
1642  if(str=="ST_float") st = ImageBase::ST_float;
1643  if(str=="ST_double") st = ImageBase::ST_double;
1644  }
1645 
1646 
1647  std::istream& operator>>(std::istream& is, BIAS::ImageBase& img)
1648  {
1649  enum BIAS::ImageBase::EStorageType FileStorageType;
1650  int Version;
1651  int Width, Height, ChannelCount, PixelCount;
1652  char identifier[IDENTIFIER_LENGTH];
1653  char cBuffer[37];
1654  bool roidefined;
1655 
1656  is.read(identifier, IDENTIFIER_LENGTH);
1657  if (identifier[0] != 'M' || identifier[1] != 'I' || identifier[2] != 'P'){
1658  BIASERR("no identifier in image, maybe old version or no MIP image"
1659  <<"\ntry mipconvertversion in Image/test");
1660  is.setstate(std::ios::badbit);
1661  return is;
1662  }
1663 
1664  is.read(reinterpret_cast<char*>(&FileStorageType),
1667  if (FileStorageType!=img.GetStorageType()){
1668  // please ensure that TestImageIO works correctly after changeing
1669  // code here
1670  //BIASERR("ImageBase operator>> cannot read "<<FileStorageType
1671  // << " into ImageBase with storage type "<<img.GetStorageType());
1672  is.setstate(ios_base::failbit);
1673  return is;
1674  }
1675  }
1676  if ( ! img.IsEmpty() )
1677  img.Release();
1678 
1679  is.read(reinterpret_cast<char*>(&Version), sizeof(int));
1680  switch (Version)
1681  {
1682  case 320: // new ROI class
1683  // std::cout <<"Opening file with version MIP320"<<std::endl;
1684  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1685  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1686  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1687  img.Init(Width, Height, ChannelCount, FileStorageType);
1688  is.read(reinterpret_cast<char*>(&img.ColorModel_),
1690  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1691  img.Depth_ /= 8;
1692  is.read(reinterpret_cast<char*>(&img.BitDepth_), sizeof(int));
1693  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1694  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1695  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1697  // read uid:
1698  is.read(cBuffer, 36);
1699  cBuffer[36]=0;
1700  img._UID.SetFromString(cBuffer);
1701  if (img.GetROI()->ReadBinary(is)!=0){
1702  BIASERR("error reading roi");
1703  }
1704  // read image data
1705  is.read(reinterpret_cast<char*>(img.ImageData_),
1706  img.GetPixelCount() * img.ChannelCount_ * img.Depth_);
1707  break;
1708  case 313: // removed ROIIsDefined_
1709  // std::cout <<"Opening file with version MIP313"<<std::endl;
1710  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1711  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1712  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1713  img.Init(Width, Height, ChannelCount, FileStorageType);
1714  is.read(reinterpret_cast<char*>(&img.ColorModel_),
1716  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1717  img.Depth_ /= 8;
1718  is.read(reinterpret_cast<char*>(&img.BitDepth_), sizeof(int));
1719  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1720  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1721  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1722  {
1723  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1724  is.read(reinterpret_cast<char*>(&UpperLeftX), sizeof(unsigned int));
1725  is.read(reinterpret_cast<char*>(&UpperLeftY), sizeof(unsigned int));
1726  is.read(reinterpret_cast<char*>(&LowerRightX), sizeof(unsigned int));
1727  is.read(reinterpret_cast<char*>(&LowerRightY), sizeof(unsigned int));
1728  // not necessary
1729  //img.GetROI()->Resize(Width, Height);
1730  img.GetROI()->SetCorners(UpperLeftX, UpperLeftY,
1731  LowerRightX, LowerRightY);
1732  // cout <<"("<<UpperLeftX<<", "<<UpperLeftY<<") <--> ("
1733  // <<LowerRightX<<", "<<LowerRightY<<")"<<endl;
1734  }
1735  // read uid:
1736  is.read(cBuffer, 36);
1737  cBuffer[36]=0;
1738  img._UID.SetFromString(cBuffer);
1739 
1740  // read image data
1741  is.read(reinterpret_cast<char*>(img.ImageData_),
1742  img.GetPixelCount() * img.ChannelCount_ * img.Depth_);
1743  break;
1744  case 312: // removed ROIIsDefined_
1745  // std::cout <<"Opening file with version MIP312"<<std::endl;
1746  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1747  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1748  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1749  img.Init(Width, Height, ChannelCount, FileStorageType);
1750  is.read(reinterpret_cast<char*>(&img.ColorModel_), sizeof(BIAS::ImageBase::EColorModel));
1751  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1752  img.Depth_ /= 8;
1753  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1754  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1755  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1756  {
1757  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1758  is.read(reinterpret_cast<char*>(&UpperLeftX), sizeof(unsigned int));
1759  is.read(reinterpret_cast<char*>(&UpperLeftY), sizeof(unsigned int));
1760  is.read(reinterpret_cast<char*>(&LowerRightX), sizeof(unsigned int));
1761  is.read(reinterpret_cast<char*>(&LowerRightY), sizeof(unsigned int));
1762  // not necessary
1763  //img.GetROI()->Resize(Width, Height);
1764  img.GetROI()->SetCorners(UpperLeftX, UpperLeftY,
1765  LowerRightX, LowerRightY);
1766  }
1767  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftX_), sizeof(unsigned int));
1768  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftY_), sizeof(unsigned int));
1769  // is.read(reinterpret_cast<char*>(&img.ROILowerRightX_), sizeof(unsigned int));
1770  // is.read(reinterpret_cast<char*>(&img.ROILowerRightY_), sizeof(unsigned int));
1771  // read uid:
1772  is.read(cBuffer, 36);
1773  cBuffer[36]=0;
1774  img._UID.SetFromString(cBuffer);
1775 
1776  // read image data
1777  is.read(reinterpret_cast<char*>(img.ImageData_), img.GetPixelCount() * img.ChannelCount_
1778  * img.Depth_);
1779  break;
1780  case 311: // solved stack corruption problem due to wrong id writing/loading
1781  // std::cout <<"Opening file with version MIP311"<<std::endl;
1782  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1783  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1784  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1785  img.Init(Width, Height, ChannelCount, FileStorageType);
1786  is.read(reinterpret_cast<char*>(&img.ColorModel_), sizeof(BIAS::ImageBase::EColorModel));
1787  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1788  img.Depth_ /= 8;
1789  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1790  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1791  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1792  {
1793  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1794  is.read(reinterpret_cast<char*>(&UpperLeftX), sizeof(unsigned int));
1795  is.read(reinterpret_cast<char*>(&UpperLeftY), sizeof(unsigned int));
1796  is.read(reinterpret_cast<char*>(&LowerRightX), sizeof(unsigned int));
1797  is.read(reinterpret_cast<char*>(&LowerRightY), sizeof(unsigned int));
1798  is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1799  // not necessary
1800  //img.GetROI()->Resize(Width, Height);
1801  if (roidefined)
1802  img.GetROI()->SetCorners(UpperLeftX, UpperLeftY,
1803  LowerRightX, LowerRightY);
1804  }
1805  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftX_), sizeof(unsigned int));
1806  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftY_), sizeof(unsigned int));
1807  // is.read(reinterpret_cast<char*>(&img.ROILowerRightX_), sizeof(unsigned int));
1808  // is.read(reinterpret_cast<char*>(&img.ROILowerRightY_), sizeof(unsigned int));
1809  // is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1810  // if (!roidefined){
1811  // img.ROIUpperLeftX_=img.ROIUpperLeftY_=0;
1812  // img.ROILowerRightX_=img.Width_; img.ROILowerRightY_=img.Height_;
1813  // }
1814  // read uid:
1815  is.read(cBuffer, 36);
1816  cBuffer[36]=0;
1817  img._UID.SetFromString(cBuffer);
1818 
1819  // read image data
1820  is.read(reinterpret_cast<char*>(img.ImageData_), img.GetPixelCount() * img.ChannelCount_
1821  * img.Depth_);
1822  break;
1823  case 310: // introduced unique image id in this version
1824  // std::cout <<"Opening file with version MIP310"<<std::endl;
1825  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1826  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1827  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1828  img.Init(Width, Height, ChannelCount, FileStorageType);
1829  is.read(reinterpret_cast<char*>(&img.ColorModel_), sizeof(BIAS::ImageBase::EColorModel));
1830  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1831  img.Depth_ /= 8;
1832  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1833  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1834  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1835  {
1836  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1837  is.read(reinterpret_cast<char*>(&UpperLeftX), sizeof(unsigned int));
1838  is.read(reinterpret_cast<char*>(&UpperLeftY), sizeof(unsigned int));
1839  is.read(reinterpret_cast<char*>(&LowerRightX), sizeof(unsigned int));
1840  is.read(reinterpret_cast<char*>(&LowerRightY), sizeof(unsigned int));
1841  is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1842  // not necessary
1843  //img.GetROI()->Resize(Width, Height);
1844  if (roidefined)
1845  img.GetROI()->SetCorners(UpperLeftX, UpperLeftY,
1846  LowerRightX, LowerRightY);
1847  }
1848  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftX_), sizeof(unsigned int));
1849  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftY_), sizeof(unsigned int));
1850  // is.read(reinterpret_cast<char*>(&img.ROILowerRightX_), sizeof(unsigned int));
1851  // is.read(reinterpret_cast<char*>(&img.ROILowerRightY_), sizeof(unsigned int));
1852  // is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1853  // if (!roidefined){
1854  // img.ROIUpperLeftX_=img.ROIUpperLeftY_=0;
1855  // img.ROILowerRightX_=img.Width_; img.ROILowerRightY_=img.Height_;
1856  // }
1857  // do not read uid:
1858  { /// \bug fake reading of uuid because of bug, id is DISABLED !
1859  char *tmp=new char[sizeof(UUID)];
1860  is.read(tmp, sizeof(UUID));
1861  delete[] tmp;
1862  BIASERR("Cannot read image id in MIP version 310.");
1863  }
1864 
1865  // read image data
1866  is.read(reinterpret_cast<char*>(img.ImageData_), img.GetPixelCount() * img.ChannelCount_
1867  * img.Depth_);
1868  break;
1869  case 300:
1870  //std::cout <<"Opening file with version MIP300"<<std::endl;
1871  is.read(reinterpret_cast<char*>(&ChannelCount), sizeof(int));
1872  is.read(reinterpret_cast<char*>(&Width), sizeof(int));
1873  is.read(reinterpret_cast<char*>(&Height), sizeof(int));
1874  img.Init(Width, Height, ChannelCount, FileStorageType);
1875  is.read(reinterpret_cast<char*>(&img.ColorModel_), sizeof(BIAS::ImageBase::EColorModel));
1876  is.read(reinterpret_cast<char*>(&img.Depth_), sizeof(int));
1877  img.Depth_ /= 8;
1878  is.read(reinterpret_cast<char*>(&img.InterleavedDataOrder_), sizeof(bool));
1879  is.read(reinterpret_cast<char*>(&PixelCount), sizeof(int));
1880  is.read(reinterpret_cast<char*>(&img.WidthStep_), sizeof(int));
1881  {
1882  unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1883  is.read(reinterpret_cast<char*>(&UpperLeftX), sizeof(unsigned int));
1884  is.read(reinterpret_cast<char*>(&UpperLeftY), sizeof(unsigned int));
1885  is.read(reinterpret_cast<char*>(&LowerRightX), sizeof(unsigned int));
1886  is.read(reinterpret_cast<char*>(&LowerRightY), sizeof(unsigned int));
1887  is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1888  // not necessary
1889  //img.GetROI()->Resize(Width, Height);
1890  if (roidefined)
1891  img.GetROI()->SetCorners(UpperLeftX, UpperLeftY,
1892  LowerRightX, LowerRightY);
1893  }
1894  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftX_), sizeof(unsigned int));
1895  // is.read(reinterpret_cast<char*>(&img.ROIUpperLeftY_), sizeof(unsigned int));
1896  // is.read(reinterpret_cast<char*>(&img.ROILowerRightX_), sizeof(unsigned int));
1897  // is.read(reinterpret_cast<char*>(&img.ROILowerRightY_), sizeof(unsigned int));
1898  // is.read(reinterpret_cast<char*>(&roidefined), sizeof(bool));
1899  // if (!roidefined){
1900  // img.ROIUpperLeftX_=img.ROIUpperLeftY_=0;
1901  // img.ROILowerRightX_=img.Width_; img.ROILowerRightY_=img.Height_;
1902  // }
1903  // img.PrintHeader(cerr);
1904  // cerr << endl << "size to read "<< img.PixelCount_ * img.ChannelCount_ * img.Depth_<< endl;
1905  is.read(reinterpret_cast<char*>(img.ImageData_), img.GetPixelCount() * img.ChannelCount_
1906  * img.Depth_);
1907  break;
1908  default:
1909  BIASERR("operator>> invalid or unsupported version number ("<<Version
1910  <<")\ntry mipconvertversion in Image/test");
1911 
1912  break;
1913  }
1914  return is;
1915  }
1916 
1917 
1918 
1920  const unsigned int x,
1921  const unsigned int y,
1922  const unsigned short channel,
1923  std::ostream & os)
1924 {
1925  // determine storage type
1926  switch ( im.GetStorageType())
1927  {
1929  const Image<unsigned char> *
1930  p = static_cast< const Image<unsigned char> * >(&im);
1931  BIASASSERT(p!=NULL);
1932  os<<(int)p->PixelValue(x,y,channel);
1933  break; }
1934 
1935  case ImageBase::ST_float: {
1936  const Image<float> *
1937  p = static_cast< const Image<float> * >(&im);
1938  BIASASSERT(p!=NULL);
1939  os<<(float)p->PixelValue(x,y,channel);
1940  break; }
1941 
1942 #ifdef BUILD_IMAGE_DOUBLE
1943  case ImageBase::ST_double: {
1944  const Image<double> *
1945  p = static_cast< const Image<double> * >(&im);
1946  BIASASSERT(p!=NULL);
1947  os<<(double)p->PixelValue(x,y,channel);
1948  break; }
1949 #endif
1950 
1951 
1952 #ifdef BUILD_IMAGE_INT
1953  case ImageBase::ST_int: {
1954  const Image<int> *
1955  p = static_cast< const Image<int> * >(&im);
1956  BIASASSERT(p!=NULL);
1957  os<<(int)p->PixelValue(x,y,channel);
1958  break; }
1959 #endif
1960 
1961 #ifdef BUILD_IMAGE_UINT
1963  const Image<unsigned int> *
1964  p = static_cast< const Image<unsigned int> * >(&im);
1965  BIASASSERT(p!=NULL);
1966  os<<(int)p->PixelValue(x,y,channel);
1967  break; }
1968 #endif
1969 
1970 #ifdef BUILD_IMAGE_SHORT
1971  case ImageBase::ST_shortint: {
1972  const Image<short> *
1973  p = static_cast< const Image<short> * >(&im);
1974  BIASASSERT(p!=NULL);
1975  os<<(int)p->PixelValue(x,y,channel);
1976  break; }
1977 #endif
1978 
1979 #ifdef BUILD_IMAGE_USHORT
1981  const Image<unsigned short> *
1982  p = static_cast< const Image<unsigned short> * >(&im);
1983  BIASASSERT(p!=NULL);
1984  os<<(int)p->PixelValue(x,y,channel);
1985  break; }
1986 #endif
1987 
1988 #ifdef BUILD_IMAGE_CHAR // signed!
1989  case ImageBase::ST_char: {
1990  const Image<char> *
1991  p = static_cast< const Image<char> * >(&im);
1992  BIASASSERT(p!=NULL);
1993  os<<(int)p->PixelValue(x,y,channel);
1994  break; }
1995 #endif
1996 
1997  default:
1998  {
1999  BIASERR("unknown StorageType "<<im.GetStorageType()<<"detected");
2000  os<<"?";
2001  }
2002  };
2003 }
2004 
2005 
2006 #ifdef BIAS_HAVE_OPENEXR
2008  const unsigned int channelId,
2009  half* channelOut)
2010 {
2011  // BIASASSERT(im.IsInterleaved());
2012  unsigned int C = im.GetChannelCount();
2013  unsigned int width = im.GetWidth();
2014  unsigned int height = im.GetHeight();
2015  switch ( im.GetStorageType())
2016  {
2018  if (im.IsInterleaved()) {
2019  unsigned char** p = (unsigned char**)im.GetImageDataArray();
2020  for(unsigned int y=0; y<height; y++) {
2021  for(unsigned int x=0; x<width; x++) {
2022  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2023  }
2024  }
2025  } else {
2026  unsigned char const *data = reinterpret_cast<unsigned char const *>(im.GetImageData());
2027  unsigned char const *start = &data[channelId * width * height];
2028  unsigned char const *end = &data[(channelId + 1) * width * height];
2029  std::copy(start, end, channelOut);
2030  }
2031  break; }
2032 
2034  if (im.IsInterleaved()) {
2035  float** p = (float**)im.GetImageDataArray();
2036  for(unsigned int y=0; y<height; y++) {
2037  for(unsigned int x=0; x<width; x++) {
2038  channelOut[y*width+x] = p[y][x*C+channelId];
2039  }
2040  }
2041  } else {
2042  float const *data = reinterpret_cast<float const *>(im.GetImageData());
2043  float const *start = &data[channelId * width * height];
2044  float const *end = &data[(channelId + 1) * width * height];
2045  std::copy(start, end, channelOut);
2046  }
2047  break; }
2048 
2049 #ifdef BUILD_IMAGE_DOUBLE
2051  if (im.IsInterleaved()) {
2052  double** p = (double**)im.GetImageDataArray();
2053  for(unsigned int y=0; y<height; y++) {
2054  for(unsigned int x=0; x<width; x++) {
2055  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2056  }
2057  }
2058  } else {
2059  double const *data = reinterpret_cast<double const *>(im.GetImageData());
2060  double const *start = &data[channelId * width * height];
2061  double const *end = &data[(channelId + 1) * width * height];
2062  std::copy(start, end, channelOut);
2063  }
2064  break; }
2065 #endif
2066 
2067 
2068 #ifdef BUILD_IMAGE_INT
2069  case BIAS::ImageBase::ST_int: {
2070  if (im.IsInterleaved()) {
2071  int** p = (int**)im.GetImageDataArray();
2072  for(unsigned int y=0; y<height; y++) {
2073  for(unsigned int x=0; x<width; x++) {
2074  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2075  }
2076  }
2077  } else {
2078  int const *data = reinterpret_cast<int const *>(im.GetImageData());
2079  int const *start = &data[channelId * width * height];
2080  int const *end = &data[(channelId + 1) * width * height];
2081  std::copy(start, end, channelOut);
2082  }
2083  break; }
2084 #endif
2085 
2086 #ifdef BUILD_IMAGE_UINT
2088  if (im.IsInterleaved()) {
2089  unsigned int** p = (unsigned int**)im.GetImageDataArray();
2090  for(unsigned int y=0; y<height; y++) {
2091  for(unsigned int x=0; x<width; x++) {
2092  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2093  }
2094  }
2095  } else {
2096  unsigned int const *data = reinterpret_cast<unsigned int const *>(im.GetImageData());
2097  unsigned int const *start = &data[channelId * width * height];
2098  unsigned int const *end = &data[(channelId + 1) * width * height];
2099  std::copy(start, end, channelOut);
2100  }
2101 
2102  break; }
2103 #endif
2104 
2105 #ifdef BUILD_IMAGE_SHORT
2107  if (im.IsInterleaved()) {
2108  short** p = (short**)im.GetImageDataArray();
2109  for(unsigned int y=0; y<height; y++) {
2110  for(unsigned int x=0; x<width; x++) {
2111  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2112  }
2113  }
2114  } else {
2115  short const *data = reinterpret_cast<short const *>(im.GetImageData());
2116  short const *start = &data[channelId * width * height];
2117  short const *end = &data[(channelId + 1) * width * height];
2118  std::copy(start, end, channelOut);
2119  }
2120  break; }
2121 #endif
2122 
2123 #ifdef BUILD_IMAGE_USHORT
2125  if (im.IsInterleaved()) {
2126  unsigned short** p = (unsigned short**)im.GetImageDataArray();
2127  for(unsigned int y=0; y<height; y++) {
2128  for(unsigned int x=0; x<width; x++) {
2129  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2130  }
2131  }
2132  } else {
2133  unsigned short const *data = reinterpret_cast<unsigned short const *>(im.GetImageData());
2134  unsigned short const *start = &data[channelId * width * height];
2135  unsigned short const *end = &data[(channelId + 1) * width * height];
2136  std::copy(start, end, channelOut);
2137  }
2138  break; }
2139 #endif
2140 
2141 #ifdef BUILD_IMAGE_CHAR // signed!
2142  case BIAS::ImageBase::ST_char: {
2143  if (im.IsInterleaved()) {
2144  char** p = (char**)im.GetImageDataArray();
2145  for(unsigned int y=0; y<height; y++) {
2146  for(unsigned int x=0; x<width; x++) {
2147  channelOut[y*width+x] = static_cast<float>(p[y][x*C+channelId]);
2148  }
2149  }
2150  } else {
2151  char const *data = reinterpret_cast<char const *>(im.GetImageData());
2152  char const *start = &data[channelId * width * height];
2153  char const *end = &data[(channelId + 1) * width * height];
2154  std::copy(start, end, channelOut);
2155  }
2156 
2157  break; }
2158 #endif
2159 
2160  default:
2161  {
2162  BIASERR("unknown StorageType "<<im.GetStorageType()<<"detected");
2163  }
2164  };
2165 
2166 }
2167 #endif
2168 
2169 
2170 } // end namespace
int GetCopyOfROI(ImageBase &copy) const
returns a copy of ROI (a new image) lower right point excluded, only interleaved images ! ...
Definition: ImageBase.cpp:568
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
Definition: ImageBase.hh:133
Bayer_GRBG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:145
void SetBitDepth(unsigned bitdepth)
needed by ImageIO
Definition: ImageBase.hh:581
bool IsPowerOfTwoSize() const
Definition: ImageBase.cpp:940
hsl, similar to HSL but euclidean (h,s) for CNCC
Definition: ImageBase.hh:148
void PrintHeader(std::ostream &os=std::cout) const
Definition: ImageBase.cpp:905
LAB, 3 channels, http://en.wikipedia.org/wiki/Lab_color_space.
Definition: ImageBase.hh:157
unsigned int BitDepth_
relevant bits per pixel per channel
Definition: ImageBase.hh:1062
int Cut2ROI()
reduces image to current ROI, !!! image size changes !!!
Definition: ImageBase.cpp:646
void GetString(std::string &sUUID) const
writes the UUID into a string object
Definition: UUID.cpp:366
class for handling different region of interest (ROI) representations...
Definition: ROI.hh:118
static unsigned int PowerOfTwoSize(const unsigned int &val)
Definition: ImageBase.cpp:971
(16bit) unsigned integer image storage type
Definition: ImageBase.hh:114
enum EStorageType StorageType_
the storage type in a pixel channel
Definition: ImageBase.hh:1056
unsigned int GetDepth() const
returns the bytes per channel, which is the sizeof(StorageType) Should match GetSizeDepth(GetStorageT...
Definition: ImageBase.hh:328
bool InterleavedDataOrder_
planar or interleaved: planar means we have several image planes, e.g.
Definition: ImageBase.hh:1070
const unsigned int GetROIUpperLeftX() const
deprecated, use GetROI()-&gt;GetCorners()
Definition: ImageBase.cpp:1092
HSL, similar to HSV but space is a double tipped cone.
Definition: ImageBase.hh:147
gray values, 1 channel
Definition: ImageBase.hh:130
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
void Resize(unsigned width, unsigned height)
Resizes parent image.
Definition: ROI.cpp:227
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
Definition: ROI.hh:443
unsigned int Depth_
size of one channel of one pixel in bytes
Definition: ImageBase.hh:1060
void Release()
Deletes internal memory, sets mask and vector invalid.
Definition: ROI.cpp:141
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
Definition: ImageBase.cpp:827
virtual ~ImageBase()
Definition: ImageBase.cpp:42
bool IsInterleaved() const
Definition: ImageBase.hh:491
ImageBase & operator=(const ImageBase &Source)
assignment operator, allocates memory structure via Init only if necessary
Definition: ImageBase.cpp:745
DV, color model used for digital video cameras such as Mini-DV.
Definition: ImageBase.hh:140
static const int Version_
version number of imagebase class
Definition: ImageBase.hh:1052
static void PrintPixelValue(const ImageBase &im, const unsigned int x, const unsigned int y, const unsigned short channel=0, std::ostream &os=std::cout)
print the (typed) pixel value to stream.
Definition: ImageBase.cpp:1919
(8bit) signed char image storage type
Definition: ImageBase.hh:113
unsigned int GetWidthStep() const
returns the number of bytes per line
Definition: ImageBase.hh:400
void InitWithForeignData(unsigned int width, unsigned int height, unsigned int nChannels, void *data, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true, const bool shouldRelease=true)
Initialize image size and channels using a foreign data pointer.
Definition: ImageBase.cpp:155
static int GetStorageSizeByte(const unsigned int &width, const unsigned int &height, const unsigned int nChannels, const enum EStorageType storageType)
computes the storage data size in Byte required for a given video format.
Definition: ImageBase.cpp:115
YUV411, 2 channles, full luminance, 1 U, 1 V.
Definition: ImageBase.hh:137
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
unsigned int GetSizeByte() const
returns the nr.
Definition: ImageBase.hh:352
void UnsetROI()
Delete region of interest.
Definition: ROI.cpp:214
void ** ImageDataArray_
array of pointers to the first byte in an image row
Definition: ImageBase.hh:1074
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
float image storage type
Definition: ImageBase.hh:118
static int GetChannelcount(const enum BIAS::ImageBase::EColorModel &colormodel)
get the number of channels corresponding to the enum ColorModel Determines the number of (packed) dat...
Definition: ImageBase.cpp:1366
unsigned int WidthStep_
size of a line in bytes for interleaved, NOT nr . of pixels (but size a line in one plane for planar)...
Definition: ImageBase.hh:1072
bool IsPlanar() const
Definition: ImageBase.hh:484
double image storage type
Definition: ImageBase.hh:119
int ZeroPad(const unsigned int newwidth, const unsigned int newheight, unsigned char bgcolor=0)
backward compatibility interface for Pad.
Definition: ImageBase.cpp:1122
XYZ, 3 channels, http://en.wikipedia.org/wiki/Xyz_color_space.
Definition: ImageBase.hh:156
bool DimensionMatch(const BIAS::ImageBase &other) const
Definition: ImageBase.cpp:985
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetBitDepth() const
returns the bits per channel Is not necessairily 8*sizeof(StorageType), could be fewer bits...
Definition: ImageBase.hh:344
int WriteBinary(std::ostream &os) const
binary output to stream
Definition: ROI.cpp:507
const unsigned int GetROIUpperLeftY() const
deprecated, use GetROI()-&gt;GetCorners()
Definition: ImageBase.cpp:1099
YUV420P, 2 channels, full luminance Y, 1 U, 1 V. Y, U and V are grouped together for better compressi...
Definition: ImageBase.hh:135
Todo: Conflict with YUVU model, what does it do?
Definition: ImageBase.hh:154
const unsigned int GetROILowerRightY() const
deprecated, use GetROI()-&gt;GetCorners()
Definition: ImageBase.cpp:1113
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
Definition: Image.hh:91
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
Definition: ImageBase.hh:152
int GetDebugLevel() const
Definition: Debug.hh:332
const BIAS::UUID & GetUID() const
returns the UUID of the image
Definition: ImageBase.hh:449
bool SetFromString(const std::string &sID)
construct from string containing ascii uuid.
Definition: UUID.cpp:130
void SetInterleaved(bool interleaved)
Definition: ImageBase.hh:568
void GetROICorners(unsigned int &UpperLeftX, unsigned int &UpperLeftY, unsigned int &LowerRightX, unsigned int &LowerRightY) const
access region of interest rectangle JW
Definition: ImageBase.cpp:1067
invalid not set image storage type
Definition: ImageBase.hh:111
void SetStorageType(const EStorageType st)
changes StorageType data mmeber
Definition: ImageBase.hh:1042
BIAS::UUID _UID
unique id for every image
Definition: ImageBase.hh:1078
(16bit) signed integer image storage type
Definition: ImageBase.hh:115
color values, 3 channels, order: blue,green,red
Definition: ImageBase.hh:132
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
const void * GetImageData() const
Definition: ImageBase.hh:280
Disparity images Q: should disp and depth be treated separately, if not what would be a good name to ...
Definition: ImageBase.hh:158
int ReadBinary(std::istream &is)
binary input from stream
Definition: ROI.cpp:573
Bayer_GBRG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:144
int GetChannel(const ImageBase &source, const unsigned int channel)
copies one specific channel from source to Image can only be called from an planar image...
Definition: ImageBase.cpp:428
MetaData _MetaData
additional data block, handled by derived classes
Definition: ImageBase.hh:1080
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
unsigned int Height_
image height in pixels
Definition: ImageBase.hh:1066
int Pad(BIAS::ImageBase &dest, const unsigned int &newwidth, const unsigned int &newheight, const int &padVal=0) const
Definition: ImageBase.cpp:1207
void ReInit(const unsigned int &width, const unsigned int &height, const unsigned int nChannels=1, const enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true, const EColorModel colormodel=CM_Grey)
(Re-)Initialize Image data if required.
Definition: ImageBase.cpp:131
void ** GetImageDataArray() const
Get an array of pointers to image data.
Definition: ImageBase.hh:305
static int GetSizeUnits(const enum BIAS::ImageBase::EColorModel &colormodel)
get the number of (packed) data values of color model E.g: CM_Grey : 1 CM_YUYV422 : 2 packs 3 channel...
Definition: ImageBase.cpp:1329
int StealImage(ImageBase &source)
steals the image data array from source, after releasing the actual image data and sets source image ...
Definition: ImageBase.cpp:395
CM_YUV444, 3 channels, all channels have full data.
Definition: ImageBase.hh:136
bool IsInROI(const double &x, const double &y) const
ROI check if pixel position is inside the ROI.
Definition: ROI.hh:463
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
CIELUV color space, 3 channels, http://en.wikipedia.org/wiki/CIELUV_color_space.
Definition: ImageBase.hh:155
ROI Roi_
roi object
Definition: ImageBase.hh:1082
int Display() const
display image simple signature interface for Debugger usage This function can be used to display an (...
Definition: ImageBase.cpp:1463
void clear()
NULLS the class members, invalidates this UID ( not unique anymore).
Definition: UUID.cpp:93
unsigned int GetHeight() const
Definition: ImageBase.hh:319
int GetCopyOfROI2(ImageBase &copy) const
like GetCopyOfROI, but with lower right point included only interleaved images !
Definition: ImageBase.cpp:535
static void StringToStorageType(const std::string &str, ImageBase::EStorageType &st)
Definition: ImageBase.cpp:1632
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
Definition: ImageBase.hh:134
The image template class for specific storage types.
Definition: Image.hh:78
obsolete, HSI is unused and identical to HSL
Definition: ImageBase.hh:139
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same &quot;size&quot; as Image of other type
Definition: ImageBase.hh:73
void SetOutsideROIZero()
sets all pixel not in ROI to zero
Definition: ImageBase.cpp:675
int SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
deprecated, use SetROICorners()
Definition: ImageBase.cpp:1033
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
long int _liDebugLevel
Definition: Debug.hh:510
SymTensor2x2 The image contains a 2x2 symmetric tensor.
Definition: ImageBase.hh:149
bool shouldReleaseData_
shoud ImageBase release the data pointer?
Definition: ImageBase.hh:1084
RGBA, 4 channels, order: red,green,blue,alpha.
Definition: ImageBase.hh:141
unsigned int ChannelCount_
number of channels per pixel
Definition: ImageBase.hh:1058
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
Definition: ImageBase.cpp:350
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
(32bit) signed integer image storage type
Definition: ImageBase.hh:117
int GetVersionNumber() const
Definition: ImageBase.hh:477
RGBE color values, 4 channels, RADIANCE hdr format, four low dynamic channels meaning: 3x mantissa (r...
Definition: ImageBase.hh:151
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
this class collects all additional data chunks of type AppData to be written into/read from an image ...
Definition: MetaData.hh:121
void ReleaseImageDataPointer()
Releases ImageData_ (to be used together with RedirectImageDataPointer)
Definition: ImageBase.hh:90
static void StringToColorModel(const std::string &str, ImageBase::EColorModel &cm)
Definition: ImageBase.cpp:1595
const unsigned int GetROILowerRightX() const
deprecated, use GetROI()-&gt;GetCorners()
Definition: ImageBase.cpp:1106
invalid (not set) image format
Definition: ImageBase.hh:129
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
class BIASImageBase_EXPORT UUID
forward declaration for stream operators
Definition: UUID.hh:64
HSV, 3 channels, order: hue, sat , value.
Definition: ImageBase.hh:138
int UpdateImageDataArrayFromImageData_()
recomputes pointer array returned by GetImageDataArray
Definition: ImageBase.cpp:302
int Flip()
flips the image vertically (row order is inverted) In place function return 0 in case of success...
Definition: ImageBase.cpp:834
int Paste2ROI(const ImageBase &Image)
paste Image to current ROI
Definition: ImageBase.cpp:603
void * ImageData_
a pointer to the image data
Definition: ImageBase.hh:1076
int PadToPowerOfTwoAndFlip(const int &padVal=0)
first pad, then flip.
Definition: ImageBase.cpp:1282
interface class for producing/storing Universally Unique IDentifiers
Definition: UUID.hh:98
void * PixelValueBase(unsigned x, unsigned y, unsigned channel=0)
Definition: ImageBase.cpp:1019
Todo: Unclear, I think one channel float, why isn&#39;t grey used for that?
Definition: ImageBase.hh:153
wrapper around a BIAS image to be used as an OpenCv IPlimage with shared data area.
Definition: WrapBias2Ipl.hh:26
int SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
Definition: ImageBase.cpp:1048
unsigned long int GetPixelCount() const
returns number of pixels in image
Definition: ImageBase.hh:422
GreyA, 2 channels, grey plus Alpha.
Definition: ImageBase.hh:142
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void RedirectImageDataPointer(void *data)
This method takes data and set the internal image data pointer to this.
Definition: ImageBase.hh:859
void PrintROI(std::ostream &os=std::cout) const
deprecated, use &#39;os &lt;&lt; *GetROI()&#39;
Definition: ImageBase.cpp:1087
int FlipHorizontal()
flips the image horizontal (column order is inverted) In place function return 0 in case of success...
Definition: ImageBase.cpp:878
Depth images A: separated for now.
Definition: ImageBase.hh:159
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.
Definition: ImageBase.cpp:1154
unsigned int Width_
image width in pixels
Definition: ImageBase.hh:1064
enum EColorModel ColorModel_
the color model of the pixels
Definition: ImageBase.hh:1054
bool IsValid() const
checks whether this uuid is valid(true) or unitialized(false)
Definition: UUID.hh:210
static int Display(const IplImage *img, const std::string &DestWin, const bool &autoresize, const bool &moveToTopLeft, const bool &waitForKey, const unsigned int &delayMsec, const float &scale=DEFAULT_32to8_scale, const bool &allowAlphaWindow=ALLOW_ALPHA_WIN_DEFAULT)
Display img as simple popup window.
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157
bool FormatMatch(const BIAS::ImageBase &d) const
Definition: ImageBase.cpp:992
void UnsetROI()
deprecated, use GetROI()-&gt;UnsetROI()
Definition: ImageBase.cpp:1057
BGRA color values, 4 channels, order: blue,green,red,alpha.
Definition: ImageBase.hh:150
(32bit) unsigned integer image storage type
Definition: ImageBase.hh:116