21 #include "ImageBase.hh"
22 #include <Base/Common/W32Compat.hh>
27 # define _USE_MATH_DEFINES
36 using std::stringstream;
44 if (ImageDataArray_ != NULL) {
45 delete[] (
char**)ImageDataArray_;
46 ImageDataArray_ = NULL;
48 if (ImageData_!=NULL && shouldReleaseData_){
49 delete[] (
char*)ImageData_;
57 :
Debug(), Roi_(), shouldReleaseData_(true)
60 BIASGDOUT(D_IMAGE_TRACE,
"called ImageBase::ImageBase()");
80 BIASGDOUT(D_IMAGE_TRACE,
"called ImageBase::ImageBase(const ImageBase& im)");
95 bool interleaved) : shouldReleaseData_(true)
98 BIASGDOUT(D_IMAGE_TRACE,
"called ImageBase::ImageBase(width, height,"
99 <<
" channels, storageType, interleaved ");
108 Init(width,height,channels,storageType);
116 const unsigned int nChannels,
121 const int nPixel = width * height;
122 const int nBytePerPixel = nChannels *
GetSizeByte(storageType);
126 return nPixel * nBytePerPixel;
132 const unsigned int nChannels,
134 const bool interleaved,
138 nChannels, storageType );
141 if (current_nBytes != required_nBytes){
156 unsigned int nChannels,
160 const bool shouldRelease) {
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");
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
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");
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
331 unsigned int tmpstep;
337 BIASERR(
"Congratulations! You found a major bug in BIAS."
338 <<
" Inconsistency in image dimension data.");
342 for (
register unsigned int i=1; i < height; i++) {
355 BIASERR(
"ImageBase::Release called with empty image !");
372 if (reset_storage_type){
397 BIASERR(
"tried to steal empty image");
437 BIASERR(
"ImageConvert<StorageType>::GetChannel() invalid size of image");
439 BIASERR(
"ImageConvert<StorageType>::GetChannel() should be called with one"
442 BIASERR(
"ImageConvert<StorageType>::GetChannel() only makes sense with"
464 BIASERR(
"ImageConvert<StorageType>::GetChannel() invalid Channel");
488 BIASERR(
"ImageConvert<StorageType>::GetChannel() invalid Channel");
494 if ((channel<0) || (channel>2)){
495 BIASERR(
"ImageConvert<StorageType>::GetChannel() invalid Channel");
504 register int depth2=depth<<1;
508 for (
int i=0; i<depth; i++) *dst++=*src++;
515 for (
int i=0; i<depth; i++) *dst++=*src++;
522 for (
int i=0; i<depth; i++) *dst++=*src++;
539 BIASERR(
"only implemented for interleaved images...");
545 int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
547 ROILowerRightX, ROILowerRightY);
549 copy.
Init(ROILowerRightX - ROIUpperLeftX + 1,
558 int length = (ROILowerRightX-ROIUpperLeftX + 1)
560 for (y = ROIUpperLeftY; y <= ROILowerRightY; y++){
561 memcpy(&(dst[y-ROIUpperLeftY][0]),
572 BIASERR(
"only implemented for interleaved images...");
578 int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
580 ROILowerRightX, ROILowerRightY);
583 copy.
Init(ROILowerRightX - ROIUpperLeftX,
595 for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
596 memcpy(&(dst[y-ROIUpperLeftY][0]),
607 BIASERR(
"only implemented for interleaved images...");
611 int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
613 ROILowerRightX, ROILowerRightY);
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 "
626 BIASERR(
"ImageBase::Paste2ROI(): ColorModels do not match, aborting!");
638 for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
640 &(src[y-ROIUpperLeftY][0]),length);
648 int ROIUpperLeftX, ROIUpperLeftY, ROILowerRightX, ROILowerRightY;
650 ROILowerRightX, ROILowerRightY);
652 const int bytesInRow= (ROILowerRightX-ROIUpperLeftX)*
654 char *dst =
new char[(ROILowerRightY - ROIUpperLeftY)*bytesInRow];
660 for (y = ROIUpperLeftY; y < ROILowerRightY; y++){
661 memcpy(dst+(y-ROIUpperLeftY)*bytesInRow, &(src[y][start]),
665 Width_ = ROILowerRightX - ROIUpperLeftX;
666 Height_ = ROILowerRightY - ROIUpperLeftY;
677 switch (
GetROI()->GetROIType()){
684 unsigned ulx, uly, lrx, lry;
688 memset((
void *)
id, 0, size);
693 unsigned left_size, right_offs, right_size, y_offs;
697 for (
unsigned y=uly; y<lry; y++){
699 memset((
void *)(&
id[y_offs]), 0, left_size);
700 memset((
void *)(&
id[y_offs+right_offs]), 0, right_size);
728 for (
unsigned x=0; x<
GetWidth(); x++){
752 BIASGDOUT(D_IMAGE_TRACE,
753 "called ImageBase::operator=(const ImageBase& Source)"
761 bool skipAlloc=
false;
783 BEXCEPTION(
"Can not assign images of different storage type! Call Release(true) on destination image, if this is intented.");
792 if (this->
IsEmpty() && !skipAlloc){
829 BIASDOUT(D_COPYIN,
" entering CopyIn_NoInit()");
837 if (size<=0)
return -1;
839 char *newData = NULL;
842 newData =
new char[size];
851 register char *targetData = newData + size - length;
852 for (
register unsigned int i=0; i <
Height_; i++) {
854 targetData -= length;
858 BIASERR(
"Flip not implemented for planar images.");
881 if (size<=0)
return -1;
883 char *newData =
new char[size];
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;
890 for (
register int x=0; x<(int)
Width_; x++){
891 memcpy(targetData-x*pixelsize, srcData+x*pixelsize, pixelsize);
895 BIASERR(
"FlipHorizontal not implemented for planar images.");
912 <<
"\nWidth_: \t\t" <<
Width_
913 <<
"\nHeight_: \t\t" <<
Height_
916 <<
"\nDepth_: \t\t" <<
Depth_
920 <<
"\nROI: \t" <<
Roi_
921 <<
"\nUUID: \t\t\t"<<
GetUID()
923 os<<
"\nImageData_ ptr: \t\t"
926 os<<
"\nImageDataArray_ ptr: :\t\t"
930 os <<
"\nDebuglevel_:\t" << Debuglevel_;
951 const unsigned int h)
954 return (((w&(w-1))==0) && ((h&(h-1))==0));
977 unsigned int res = 1;
1021 BIASERR(
"warnig, PixelValueBase is deprecated and will be removed in the "
1022 "future,\nuse GetImageDataArray() instead!");
1034 unsigned int LowerRightX,
unsigned int LowerRightY)
1037 UpperLeftX, UpperLeftY,
1038 LowerRightX, LowerRightY);
1049 unsigned int LowerRightX,
unsigned int LowerRightY)
1052 UpperLeftX, UpperLeftY,
1053 LowerRightX, LowerRightY);
1063 unsigned int& LowerRightX,
unsigned int& LowerRightY)
const
1065 GetROICorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1068 unsigned int& LowerRightX,
unsigned int& LowerRightY)
const
1075 int& LowerRightX,
int& LowerRightY)
const
1077 GetROICorners(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY);
1080 int& LowerRightX,
int& LowerRightY)
const
1094 unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1101 unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1108 unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1115 unsigned UpperLeftX, UpperLeftY, LowerRightX, LowerRightY;
1123 const unsigned int newheight,
1124 unsigned char bgcolor )
1126 return this->
Pad(newwidth, newheight, bgcolor );
1133 unsigned int w2, h2;
1155 const int & padVal)
const
1159 BIASERR(
"PadToPowerOfTwo just for interleaved format implemented!");
1164 unsigned int w2, h2;
1174 return Pad(dest, w2, h2, padVal);
1183 const unsigned int & newheight,
1196 int result=
Pad( img, newwidth, newheight, padVal );
1208 const unsigned int & newwidth,
1209 const unsigned int & newheight,
1210 const int & padVal)
const
1215 BIASERR(
"can work on interleaved images, only. Sorry.");
1220 BIASERR(
"can only increase image size. Sorry.");
1224 BIASASSERT(
GetWidth() <= newwidth );
1248 for (
unsigned int ys=0; ys<
GetHeight(); ys++)
1259 if (dest_BytePerRow > src_BytePerRow) {
1265 ,dest_BytePerRow-src_BytePerRow );
1289 BIASERR(
"could not flip. skipped padding.");
1299 switch (storagetype)
1304 return sizeof(char);
1308 return sizeof(
short int);
1315 return sizeof(float);
1318 return sizeof(double);
1323 BIASERR(
"unsupported StorageType:"<<storagetype);
1339 BIASWARN(
"you are possibly treating a HSV/HSL/hsL as RGB.");
1359 BIASERR(
"unsupported/unknown color model "<<colormodel);
1377 BIASWARN(
"you are possibly treating a HSV/HSL/hsL as RGB.");
1402 BIASERR(
"unsupported/unknown color model "<<colormodel);
1408 #ifdef BIAS_HAVE_OPENCV
1410 #include "WrapBias2Ipl.hh"
1415 const bool & autoresize,
1416 const bool & moveToTopLeft,
1417 const bool & waitForKey,
1418 const unsigned int & delayMsec,
1420 const bool & allowAlphaWindow
1453 const unsigned int & delayMsec,
1454 const float &scale )
const
1457 string( DEFAULT_WrapBias2Ipl_WINNAME ),
1459 waitForKey, delayMsec, scale );
1467 DEFAULT_Display_delay,
1471 #endif // BIAS_HAVE_OPENCV
1487 os.write(IDENTIFIER, IDENTIFIER_LENGTH);
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));
1494 depthondisk = img.
Depth_ * 8;
1495 os.write(reinterpret_cast<char*>(& depthondisk),
sizeof(
int));
1496 os.write(reinterpret_cast<char*>(&img.
BitDepth_),
sizeof(
int));
1499 os.write(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1500 os.write(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
1505 # ifdef BIAS_EXTRA_WARN
1507 BIASERR(
"Writing invalid UID! Generate a valid one before writing image !");
1510 # endif //BIAS_EXTRA_WARN
1514 os.write(
id.c_str(), 36);
1516 BIASERR(
"error writing ROI");
1546 default: os<<
"unknown StorageType";
break;
1590 default: os<<
"unknown ColorModel";
break;
1651 int Width, Height, ChannelCount, PixelCount;
1652 char identifier[IDENTIFIER_LENGTH];
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);
1664 is.read(reinterpret_cast<char*>(&FileStorageType),
1672 is.setstate(ios_base::failbit);
1679 is.read(reinterpret_cast<char*>(&Version),
sizeof(
int));
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));
1692 is.read(reinterpret_cast<char*>(&img.
BitDepth_),
sizeof(
int));
1694 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1695 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
1698 is.read(cBuffer, 36);
1702 BIASERR(
"error reading roi");
1705 is.read(reinterpret_cast<char*>(img.
ImageData_),
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));
1718 is.read(reinterpret_cast<char*>(&img.
BitDepth_),
sizeof(
int));
1720 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1721 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
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));
1731 LowerRightX, LowerRightY);
1736 is.read(cBuffer, 36);
1741 is.read(reinterpret_cast<char*>(img.
ImageData_),
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);
1751 is.read(reinterpret_cast<char*>(&img.
Depth_),
sizeof(
int));
1754 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1755 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
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));
1765 LowerRightX, LowerRightY);
1772 is.read(cBuffer, 36);
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);
1787 is.read(reinterpret_cast<char*>(&img.
Depth_),
sizeof(
int));
1790 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1791 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
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));
1803 LowerRightX, LowerRightY);
1815 is.read(cBuffer, 36);
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);
1830 is.read(reinterpret_cast<char*>(&img.
Depth_),
sizeof(
int));
1833 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1834 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
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));
1846 LowerRightX, LowerRightY);
1859 char *tmp=
new char[
sizeof(
UUID)];
1860 is.read(tmp,
sizeof(
UUID));
1862 BIASERR(
"Cannot read image id in MIP version 310.");
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);
1876 is.read(reinterpret_cast<char*>(&img.
Depth_),
sizeof(
int));
1879 is.read(reinterpret_cast<char*>(&PixelCount),
sizeof(
int));
1880 is.read(reinterpret_cast<char*>(&img.
WidthStep_),
sizeof(
int));
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));
1892 LowerRightX, LowerRightY);
1909 BIASERR(
"operator>> invalid or unsupported version number ("<<Version
1910 <<
")\ntry mipconvertversion in Image/test");
1920 const unsigned int x,
1921 const unsigned int y,
1922 const unsigned short channel,
1931 BIASASSERT(p!=NULL);
1938 BIASASSERT(p!=NULL);
1942 #ifdef BUILD_IMAGE_DOUBLE
1946 BIASASSERT(p!=NULL);
1952 #ifdef BUILD_IMAGE_INT
1956 BIASASSERT(p!=NULL);
1961 #ifdef BUILD_IMAGE_UINT
1965 BIASASSERT(p!=NULL);
1970 #ifdef BUILD_IMAGE_SHORT
1974 BIASASSERT(p!=NULL);
1979 #ifdef BUILD_IMAGE_USHORT
1983 BIASASSERT(p!=NULL);
1988 #ifdef BUILD_IMAGE_CHAR // signed!
1992 BIASASSERT(p!=NULL);
1999 BIASERR(
"unknown StorageType "<<im.
GetStorageType()<<
"detected");
2006 #ifdef BIAS_HAVE_OPENEXR
2008 const unsigned int channelId,
2013 unsigned int width = im.
GetWidth();
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]);
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);
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];
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);
2049 #ifdef BUILD_IMAGE_DOUBLE
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]);
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);
2068 #ifdef BUILD_IMAGE_INT
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]);
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);
2086 #ifdef BUILD_IMAGE_UINT
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]);
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);
2105 #ifdef BUILD_IMAGE_SHORT
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]);
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);
2123 #ifdef BUILD_IMAGE_USHORT
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]);
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);
2141 #ifdef BUILD_IMAGE_CHAR // signed!
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]);
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);
2162 BIASERR(
"unknown StorageType "<<im.
GetStorageType()<<
"detected");
int GetCopyOfROI(ImageBase ©) const
returns a copy of ROI (a new image) lower right point excluded, only interleaved images ! ...
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
bool IsPowerOfTwoSize() const
hsl, similar to HSL but euclidean (h,s) for CNCC
void PrintHeader(std::ostream &os=std::cout) const
LAB, 3 channels, http://en.wikipedia.org/wiki/Lab_color_space.
unsigned int BitDepth_
relevant bits per pixel per channel
int Cut2ROI()
reduces image to current ROI, !!! image size changes !!!
void GetString(std::string &sUUID) const
writes the UUID into a string object
class for handling different region of interest (ROI) representations...
static unsigned int PowerOfTwoSize(const unsigned int &val)
(16bit) unsigned integer image storage type
enum EStorageType StorageType_
the storage type in a pixel channel
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.
const unsigned int GetROIUpperLeftX() const
deprecated, use GetROI()->GetCorners()
HSL, similar to HSV but space is a double tipped cone.
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
void Resize(unsigned width, unsigned height)
Resizes parent image.
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...
unsigned int Depth_
size of one channel of one pixel in bytes
void Release()
Deletes internal memory, sets mask and vector invalid.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
bool IsInterleaved() const
ImageBase & operator=(const ImageBase &Source)
assignment operator, allocates memory structure via Init only if necessary
DV, color model used for digital video cameras such as Mini-DV.
static const int Version_
version number of imagebase class
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.
(8bit) signed char image storage type
unsigned int GetWidthStep() const
returns the number of bytes per line
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.
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.
YUV411, 2 channles, full luminance, 1 U, 1 V.
void SetColorModel(EColorModel Model)
unsigned int GetSizeByte() const
returns the nr.
void UnsetROI()
Delete region of interest.
void ** ImageDataArray_
array of pointers to the first byte in an image row
Bayer_RGGB, 1 channel RGB image Bayer tile.
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...
unsigned int WidthStep_
size of a line in bytes for interleaved, NOT nr . of pixels (but size a line in one plane for planar)...
double image storage type
int ZeroPad(const unsigned int newwidth, const unsigned int newheight, unsigned char bgcolor=0)
backward compatibility interface for Pad.
XYZ, 3 channels, http://en.wikipedia.org/wiki/Xyz_color_space.
bool DimensionMatch(const BIAS::ImageBase &other) const
unsigned int GetWidth() const
unsigned int GetBitDepth() const
returns the bits per channel Is not necessairily 8*sizeof(StorageType), could be fewer bits...
int WriteBinary(std::ostream &os) const
binary output to stream
const unsigned int GetROIUpperLeftY() const
deprecated, use GetROI()->GetCorners()
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?
const unsigned int GetROILowerRightY() const
deprecated, use GetROI()->GetCorners()
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.
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
int GetDebugLevel() const
const BIAS::UUID & GetUID() const
returns the UUID of the image
bool SetFromString(const std::string &sID)
construct from string containing ascii uuid.
void SetInterleaved(bool interleaved)
void GetROICorners(unsigned int &UpperLeftX, unsigned int &UpperLeftY, unsigned int &LowerRightX, unsigned int &LowerRightY) const
access region of interest rectangle JW
invalid not set image storage type
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 ...
int ReadBinary(std::istream &is)
binary input from stream
Bayer_GBRG, 1 channel RGB image Bayer tile.
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...
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
int Pad(BIAS::ImageBase &dest, const unsigned int &newwidth, const unsigned int &newheight, const int &padVal=0) const
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.
void ** GetImageDataArray() const
Get an array of pointers to image data.
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...
int StealImage(ImageBase &source)
steals the image data array from source, after releasing the actual image data and sets source image ...
CM_YUV444, 3 channels, all channels have full data.
bool IsInROI(const double &x, const double &y) const
ROI check if pixel position is inside the ROI.
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.
int Display() const
display image simple signature interface for Debugger usage This function can be used to display an (...
void clear()
NULLS the class members, invalidates this UID ( not unique anymore).
unsigned int GetHeight() const
int GetCopyOfROI2(ImageBase ©) const
like GetCopyOfROI, but with lower right point included only interleaved images !
static void StringToStorageType(const std::string &str, ImageBase::EStorageType &st)
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
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
void SetOutsideROIZero()
sets all pixel not in ROI to zero
int SetROI(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
deprecated, use SetROICorners()
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
SymTensor2x2 The image contains a 2x2 symmetric tensor.
bool shouldReleaseData_
shoud ImageBase release the data pointer?
RGBA, 4 channels, order: red,green,blue,alpha.
unsigned int ChannelCount_
number of channels per pixel
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...
enum EColorModel GetColorModel() const
(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 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.
void ReleaseImageDataPointer()
Releases ImageData_ (to be used together with RedirectImageDataPointer)
static void StringToColorModel(const std::string &str, ImageBase::EColorModel &cm)
const unsigned int GetROILowerRightX() const
deprecated, use GetROI()->GetCorners()
invalid (not set) image format
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
class BIASImageBase_EXPORT UUID
forward declaration for stream operators
HSV, 3 channels, order: hue, sat , value.
int UpdateImageDataArrayFromImageData_()
recomputes pointer array returned by GetImageDataArray
int Flip()
flips the image vertically (row order is inverted) In place function return 0 in case of success...
int Paste2ROI(const ImageBase &Image)
paste Image to current ROI
void * ImageData_
a pointer to the image data
int PadToPowerOfTwoAndFlip(const int &padVal=0)
first pad, then flip.
interface class for producing/storing Universally Unique IDentifiers
void * PixelValueBase(unsigned x, unsigned y, unsigned channel=0)
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.
int SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
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.
void PrintROI(std::ostream &os=std::cout) const
deprecated, use 'os << *GetROI()'
int FlipHorizontal()
flips the image horizontal (column order is inverted) In place function return 0 in case of success...
Depth images A: separated for now.
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.
unsigned int Width_
image width in pixels
enum EColorModel ColorModel_
the color model of the pixels
bool IsValid() const
checks whether this uuid is valid(true) or unitialized(false)
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.
bool FormatMatch(const BIAS::ImageBase &d) const
void UnsetROI()
deprecated, use GetROI()->UnsetROI()
BGRA color values, 4 channels, order: blue,green,red,alpha.
(32bit) unsigned integer image storage type