25 #ifndef _IMAGE_BASE_H_INCLUDED_
26 #define _IMAGE_BASE_H_INCLUDED_
28 #include "bias_config.h"
33 # include <sys/malloc.h>
40 #include <Base/Debug/Debug.hh>
41 #include <Base/Debug/Error.hh>
42 #include <Base/Common/CompareFloatingPoint.hh>
43 #include "MetaData.hh"
47 #ifdef BIAS_HAVE_OPENEXR
49 # pragma warning( push, 1)
50 # define PLATFORM_WINDOWS
54 # pragma warning( pop)
63 #define MIP_DV_WIDTH 500
64 #define MIP_DV_HEIGHT 288
67 #define D_CONVERT 1<<2
68 #define D_CAST_CHECK 1<<3
69 #define D_MI_TOPLANAR 1<<4
70 #define D_MI_IOSTREAM 1<<5
71 #define D_MI_CONVGREY 1<<6
74 #define D_IMAGE_TRACE 1<<25
76 #define VERSION_NUMBER 320
78 #define IDENTIFIER "MIP"
79 #define IDENTIFIER_LENGTH 3
82 #define DEFAULT_32to8_scale 255.0f
84 #define DEFAULT_Display_delay 3000
86 #define DEFAULT_WrapBias2Ipl_WINNAME "WrapBias2Ipl_0"
90 template<
class StorageType>
91 class BIASImageBase_EXPORT
Image;
182 ImageBase(
unsigned int width,
unsigned int height,
unsigned int channels =
184 const bool interleaved =
true);
205 ReInit(
const unsigned int & width,
const unsigned int & height,
206 const unsigned int nChannels = 1,
const enum EStorageType storageType =
207 ST_unsignedchar,
const bool interleaved =
true,
208 const EColorModel colormodel = CM_Grey);
220 void Init(
unsigned int width,
unsigned int height,
unsigned int nChannels=1,
221 enum EStorageType storageType = ST_unsignedchar,
222 const bool interleaved=
true);
237 void InitWithForeignData(
unsigned int width,
unsigned int height,
238 unsigned int nChannels,
240 enum EStorageType storageType = ST_unsignedchar,
241 const bool interleaved =
true,
242 const bool shouldRelease =
true);
246 {
return (ImageData_ == NULL); }
251 void CopyIn_NoInit(
void *data);
263 void Release(
const bool reset_storage_type =
false);
307 return ImageDataArray_;
354 return GetPixelCount() * Depth_ * ChannelCount_;
363 return GetSizeByte();
384 return ChannelCount_;
406 inline enum EColorModel
407 GetColorModel()
const
413 inline enum EStorageType
414 GetStorageType()
const
421 inline unsigned long int
424 return Width_ * Height_;
436 GetPixelPosition(
unsigned int x,
unsigned int y,
437 unsigned short int channel = 0)
const;
445 GetChannel(
const ImageBase & source,
const unsigned int channel);
486 return (!InterleavedDataOrder_);
493 return (InterleavedDataOrder_);
497 friend BIASImageBase_EXPORT
500 friend BIASImageBase_EXPORT
509 PrintPixelValue(
const ImageBase & im,
const unsigned int x,
510 const unsigned int y,
const unsigned short channel = 0,
511 std::ostream & os = std::cout);
519 template<
class castType>
520 static castType GetValue(
const ImageBase & im,
const unsigned int x,
521 const unsigned int y,
const unsigned int channel = 0);
527 template<
class inputType>
528 static void SetValue(
const ImageBase & im,
529 const unsigned int x,
530 const unsigned int y,
531 const unsigned int channel,
532 const inputType val);
538 template<
class inputType>
539 static void SetChannel(
const ImageBase & im,
540 const unsigned int channelId,
541 const inputType* channelIn);
547 template<
class outputType>
548 static void GetChannel(
const ImageBase & im,
549 const unsigned int channelId,
550 outputType* channelOut);
551 #ifdef BIAS_HAVE_OPENEXR
552 static void GetChannel(
const ImageBase & im,
553 const unsigned int channelId,
570 InterleavedDataOrder_ = interleaved;
572 WidthStep_ = Width_ * Depth_ * ChannelCount_;
574 WidthStep_ = Width_ * Depth_;
575 UpdateImageDataArrayFromImageData_();
583 BIASASSERT(bitdepth<=(8*Depth_));
584 BitDepth_ = bitdepth;
628 SetROI(
unsigned int UpperLeftX,
unsigned int UpperLeftY,
629 unsigned int LowerRightX,
unsigned int LowerRightY);
632 SetROI(
const ROI& roi);
636 SetROICorners(
unsigned int UpperLeftX,
unsigned int UpperLeftY,
637 unsigned int LowerRightX,
unsigned int LowerRightY);
645 GetROI(
unsigned int& UpperLeftX,
unsigned int& UpperLeftY,
646 unsigned int& LowerRightX,
unsigned int& LowerRightY)
const;
649 GetROI(
int& UpperLeftX,
int& UpperLeftY,
int& LowerRightX,
650 int& LowerRightY)
const;
654 GetROICorners(
unsigned int& UpperLeftX,
unsigned int& UpperLeftY,
655 unsigned int& LowerRightX,
unsigned int& LowerRightY)
const;
658 GetROICorners(
int& UpperLeftX,
int& UpperLeftY,
int& LowerRightX,
659 int& LowerRightY)
const;
663 PrintROI(std::ostream& os = std::cout)
const;
701 IsInROI(
const double &x,
const double& y)
const
703 return Roi_.IsInROI(x, y);
708 GetROIUpperLeftX()
const;
712 GetROIUpperLeftY()
const;
716 GetROILowerRightX()
const;
720 GetROILowerRightY()
const;
771 return FlipHorizontal();
780 const unsigned int & newheight,
const int & padVal = 0)
const;
784 Pad(
const unsigned int & newwidth,
const unsigned int & newheight,
785 const int & padVal = 0);
791 ZeroPad(
const unsigned int newwidth,
const unsigned int newheight,
792 unsigned char bgcolor = 0);
809 PadToPowerOfTwo(
const int & padVal = 0);
827 PadToPowerOfTwoAndFlip(
const int & padVal = 0);
850 ReleaseImageDataPointer();
862 UpdateImageDataArrayFromImageData_();
874 delete[] ImageDataArray_;
875 ImageDataArray_ = NULL;
880 IsPowerOfTwoSize()
const;
882 IsPowerOfTwoSize(
const unsigned int w,
const unsigned int h);
886 PowerOfTwoSize(
const unsigned int & val);
894 PowerOfTwoSize(
unsigned int & width2,
unsigned int & height2)
const;
897 PixelValueBase(
unsigned x,
unsigned y,
unsigned channel = 0);
900 PrintHeader(std::ostream& os = std::cout)
const;
908 IsPositionInImage(
const int& x,
const int& y)
const;
914 MoveToClosestPositionInImage(
int& x,
int& y)
const;
925 BIASToTextureCoordinates(
const double& biasx,
const double& biasy,
926 double& gl_x,
double& gl_y)
const;
937 TextureToBIASCoordinates(
const double& gl_x,
const double& gl_y,
938 double& biasx,
double& biasy)
const;
977 GetStorageSizeByte(
const unsigned int & width,
const unsigned int & height,
978 const unsigned int nChannels,
const enum EStorageType storageType
981 #ifdef BIAS_HAVE_OPENCV
995 Display(
const std::string & DestWin,
const bool & autoresize,
996 const bool & moveToTopLeft,
const bool & waitForKey,
997 const unsigned int & delayMsec = DEFAULT_Display_delay,
998 const float & scale = DEFAULT_32to8_scale,
999 const bool & allowAlphaWindow =
false)
const;
1006 Display(
const std::string & DestWin)
const;
1010 Display(
const bool & waitForKey,
const unsigned int & delayMsec,
1011 const float &scale)
const;
1023 #endif // BIAS_HAVE_OPENCV
1025 static void StringToColorModel(
const std::string& str,
1027 static void StringToStorageType(
const std::string& str,
1038 UpdateImageDataArrayFromImageData_();
1052 static const int Version_ = VERSION_NUMBER;
1089 BIASImageBase_EXPORT std::ostream&
1091 BIASImageBase_EXPORT std::ostream&
1093 BIASImageBase_EXPORT std::ostream&
1095 BIASImageBase_EXPORT std::istream&
1099 #include "ImageBaseInline.hh"
1104 #endif // _IMAGE_BASE_H_INCLUDED_
EColorModel
These are the most often used color models.
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
Bayer_GRBG, 1 channel RGB image Bayer tile.
void SetBitDepth(unsigned bitdepth)
needed by ImageIO
hsl, similar to HSL but euclidean (h,s) for CNCC
LAB, 3 channels, http://en.wikipedia.org/wiki/Lab_color_space.
unsigned int BitDepth_
relevant bits per pixel per channel
class for handling different region of interest (ROI) representations...
const bool IsInROI(const double &x, const double &y) const
(16bit) unsigned integer image storage type
Routines for loading and writing all kinds of image formats.
unsigned int GetDepth() const
returns the bytes per channel, which is the sizeof(StorageType) Should match GetSizeDepth(GetStorageT...
bool InterleavedDataOrder_
planar or interleaved: planar means we have several image planes, e.g.
HSL, similar to HSV but space is a double tipped cone.
unsigned int Depth_
size of one channel of one pixel in bytes
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
bool IsInterleaved() const
DV, color model used for digital video cameras such as Mini-DV.
(8bit) signed char image storage type
unsigned int GetWidthStep() const
returns the number of bytes per line
Othe's principle component generalization for RGB based segmentation.
YUV411, 2 channles, full luminance, 1 U, 1 V.
void SetColorModel(EColorModel Model)
int Mirror()
interface for the above JW
unsigned int GetSizeByte() const
returns the nr.
void ** ImageDataArray_
array of pointers to the first byte in an image row
Bayer_RGGB, 1 channel RGB image Bayer tile.
unsigned int WidthStep_
size of a line in bytes for interleaved, NOT nr . of pixels (but size a line in one plane for planar)...
XYZ, 3 channels, http://en.wikipedia.org/wiki/Xyz_color_space.
unsigned int GetWidth() const
unsigned int GetBitDepth() const
returns the bits per channel Is not necessairily 8*sizeof(StorageType), could be fewer bits...
YUV420P, 2 channels, full luminance Y, 1 U, 1 V. Y, U and V are grouped together for better compressi...
Todo: Conflict with YUVU model, what does it do?
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
const BIAS::UUID & GetUID() const
returns the UUID of the image
void SetInterleaved(bool interleaved)
void SetStorageType(const EStorageType st)
changes StorageType data mmeber
BIAS::UUID _UID
unique id for every image
(16bit) signed integer image storage type
color values, 3 channels, order: blue,green,red
Bayer_BGGR, 1 channel RGB image Bayer tile.
const void * GetImageData() const
Disparity images Q: should disp and depth be treated separately, if not what would be a good name to ...
const MetaData * GetMetaData() const
Bayer_GBRG, 1 channel RGB image Bayer tile.
MetaData _MetaData
additional data block, handled by derived classes
ROI * GetROI()
Returns a pointer to the roi object.
unsigned int Height_
image height in pixels
void ** GetImageDataArray() const
Get an array of pointers to image data.
CM_YUV444, 3 channels, all channels have full data.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
CIELUV color space, 3 channels, http://en.wikipedia.org/wiki/CIELUV_color_space.
unsigned int GetHeight() const
class with static functions for converting all kinds of color formats and storage types ...
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
The image template class for specific storage types.
obsolete, HSI is unused and identical to HSL
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
SymTensor2x2 The image contains a 2x2 symmetric tensor.
void InvalidateUID()
sets the image's uid to invalid
void SetUID(const BIAS::UUID &id)
bool shouldReleaseData_
shoud ImageBase release the data pointer?
RGBA, 4 channels, order: red,green,blue,alpha.
unsigned int ChannelCount_
number of channels per pixel
(32bit) signed integer image storage type
int GetVersionNumber() const
RGBE color values, 4 channels, RADIANCE hdr format, four low dynamic channels meaning: 3x mantissa (r...
void ClearDataPointer()
set data pointer to NULL, such that image IsEmpty without deletion of data.
(8bit) unsigned char image storage type
virtual ImageBase * Clone() const
virtual covariant copy constructor which produces the same type of object as the template object (Ima...
const ROI * GetROI() const
HSV, 3 channels, order: hue, sat , value.
void * ImageData_
a pointer to the image data
interface class for producing/storing Universally Unique IDentifiers
void SetMetaData(const MetaData &m)
Todo: Unclear, I think one channel float, why isn't grey used for that?
wrapper around a BIAS image to be used as an OpenCv IPlimage with shared data area.
unsigned long int GetPixelCount() const
returns number of pixels in image
GreyA, 2 channels, grey plus Alpha.
This is the base class for images in BIAS.
void RedirectImageDataPointer(void *data)
This method takes data and set the internal image data pointer to this.
Depth images A: separated for now.
unsigned int GetByteDepth() const
bool operator==(const ImageBase &img) const
comparison operator, based upon the adresses of the actual image data
unsigned int GetSize() const
returns the image size in bytes = count - NOT the dimension DEPRECATED Please use GetSizeByte instead...
unsigned int Width_
image width in pixels
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
BGRA color values, 4 channels, order: blue,green,red,alpha.
(32bit) unsigned integer image storage type