51 #include <visp/vpConfig.h>
52 #include <visp/vpDebug.h>
53 #include <visp/vpException.h>
54 #include <visp/vpImageException.h>
55 #include <visp/vpImagePoint.h>
56 #include <visp/vpRGBa.h>
128 vpImage(
unsigned int height,
unsigned int width) ;
130 vpImage(
unsigned int height,
unsigned int width, Type value) ;
134 void init(
unsigned int height,
unsigned int width) ;
136 void init(
unsigned int height,
unsigned int width, Type value) ;
138 void resize(
const unsigned int height,
const unsigned int width) ;
150 inline unsigned int getHeight()
const {
return height; }
159 inline unsigned int getWidth()
const {
return width; }
169 inline unsigned int getRows()
const {
return height ; }
178 inline unsigned int getCols()
const {
return width ; }
187 inline unsigned int getSize()
const {
return width*height ; }
198 Type
getValue(
double i,
double j)
const;
219 inline Type *
operator[](
const unsigned int i) {
return row[i];}
222 inline const Type *
operator[](
unsigned int i)
const {
return row[i];}
233 inline Type
operator()(
const unsigned int i,
const unsigned int j)
const
235 return bitmap[i*width+j] ;
246 inline void operator()(
const unsigned int i,
const unsigned int j,
264 unsigned int i = (
unsigned int) ip.
get_i();
265 unsigned int j = (
unsigned int) ip.
get_j();
267 return bitmap[i*width+j] ;
281 unsigned int i = (
unsigned int) ip.
get_i();
282 unsigned int j = (
unsigned int) ip.
get_j();
311 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
324 unsigned int npixels ;
326 unsigned int height ;
356 for (
unsigned int i=0 ; i < npixels ; i++)
380 if (height != this->height) {
388 if ((height != this->height) || (width != this->width))
390 if (bitmap != NULL) {
399 this->width = width ;
400 this->height = height ;
402 npixels=width*height;
405 if (bitmap == NULL) bitmap =
new Type[npixels] ;
412 "cannot allocate bitmap ")) ;
415 if (row == NULL) row =
new Type*[height] ;
421 "cannot allocate row ")) ;
425 for ( i =0 ; i < height ; i++)
426 row[i] = bitmap + i*width ;
451 this->height = this->width = 0 ;
454 init(height,width,0) ;
485 this->height = this->width = 0 ;
488 init(height,width,value) ;
514 this->height = this->width = 0 ;
539 init(height, width) ;
613 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
614 for (i =0 ; i < this->height ; i++) row[i] = bitmap + i*this->width ;
633 for (
unsigned int i=0 ; i < npixels ; i++)
635 if (bitmap[i]>m) m = bitmap[i] ;
649 for (
unsigned int i=0 ; i < npixels ; i++)
650 if (bitmap[i]<m) m = bitmap[i] ;
664 min = max = bitmap[0];
665 for (
unsigned int i=0 ; i < npixels ; i++)
667 if (bitmap[i]<min) min = bitmap[i] ;
668 if (bitmap[i]>max) max = bitmap[i] ;
688 this->width = I.width;
689 this->height = I.height;
690 this->npixels = I.npixels;
696 bitmap =
new Type[npixels] ;
702 "cannot allocate bitmap ")) ;
706 row =
new Type*[height] ;
711 "cannot allocate row ")) ;
714 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
716 for (
unsigned int i=0; i<this->height; i++){
717 row[i] = bitmap + i*this->width;
738 for (
unsigned int i=0 ; i < npixels ; i++)
755 for (
unsigned int i=0 ; i < npixels ; i++)
757 if (bitmap[i] != I.
bitmap[i])
775 for (
unsigned int i=0 ; i < npixels ; i++)
777 if (bitmap[i] == I.
bitmap[i])
832 int itl = (int)topLeft.
get_i();
833 int jtl = (int)topLeft.
get_j();
839 int dest_w = this->getWidth();
840 int dest_h = this->getHeight();
846 if (itl >= dest_h || jtl >= dest_w)
859 if (src_w - src_jbegin > dest_w - dest_jbegin)
860 wsize = dest_w - dest_jbegin;
862 wsize = src_w - src_jbegin;
864 if (src_h - src_ibegin > dest_h - dest_ibegin)
865 hsize = dest_h - dest_ibegin;
867 hsize = src_h - src_ibegin;
869 for (
int i = 0; i < hsize; i++)
871 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
872 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
874 memcpy(destBitmap,srcBitmap,wsize*
sizeof(Type));
911 unsigned int h = height/2;
912 unsigned int w = width/2;
914 for(
unsigned int i = 0; i < h; i++)
915 for(
unsigned int j = 0; j < w; j++)
916 res[i][j] = (*
this)[i<<1][j<<1];
945 unsigned int h = height/4;
946 unsigned int w = width/4;
948 for(
unsigned int i = 0; i < h; i++)
949 for(
unsigned int j = 0; j < w; j++)
950 res[i][j] = (*
this)[i<<2][j<<2];
995 for(
int i = 0; i < h; i++)
996 for(
int j = 0; j < w; j++)
997 res[i][j] = (*
this)[i>>1][j>>1];
1008 for(
int i = 0; i < h; i += 2)
1009 for(
int j = 1; j < w - 1; j += 2)
1010 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1011 + (*this)[i>>1][(j>>1) + 1]));
1014 for(
int i = 1; i < h - 1; i += 2)
1015 for(
int j = 0; j < w; j += 2)
1016 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1017 + (*this)[(i>>1)+1][j>>1]));
1020 for(
int i = 1; i < h - 1; i += 2)
1021 for(
int j = 1; j < w - 1; j += 2)
1022 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1023 + (*this)[i>>1][(j>>1)+1]
1024 + (*
this)[(i>>1)+1][j>>1]
1025 + (*
this)[(i>>1)+1][(j>>1)+1]));
1038 template<
class Type>
1064 unsigned int iround, jround;
1065 double rfrac, cfrac;
1067 iround = (
unsigned int)floor(i);
1068 jround = (
unsigned int)floor(j);
1070 if (iround >= height || jround >= width) {
1073 "Pixel outside the image"));
1077 i = (double)(height - 1);
1080 j = (double)(width - 1);
1082 double rratio = i - (double) iround;
1085 double cratio = j - (double) jround;
1089 rfrac = 1.0f - rratio;
1090 cfrac = 1.0f - cratio;
1093 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1094 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1119 unsigned int iround, jround;
1120 double rfrac, cfrac;
1122 iround = (
unsigned int)floor(i);
1123 jround = (
unsigned int)floor(j);
1125 if (iround >= height || jround >= width) {
1128 "Pixel outside the image"));
1132 i = (double)(height - 1);
1135 j = (double)(width - 1);
1137 double rratio = i - (double) iround;
1140 double cratio = j - (double) jround;
1144 rfrac = 1.0f - rratio;
1145 cfrac = 1.0f - cratio;
1148 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1149 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1156 unsigned int iround, jround;
1157 double rfrac, cfrac;
1159 iround = (
unsigned int)floor(i);
1160 jround = (
unsigned int)floor(j);
1162 if (iround >= height || jround >= width) {
1165 "Pixel outside the image"));
1169 i = (double)(height - 1);
1172 j = (double)(width - 1);
1174 double rratio = i - (double) iround;
1177 double cratio = j - (double) jround;
1181 rfrac = 1.0f - rratio;
1182 cfrac = 1.0f - cratio;
1184 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1185 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1186 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1187 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1188 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1189 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1203 template<
class Type>
1212 unsigned int iround, jround;
1213 double rfrac, cfrac;
1215 iround = (
unsigned int)floor(ip.
get_i());
1216 jround = (
unsigned int)floor(ip.
get_j());
1218 if (iround >= height || jround >= width) {
1221 "Pixel outside the image"));
1224 if (ip.
get_i() > height - 1)
1225 ip.
set_i((
double)(height - 1));
1227 if (ip.
get_j() > width - 1)
1228 ip.
set_j((
double)(width - 1));
1230 double rratio = ip.
get_i() - (double) iround;
1233 double cratio = ip.
get_j() - (double) jround;
1237 rfrac = 1.0f - rratio;
1238 cfrac = 1.0f - cratio;
1241 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1242 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1250 unsigned int iround, jround;
1251 double rfrac, cfrac;
1253 iround = (
unsigned int)floor(ip.
get_i());
1254 jround = (
unsigned int)floor(ip.
get_j());
1256 if (iround >= height || jround >= width) {
1259 "Pixel outside the image"));
1262 if (ip.
get_i() > height - 1)
1263 ip.
set_i((
double)(height - 1));
1265 if (ip.
get_j() > width - 1)
1266 ip.
set_j((
double)(width - 1));
1268 double rratio = ip.
get_i() - (double) iround;
1271 double cratio = ip.
get_j() - (double) jround;
1275 rfrac = 1.0f - rratio;
1276 cfrac = 1.0f - cratio;
1279 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1280 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1287 unsigned int iround, jround;
1288 double rfrac, cfrac;
1290 iround = (
unsigned int)floor(ip.
get_i());
1291 jround = (
unsigned int)floor(ip.
get_j());
1293 if (iround >= height || jround >= width) {
1296 "Pixel outside the image"));
1299 if (ip.
get_i() > height - 1)
1300 ip.
set_i((
double)(height - 1));
1302 if (ip.
get_j() > width - 1)
1303 ip.
set_j((
double)(width - 1));
1305 double rratio = ip.
get_i() - (double) iround;
1308 double cratio = ip.
get_j() - (double) jround;
1312 rfrac = 1.0f - rratio;
1313 cfrac = 1.0f - cratio;
1315 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1316 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1317 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1318 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1319 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1320 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1353 template<
class Type>
1359 if ((this->getHeight() != C.
getHeight())
1360 || (this->getWidth() != C.
getWidth()))
1361 C.
resize(this->getHeight(), this->getWidth());
1366 std::cout << me << std::endl ;
1372 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1374 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1377 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1394 template<
class Type>
1408 std::cout << me << std::endl ;
1414 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1416 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1424 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1436 template<
class Type>
1440 if (B == NULL || C == NULL) {
1442 "Images are not allocated in vpImage<>::sub()")) ;
1444 if ( (this->getWidth() != B->
getWidth())
1445 || (this->getHeight() != B->
getHeight())
1446 || (this->getWidth() != C->
getWidth())
1447 || (this->getHeight() != C->
getHeight()))
1449 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1451 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1454 for(
unsigned int i = 0; i < height * width; i++)
1471 template<
class Type>
1475 unsigned int r = height/2;
1476 unsigned int c = width/2;
1479 "Images are not allocated in vpImage<>::sub()")) ;
1483 for(
unsigned int y = 0; y < r; y++)
1484 for(
unsigned int x = 0; x < c; x++)
1485 (*res)[y][x] = (*this)[y*2][x*2];
1499 template<
class Type>
1503 unsigned int r = height/4;
1504 unsigned int c = width/4;
1507 "Images are not allocated in vpImage<>::sub()")) ;
1511 for(
unsigned int y = 0; y < r; y++)
1512 for(
unsigned int x = 0; x < c; x++)
1513 (*res)[y][x] = (*this)[y*4][x*4];
1527 template<
class Type>
1536 "Images are not allocated in vpImage<>::sub()")) ;
1541 for(
int j = 0; j < h; j++)
1542 for(
int i = 0; i < w; i++)
1543 (*res)[j][i] = (*this)[j/2][i/2];
1554 for(
int j = 0; j < h; j += 2)
1555 for(
int i = 1; i < w - 1; i += 2)
1556 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*
this)[j/2][i/2 + 1]));
1559 for(
int j = 1; j < h - 1; j += 2)
1560 for(
int i = 0; i < w; i += 2)
1561 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*this)[j/2+1][i/2]));
1564 for(
int j = 1; j < h - 1; j += 2)
1565 for(
int i = 1; i < w - 1; i += 2)
1566 (*res)[j][i] = (Type)(0.25 * ((*
this)[j/2][i/2] + (*this)[j/2][i/2+1] +
1567 (*this)[j/2+1][i/2] + (*this)[j/2+1][i/2+1]));
1570 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS