25 #include <Base/Common/W32Compat.hh>
33 #include <Base/Common/BIASpragma.hh>
34 #include <Base/Debug/Error.hh>
38 #pragma warning (disable: 4756)
46 template<
class StorageType>
56 BIASGDOUT(D_IMAGE_TRACE,
"called Image<unsigned char>::Image()");
59 Depth_ =
sizeof(
unsigned char);
69 BIASGDOUT(D_IMAGE_TRACE,
"called Image<float>::Image()");
77 #ifdef BUILD_IMAGE_SHORT
83 Depth_ =
sizeof(
short int);
86 #endif // BUILD_IMAGE_SHORT
89 template<
class StorageType>
93 BIASERR(
"invalid StorageType, necessary instance of image not compiled:"
94 <<PRINTTYPE(StorageType));
103 BIASGDOUT(D_IMAGE_TRACE,
104 "called Image<uchar>::Image(const ImageBase& Source)");
107 Depth_ =
sizeof(
unsigned char);
111 BIASERR(
"You tried to construct Image<unsigned char> from "
124 BIASGDOUT(D_IMAGE_TRACE,
125 "called Image<float>::Image(const ImageBase& Source)");
132 BIASERR(
"You tried to construct Image<float> from "
140 template<
class StorageType>
145 BIASERR(
"You tried to construct Image<"<<PRINTTYPE(StorageType)<<
"> from "
147 <<
". Not implemented for that type. Aborting.");
152 template<
class StorageType>
154 Image(
unsigned int Width,
unsigned int Height,
155 unsigned int channels,
bool interleaved)
157 BIASERR(
"invalid StorageType="<<PRINTTYPE(StorageType));
164 Image(
unsigned int Width,
unsigned int Height,
165 unsigned int Channels,
bool interleaved)
168 BIASGDOUT(D_IMAGE_TRACE,
169 "called Image<uchar>::Image(width,height,channels,interl)");
171 StorageType_ = ST_unsignedchar;
172 ImageBase::Init(Width, Height, Channels, StorageType_, interleaved);
178 Image(
unsigned int Width,
unsigned int Height,
179 unsigned int Channels,
bool interleaved)
182 BIASGDOUT(D_IMAGE_TRACE,
183 "called Image<float>::Image(width,height,channels,interl)");
185 StorageType_ = ST_float;
186 ImageBase::Init(Width, Height, Channels, StorageType_, interleaved);
190 #ifdef BUILD_IMAGE_CHAR
210 BIASERR(
"You tried to construct Image<char> from "
221 Image(
unsigned int Width,
unsigned int Height,
222 unsigned int Channels,
bool interleaved)
224 StorageType_ = ST_char;
230 #ifdef BUILD_IMAGE_USHORT
236 Depth_ =
sizeof(
unsigned short int);
246 Depth_ =
sizeof(
unsigned short int);
250 BIASERR(
"You tried to construct Image<unsigned short int> from "
261 Image(
unsigned int Width,
unsigned int Height,
262 unsigned int Channels,
bool interleaved)
264 StorageType_ = ST_unsignedshortint;
267 #endif // BUILD_IMAGE_USHORT
270 #ifdef BUILD_IMAGE_SHORT
276 Depth_ =
sizeof(
short int);
280 BIASERR(
"You tried to construct Image<short int> from "
291 Image(
unsigned int Width,
unsigned int Height,
292 unsigned int Channels,
bool interleaved)
294 StorageType_ = ST_shortint;
300 #ifdef BUILD_IMAGE_UINT
306 Depth_ =
sizeof(
unsigned int);
316 Depth_ =
sizeof(
unsigned int);
320 BIASERR(
"You tried to construct Image<unsigned int> from "
331 Image(
unsigned int Width,
unsigned int Height,
332 unsigned int Channels,
bool interleaved)
334 StorageType_ = ST_unsignedint;
339 #ifdef BUILD_IMAGE_INT
359 BIASERR(
"You tried to construct Image<int> from "
370 Image(
unsigned int Width,
unsigned int Height,
371 unsigned int Channels,
bool interleaved)
373 StorageType_ = ST_int;
379 #ifdef BUILD_IMAGE_DOUBLE
399 BIASERR(
"You tried to construct Image<double> from "
410 Image(
unsigned int Width,
unsigned int Height,
411 unsigned int Channels,
bool interleaved)
413 StorageType_ = ST_double;
419 template<
class StorageType>
421 Init(
unsigned int Width,
unsigned int Height,
422 unsigned int Channels,
enum EStorageType storType,
bool interleaved)
429 template<
class StorageType>
433 BIASASSERT(ImageData_ != NULL);BIASASSERT(ImageDataArray_ != NULL);
434 os <<
"\nImageData_: \t\t" << (
void *) GetImageData()
435 <<
"\nimageDataArray_: \t" << (
void *) (GetImageDataArray()[0]);
440 template<
class StorageType>
444 BIASASSERT(ImageData_ != NULL);
445 os <<
"\nImageData_: \t\t" << GetImageData() << endl;
446 for (
unsigned long int i = 0; i < GetPixelCount(); i++)
447 os << ((StorageType *) GetImageData())[i] <<
" ";
454 template<
class StorageType>
458 int minx, miny, maxx, maxy, cc = GetChannelCount();
459 GetROI()->GetCorners(minx, miny, maxx, maxy);
462 register int width = (int) GetWidth() * cc, step = width - maxx + minx;
464 register StorageType *p = GetImageData() + width * miny + minx;
466 register StorageType *le = GetImageData() + width * miny + maxx;
468 register StorageType *e = GetImageData() + width * (maxy - 1) + maxx;
484 template<
class StorageType>
488 int minx, miny, maxx, maxy, i;
489 register int cc = GetChannelCount();
490 GetROI()->GetCorners(minx, miny, maxx, maxy);
495 register int width = (int) GetWidth() * cc, step = width - maxx
498 register StorageType *p = GetImageData() + width * miny + minx;
500 register StorageType *le = GetImageData() + width * miny + maxx;
502 register StorageType *e = GetImageData() + width * (maxy - 1) + maxx;
508 for (i = 0; i < cc; i++)
518 for (
int i = 0; i < cc; i++)
520 register int width = (int) GetWidth(), step = width - maxx + minx;
522 register StorageType *p = GetImageData() + i * GetPixelCount()
523 + width * miny + minx;
525 register StorageType *le = GetImageData() + i * GetPixelCount()
526 + width * miny + maxx;
528 register StorageType *e = GetImageData() + i * GetPixelCount()
529 + width * (maxy - 1) + maxx;
545 template<
class StorageType>
549 int minx=0, miny=0, maxx=0, maxy=0, i=0;
550 register int cc = GetChannelCount();
551 GetROI()->GetCorners(minx, miny, maxx, maxy);
556 register int width = (int) GetWidth() * cc, step = width - maxx + minx;
558 register StorageType *p = GetImageData() + width * miny + minx + channel;
560 register StorageType *le = GetImageData() + width * miny + maxx;
562 register StorageType *e = GetImageData() + width * (maxy - 1) + maxx;
580 register int width = (int) GetWidth(), step = width - maxx + minx;
582 register StorageType *p = GetImageData() + i * GetPixelCount()
583 + width * miny + minx;
585 register StorageType *le = GetImageData() + i * GetPixelCount()
586 + width * miny + maxx;
588 register StorageType *e = GetImageData() + i * GetPixelCount()
589 + width * (maxy - 1) + maxx;
606 template<
class StorageType>
610 StorageType *p = GetImageData();
612 for (
unsigned int y = 0; y < GetHeight(); y++)
614 for (
unsigned int x = 0; x < GetWidth(); x++)
616 p[y * GetWidth() + x] = StorageType(x);
621 template<
class StorageType>
627 register const unsigned cc = GetChannelCount();
628 register unsigned int i;
629 double *sum =
new double[cc];
630 for (i = 0; i < cc; i++)
632 int minx, miny, maxx, maxy;
633 GetROI()->GetCorners(minx, miny, maxx, maxy);
634 register double pc = (double) ((maxx - minx) * (maxy - miny));
637 register int width = (int) GetWidth() * cc, step = width - maxx
640 register StorageType *p = GetImageData() + width * miny + minx;
642 register StorageType *le = GetImageData() + width * miny + maxx;
644 register StorageType *e = GetImageData() + width * (maxy - 1) + maxx;
650 for (i = 0; i < cc; i++)
651 sum[i] += (
double) p[i];
658 for (i = 0; i < cc; i++)
659 mean[i] = (StorageType)(sum[i] / pc);
664 BIASERR(
"GetMeanPixelValue not implemented for planar images ");
669 template<
class StorageType>
672 const StorageType ignoreStart,
const StorageType ignoreEnd)
const
676 register const unsigned cc = GetChannelCount();
677 register unsigned int i;
678 double *sum =
new double[cc];
679 double *pc =
new double[cc];
680 for (i = 0; i < cc; i++){
685 int minx, miny, maxx, maxy;
686 GetROI()->GetCorners(minx, miny, maxx, maxy);
689 register int width = (int) GetWidth() * cc, step = width - maxx + minx;
691 const register StorageType *p = GetImageData() + width * miny + minx;
693 const register StorageType *le = GetImageData() + width * miny + maxx;
695 const register StorageType *e = GetImageData() + width * (maxy - 1) + maxx;
701 for (i = 0; i < cc; i++){
702 if(p[i] < ignoreStart || p[i] > ignoreEnd){
703 sum[i] += (double) p[i];
713 for (i = 0; i < cc; i++)
714 mean[i] = (StorageType)(sum[i] / pc[i]);
719 BIASERR(
"GetMeanPixelValue not implemented for planar images ");
725 template<
class StorageType>
728 StorageType& max,
const StorageType ignoreStart,
729 const StorageType ignoreEnd,
const unsigned short int channel)
const
734 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() image is empty");
736 if (channel> (GetChannelCount() - 1))
737 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() invalid channel");
741 if (GetChannelCount()!=1)
743 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() not yet implemented for interleaved multi channel images");
744 BIASERR(
"ChannelCount: "<<GetChannelCount());
745 BIASERR(
"IsPlanar: "<<IsPlanar() );
748 unsigned minx, miny, maxx, maxy;
749 GetROI()->GetCorners(minx, miny, maxx, maxy);
750 if (minx!=0 || miny!=0 || maxx!=GetWidth() || maxy!=GetHeight())
751 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() not implemented for ROI!");
757 const StorageType *p_act, *p_end;
759 p_act = GetImageData() + channel * GetPixelCount();
760 p_end = p_act + GetPixelCount();
763 bool foundInRange =
false;
764 while ((!foundInRange) && (p_act != p_end))
766 if((*p_act < ignoreStart) || (*p_act > ignoreEnd))
775 if(!foundInRange)
return foundInRange;
778 for (; p_act != p_end; p_act++)
784 if ((*p_act < ignoreStart) || (*p_act > ignoreEnd))
789 else if (*p_act > max)
791 if((*p_act < ignoreStart) || (*p_act > ignoreEnd))
800 template<
class StorageType>
803 unsigned short int channel,
unsigned int *mincoo,
unsigned int *maxcoo)
const
805 register int ChannelCount = GetChannelCount();
810 BIASERR(
"Image<StorageType>::GetMinMaxPixelValue() image is empty");
811 if (channel> (ChannelCount - 1))
812 BIASERR(
"Image<StorageType>::GetMinMaxPixelValue() inavlid channel");
813 if ( (GetColorModel() != CM_RGB) && (GetColorModel() != CM_BGR) &&
814 (GetColorModel() != CM_Grey) && (GetColorModel() != CM_HSV) &&
815 (GetColorModel() != CM_RGBA) &&
816 (GetColorModel() != CM_Bayer_RGGB) &&
817 (GetColorModel() != CM_Bayer_GBRG) &&
818 (GetColorModel() != CM_Bayer_GRBG) &&
819 (GetColorModel() != CM_Bayer_BGGR) &&
820 (GetColorModel() != CM_Depth) &&
821 (GetColorModel() != CM_DepthAndVariance) &&
822 (GetColorModel() != CM_Disparity))
823 BIASERR(
"Image<StorageType>::GetMinMaxPixelValue() not implemented"
824 <<
" for this colormodel");
826 unsigned minx, miny, maxx, maxy;
827 GetROI()->GetCorners(minx, miny, maxx, maxy);
828 const StorageType **ida = GetImageDataArray();
832 BIASCDOUT(D_IMAGE_MINMAXCOO,
" interleaved ("<<minx<<
", "<<miny<<
") <--> ("
833 <<maxx<<
", "<<maxy<<
")\n");
834 unsigned cc = ChannelCount;
835 BIASASSERT(ida[miny]!=NULL);
836 min = max = ida[miny][minx * cc + channel];
837 const unsigned mmaxx = maxx * cc;
838 if (mincoo != NULL || maxcoo != NULL)
840 BIASCDOUT(D_IMAGE_MINMAXCOO,
"remember coordinates\n");
851 for (
unsigned y = miny; y < maxy; y++)
853 for (
unsigned x = minx * cc + channel; x < mmaxx; x += cc)
860 maxcoo[0] = (x - channel) / cc;
864 else if (ida[y][x] < min)
869 mincoo[0] = (x - channel) / cc;
878 BIASCDOUT(D_IMAGE_MINMAXCOO,
"don't remember coordinates\n");
879 for (
unsigned y = miny; y < maxy; y++)
881 BIASASSERT(ida[y]!=NULL);
882 for (
unsigned x = minx * cc + channel; x < mmaxx; x += cc)
896 BIASCDOUT(D_IMAGE_MINMAXCOO,
" planar ("<<minx<<
", "<<miny<<
") <--> ("
897 <<maxx<<
", "<<maxy<<
")\n");
898 const StorageType *start = GetImageData() + channel * GetPixelCount()
899 + miny * GetWidth() + minx;
900 const StorageType *mendl = start + maxx - minx;
901 const StorageType *end = GetImageData() + channel * GetPixelCount()
902 + (maxy - 1) * GetWidth() + maxx;
903 int step = (int) GetWidth() - (int) maxx + (
int) minx;
906 const int width = (int) GetWidth();
908 BIASCDOUT(D_IMAGE_MINMAXCOO,
"starting with min: "<< (
int)min <<
"\tmax: "
910 if (mincoo != NULL || maxcoo != NULL)
912 BIASCDOUT(D_IMAGE_MINMAXCOO,
"remember coordinates\n");
925 while (start < mendl)
937 else if (*start < min)
957 BIASCDOUT(D_IMAGE_MINMAXCOO,
"don't remember coordinates\n");
960 while (start < mendl)
964 else if (*start < min)
975 template<
class StorageType>
978 unsigned int *coo)
const
980 StorageType min, max;
983 GetMinMaxPixelValue(min, max, channel);
987 unsigned int maxcoo[2];
988 GetMinMaxPixelValue(min, max, channel, coo, maxcoo);
993 template<
class StorageType>
996 unsigned int *coo)
const
998 StorageType min, max;
1001 GetMinMaxPixelValue(min, max, channel);
1005 unsigned int mincoo[2];
1006 GetMinMaxPixelValue(min, max, channel, mincoo, coo);
1011 template<
class StorageType>
1016 StorageType *p = GetImageData();
1017 unsigned int count = GetPixelCount() * GetChannelCount();
1018 for (
register int i = count; i > 0; i--)
1020 *p = (*p > Threshold) ? *p : Value;
1026 template<
class StorageType>
1031 StorageType *p = GetImageData();
1032 unsigned int count = GetPixelCount() * GetChannelCount();
1033 for (
register int i = count; i > 0; i--)
1035 *p = (*p < Threshold) ? *p : Value;
1041 template<
class StorageType>
1045 StorageType *ptr, *end;
1046 ptr = end = GetImageData();
1047 end += GetPixelCount();
1050 *ptr = (*ptr > threshold) ? (MaxSTValue()) : (MinSTValue());
1055 template<
class StorageType>
1059 this->Binarize(threshold);
1062 template<
class StorageType>
1066 register StorageType *ImageData = GetImageData();
1067 register StorageType *ImageDataEnd = ImageData + GetPixelCount()
1068 * GetChannelCount();
1069 while (ImageData < ImageDataEnd)
1071 *ImageData = (StorageType)(((
double) (*ImageData) + Shift) * Scale);
1077 template<
class StorageType>
1080 unsigned int channel)
1082 StorageType *ImageData = GetImageData();
1083 StorageType *ImageDataEnd = ImageData + GetPixelCount()
1084 * GetChannelCount();
1086 if (channel >= GetChannelCount())
1088 BIASERR(
"Not enough channels.");
1094 ImageData += GetPixelCount() * channel;
1095 while (ImageData < ImageData + GetPixelCount() * (channel + 1))
1097 *ImageData = (StorageType)(((
double) (*ImageData) + Shift)
1104 ImageData += channel;
1105 while (ImageData < ImageDataEnd)
1107 *ImageData = (StorageType)(((
double) (*ImageData) + Shift)
1109 ImageData += GetChannelCount();
1116 template<
class StorageType>
1120 register double Scale, Shift;
1121 int res = CalcScaleShift(Min, Max, Scale, Shift);
1124 BIASWARNONCE(
"Cannot scale-shift, error in determining numbers.");
1127 res = ScaleShift(Scale, Shift);
1131 template<
class StorageType>
1136 int width = GetWidth();
1137 int height = GetHeight();
1138 int channels = GetChannelCount();
1143 result.
Init(height, width, channels);
1146 for (
int x = 0; x < width; x++)
1148 for (
int y = 0; y < height; y++)
1150 for (
unsigned short ch = 0; ch < channels; ch++)
1152 StorageType val = PixelValue(x, y, ch);
1161 template<
class StorageType>
1165 unsigned width = GetWidth();
1166 unsigned height = GetHeight();
1167 unsigned channels = GetChannelCount();
1171 else if (
typeid(StorageType) ==
typeid(
unsigned char))
1172 max = (StorageType)(UCHAR_MAX);
1173 else if(
typeid(StorageType) ==
typeid(float))
1174 max = StorageType(FLT_MAX);
1175 #ifdef BUILD_IMAGE_INT
1176 else if(
typeid(StorageType) ==
typeid(
int))
1177 max = StorageType(INT_MAX);
1179 #ifdef BUILD_IMAGE_CHAR
1180 else if(
typeid(StorageType) ==
typeid(
char))
1181 max = StorageType(CHAR_MAX);
1183 #ifdef BUILD_IMAGE_SHORT
1184 else if(
typeid(StorageType) ==
typeid(
short))
1185 max = (StorageType)(SHRT_MAX);
1187 #if defined(BUILD_IMAGE_USHORT)
1188 else if(
typeid(StorageType) ==
typeid(
unsigned short))
1189 max = (StorageType)(USHRT_MAX);
1191 #ifdef BUILD_IMAGE_DOUBLE
1192 else if(
typeid(StorageType) ==
typeid(double))
1193 max = (StorageType)(DBL_MAX);
1195 #ifdef BUILD_IMAGE_UINT
1196 else if(
typeid(StorageType) ==
typeid(
unsigned int))
1197 max = (StorageType)(UINT_MAX);
1206 inverted.
Init(height, width, channels);
1208 StorageType ** ida = GetImageDataArray();
1210 for (
unsigned int y = 0; y < height; y++){
1211 for (
unsigned int x = 0; x < width; x++){
1212 for (
unsigned int c = 0; c < channels; c++){
1213 idaRes[y][x] = max - ida[y][x];
1220 template<
class StorageType>
1223 double &Shift)
const
1225 StorageType min = 0, max = 0, MinVal = 0, MaxVal = 0;
1226 GetMinMaxPixelValue(MinVal, MaxVal, 0);
1227 for (
unsigned int i = 1; i < GetChannelCount(); i++)
1229 GetMinMaxPixelValue(min, max, (
unsigned short) i);
1240 if ((MaxVal - MinVal) == 0)
1242 BIASWARNONCE(
"Image<StorageType>::CalcScaleShift(): minimum pixelvalue is"
1243 <<
" equal to maximum pixel value -> no scaling possible");
1246 Scale = (double) (Max - Min) / (double) (MaxVal - MinVal);
1247 Shift = (double) (Min - MinVal);
1252 template<
class StorageType>
1255 StorageType MinValue, StorageType MaxValue)
1257 if (GetChannelCount() != 1)
1260 BIASERR(
"Image<StorageType>::BinaryThreshold(): only greyscale images supported");
1264 StorageType** dat = GetImageDataArray();
1267 unsigned minY = GetROIUpperLeftY();
1268 unsigned uppboundY = GetROILowerRightY();
1269 unsigned minX = GetROIUpperLeftX();
1270 unsigned uppboundX = GetROILowerRightX();
1271 for (
unsigned y = minY; y < uppboundY; y++)
1273 for (
unsigned x = minX; x < uppboundX; x++)
1275 dat[y][x] = (dat[y][x] >= Threshold) ? MaxValue : MinValue;
1300 template<
class StorageType>
1305 unsigned int width = GetWidth();
1306 unsigned int height = GetHeight();
1307 unsigned int channels = GetChannelCount();
1312 binaryImage.
ReInit(width, height, 1);
1315 for (
unsigned int x = 0; x < width; x++)
1317 for (
unsigned int y = 0; y < height; y++)
1320 for (
unsigned short ch = 0; ch < channels; ch++)
1322 StorageType val = PixelValue(x, y, ch);
1323 if (val > Threshold)
1339 template<
class StorageType>
1342 const unsigned short int channel)
const
1345 if (!CheckBilinearInterpolation(x, y)) {
1346 BIASERR(
"BilinearInterpolation() coordinates out of bounds: x = "
1347 << x <<
", y = " << y <<
", width = " <<GetWidth()
1348 <<
", height = " << GetHeight());
1353 switch (GetColorModel())
1356 res = BilinearInterpolationGrey(x, y);
1363 res = BilinearInterpolationRGBPlanar(x, y, channel);
1367 res = BilinearInterpolationRGBInterleaved(x, y, channel);
1372 if (IsInterleaved())
1374 StorageType **ida = (StorageType**) GetImageDataArray();
1375 BIASASSERT(ida!=NULL);
1376 unsigned int x_floor = (
unsigned int) floor(x);
1377 unsigned int y_floor = (
unsigned int) floor(y);
1378 unsigned int x_ceil = (
unsigned int) ceil(x);
1379 unsigned int y_ceil = (
unsigned int) ceil(y);
1381 ida[y_floor][x_floor * GetChannelCount() + channel];
1382 StorageType ur = ida[y_floor][x_ceil * GetChannelCount() + channel];
1383 StorageType ll = ida[y_ceil][x_floor * GetChannelCount() + channel];
1384 StorageType lr = ida[y_ceil][x_ceil * GetChannelCount() + channel];
1385 double dy = y - y_floor;
1386 double dx = x - x_floor;
1388 return ul + dy * (ll - ul) + dx * (ur - ul) + dy * dx * (ul + lr
1393 BIASERR(
"BilinearInterpolation() not implemented for planar "
1401 template<
class StorageType>
1404 const unsigned short int channel)
const
1407 if (!CheckBicubicInterpolation(x, y)) {
1408 BIASERR(
"BicubicInterpolation() coordinates out of bounds: x = "
1409 << x <<
", y = " << y <<
", width = " <<GetWidth()
1410 <<
", height = " << GetHeight());
1415 const int x_int = floor(x);
1416 const int y_int = floor(y);
1419 const double offsetx = x - x_int;
1420 const double offsety = y - y_int;
1423 const double wy0 = 0.25 * (((2.0 - offsety) * offsety - 1.0) * offsety);
1424 const double wy1 = 0.25 * ((3.0 * offsety - 5.0) * offsety * offsety
1426 const double wy2 = 0.25 * (((4.0 - 3.0 * offsety) * offsety + 1.0)
1428 const double wy3 = 0.25 * ((offsety - 1.0) * offsety * offsety);
1431 const double wx0 = ((2.0 - offsetx) * offsetx - 1.0) * offsetx;
1432 const double wx1 = (3.0 * offsetx - 5.0) * offsetx * offsetx + 2.0;
1433 const double wx2 = ((4.0 - 3.0 * offsetx) * offsetx + 1.0) * offsetx;
1434 const double wx3 = (offsetx - 1.0) * offsetx * offsetx;
1436 const StorageType** pD = (
const StorageType**) GetImageDataArray();
1437 return ((wx0 * pD[y_int - 1][(x_int - 1) * ChannelCount_ + channel] + wx1
1438 * pD[y_int - 1][x_int * ChannelCount_ + channel] + wx2
1439 * pD[y_int - 1][(x_int + 1) * ChannelCount_ + channel] + wx3
1440 * pD[y_int - 1][(x_int + 2) * ChannelCount_ + channel]) * wy0 + (wx0
1441 * pD[y_int][(x_int - 1) * ChannelCount_ + channel] + wx1
1442 * pD[y_int][x_int * ChannelCount_ + channel] + wx2 * pD[y_int][(x_int
1443 + 1) * ChannelCount_ + channel] + wx3 * pD[y_int][(x_int + 2)
1444 * ChannelCount_ + channel]) * wy1 + (wx0 * pD[y_int + 1][(x_int - 1)
1445 * ChannelCount_ + channel] + wx1 * pD[y_int + 1][x_int
1446 * ChannelCount_ + channel] + wx2 * pD[y_int + 1][(x_int + 1)
1447 * ChannelCount_ + channel] + wx3 * pD[y_int + 1][(x_int + 2)
1448 * ChannelCount_ + channel]) * wy2 + (wx0 * pD[y_int + 2][(x_int - 1)
1449 * ChannelCount_ + channel] + wx1 * pD[y_int + 2][x_int
1450 * ChannelCount_ + channel] + wx2 * pD[y_int + 2][(x_int + 1)
1451 * ChannelCount_ + channel] + wx3 * pD[y_int + 2][(x_int + 2)
1452 * ChannelCount_ + channel]) * wy3);
1455 template<
class StorageType>
1459 StorageType *src1, *src2, *dst, *write;
1464 BIASERR(
"Image::AppendChannel(): second image has different "
1468 if (img.
IsEmpty() || IsEmpty())
1470 BIASERR(
"Image::Append(): one or both images are empty");
1474 src1 = GetImageData();
1477 dst =
new StorageType[GetWidth() * GetHeight() * (GetChannelCount() + 1)];
1480 if (InterleavedDataOrder_)
1482 for (
unsigned long int p = 0; p < GetPixelCount(); p++)
1484 for (
unsigned long int c = 0; c < GetChannelCount(); c++)
1491 memcpy(write, src1, GetSizeByte());
1492 write += GetPixelCount() * GetChannelCount();
1501 ReleaseImageDataPointer();
1503 if (InterleavedDataOrder_)
1504 WidthStep_ = Width_ * Depth_ * ChannelCount_;
1506 WidthStep_ = Width_ * Depth_;
1508 RedirectImageDataPointer(dst);
1513 template<
class StorageType>
1516 unsigned cc = GetChannelCount();
1517 unsigned w = GetWidth();
1518 unsigned h = GetHeight();
1520 StorageType **src = GetImageDataArray();
1521 for (
int y = 0; y < (int)h; y++) {
1522 for (
int x = 0; x < (int)w; x++) {
1523 for (
unsigned c = 0; c < GetChannelCount(); c++){
1524 if(x<n || y<n || x>
int(w)-n || y>int(h)-n){
1525 src[y][x*cc+c] = delVal;
1534 template<
class StorageType>
1537 StorageType *src1,*dst, *write;
1540 BIASERR(
"Image::RemoveChannel(): image is empty");
1544 src1 = GetImageData();
1545 dst =
new StorageType[GetWidth() * GetHeight() * (GetChannelCount() -1)];
1548 if (InterleavedDataOrder_) {
1549 for (
unsigned long int p = 0; p < GetPixelCount(); p++) {
1550 for (
unsigned long int c = 0; c < GetChannelCount(); c++){
1551 if(c != channel) *write++ = *src1++;
1557 for(
unsigned i=0; i< GetChannelCount();i++){
1559 memcpy(write, src1, GetPixelCount());
1560 write += GetPixelCount();
1564 ReleaseImageDataPointer();
1566 if (InterleavedDataOrder_)
1567 WidthStep_ = Width_ * Depth_ * ChannelCount_;
1569 WidthStep_ = Width_ * Depth_;
1571 RedirectImageDataPointer(dst);
1577 template<
class StorageType>
1581 delete[] (
char**) ImageDataArray_;
1582 ImageDataArray_ = NULL;
1583 delete[] (
char*) ImageData_;
1586 Width_ = Height_ = 0;
1588 BitDepth_ = 8 * Depth_;
1590 ColorModel_ = CM_invalid;
1592 GetROI()->Release();
1597 template<
class StorageType>
1600 const unsigned short int channel)
1606 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() image is empty");
1608 if (channel> (GetChannelCount() - 1))
1609 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() invalid channel");
1611 unsigned minx, miny, maxx, maxy;
1612 GetROI()->GetCorners(minx, miny, maxx, maxy);
1613 if (minx!=0 || miny!=0 || maxx!=GetWidth() || maxy!=GetHeight())
1614 BIASERR(
"Image<StorageType>::GetMinMaxPixelValueIgnoreZero() not implemented for ROI!");
1625 p_src = GetImageData() + channel * GetPixelCount();
1627 for (
unsigned int i = 0; i < GetPixelCount(); i++)
1637 p_dest[i] = float(factor / p_src[i]);
1645 template <
class StorageType>
1649 StorageType *p=GetImageData();
1650 unsigned int count = GetPixelCount() * GetChannelCount();
1651 for (
register int i=count; i>0 ; i--){
1652 *p = MaxSTValue() - *p;
1658 template<
class StorageType>
1661 unsigned int channels,
void *data,
const bool interleaved,
1662 const bool shouldRelease)
1669 interleaved, shouldRelease);
1677 #include "ImageOperators.cpp"
1682 #define INSTANCE_Image(type)\
1683 template class BIASImageBase_EXPORT Image<type>;
1687 INSTANCE_Image(
unsigned char)
1688 INSTANCE_Image(
float)
1689 #ifdef BUILD_IMAGE_INT
1692 #ifdef BUILD_IMAGE_CHAR
1693 INSTANCE_Image(
char)
1695 #ifdef BUILD_IMAGE_SHORT
1696 INSTANCE_Image(
short)
1698 #if defined(BUILD_IMAGE_USHORT)
1699 INSTANCE_Image(
unsigned short)
1701 #ifdef BUILD_IMAGE_DOUBLE
1702 INSTANCE_Image(
double)
1704 #ifdef BUILD_IMAGE_UINT
1705 INSTANCE_Image(
unsigned int)
void Release()
reimplemented from ImageBase
void Invert()
inverts every pixel value, i.e. MaxSTValue() - value
unsigned int BitDepth_
relevant bits per pixel per channel
int BinaryThreshold(StorageType Threshold, StorageType MinValue, StorageType MaxValue)
Test for every pixel wether it is >= than the threshold.
int AboveThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values above Threshold to Value
(16bit) unsigned integer image storage type
StorageType GetMaxPixelValue(unsigned short int channel=0, unsigned int *coo=NULL) const
Get the maximal pixel value if coo!=NULL the coo[0]=x of max and coo[1]=y of max. ...
double BilinearInterpolation(const double x, const double y, const unsigned short int channel=0) const
Generic bilinear interpolation.
enum EStorageType StorageType_
the storage type in a pixel channel
int DeleteNBorderPixel(int n, StorageType delVal=StorageType(0))
Deletes n pixels at border of image.
int Transpose(BIAS::Image< StorageType > &result)
Transposes an image on diagonal, rows become columns, columns become rows.
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
int InvertValues(BIAS::Image< StorageType > &inverted, StorageType *newMax=NULL)
inverts values of image, new values are StorageType_MAX-oldvalue or newMax-oldvalue if newMax != NULL...
int BelowThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values below Threshold to Value
ImageBase & operator=(const ImageBase &Source)
assignment operator, allocates memory structure via Init only if necessary
int AppendChannel(Image< StorageType > &img)
(8bit) signed char image storage type
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
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.
unsigned int GetSizeByte() const
returns the nr.
std::ostream & PrintData(std::ostream &os) const
writes data of IplImage_ to os (ascii)
double image storage type
int ScaleShift(double Scale, double Shift)
scales and shifts image (all channels simultanously)
void Binarize(StorageType Threshold)
sets all pixels >= Threshold to MaxPixelValue and all others to MinPixelValue only for one channel / ...
int InitWithForeignData(unsigned int width, unsigned int height, unsigned int channels, void *data, const bool interleaved=true, const bool shouldRelease=true)
This is used to construct a BIAS::Image hull around existing image data.
void GetMinMaxPixelValue(StorageType &min, StorageType &max, unsigned short int channel=0, unsigned int *mincoo=NULL, unsigned int *maxcoo=NULL) const
returns the minimal and maximal pixel value in channel only Finds minimum and maximum pixel value in ...
unsigned int GetWidth() const
void GetMeanPixelValue(StorageType mean[])
calculates mean of pixel
(16bit) signed integer image storage type
double BicubicInterpolation(const double &x, const double &y, const unsigned short int channel=0) const
Generic bicubic interpolation.
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.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
std::ostream & PrintPointer(std::ostream &os) const
writes pointer of IplImage_ to os (ascii)
unsigned int GetHeight() const
void FillImageWithXValue()
fills image with value depending on x coordinate
void FillImageWithConstValue(StorageType Value)
fill grey images
The image template class for specific storage types.
bool GetMinMaxPixelValueIgnoreRange(StorageType &min, StorageType &max, const StorageType ignoreStart=0, const StorageType ignoreEnd=0, const unsigned short int channel=0) const
Get both, minimal and maximal pixel value –actual implementation only for planar images–.
int ScaleShiftChannel(double Scale, double Shift, unsigned int channel)
similiar to ScaleShift, but only scales and shifts one image channel
void SetPixel(const StorageType &value, const unsigned int &x, const unsigned int &y, const unsigned short int channel=0)
Set the value of a given pixel (x,y) in channel to value.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
(32bit) signed integer image storage type
void MaskValues(StorageType Threshold, Image< unsigned char > &binaryImage)
Calculates a mask image from given image depending on threshold.
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.
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
StorageType GetMinPixelValue(unsigned short int channel=0, unsigned int *coo=NULL) const
Get the minimal pixel value if coo!=NULL the coo[0]=x of min and coo[1]=y of min. ...
int RemoveChannel(unsigned int channel)
remove a channel from an image Remove means: RGB, remove channel 2 => RG CAUTION, channels start a 0 ...
void GetMeanPixelValueIgnoreRange(StorageType mean[], const StorageType ignoreStart=0, const StorageType ignoreEnd=(StorageType) 0) const
calculates mean of pixel ignoring values between ignoreStart and ignoreEnd
This is the base class for images in BIAS.
void Binarise(StorageType Threshold)
Wrapper for Binarize()
Image< float > Reciprocal(const float factor=1.0, const unsigned short int channel=0)
Calculates the reciprocal for each pixel: x' = 1/x computes for exactly one channel (in case of multi...
void ClearChannel(const unsigned int channel, const StorageType value)
Sets all pixel values in the declared channel to the specified value.
(32bit) unsigned integer image storage type
int CalcScaleShift(double Min, double Max, double &Scale, double &Shift) const
calculate the values needed by ScaleShiftBetween
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase