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>
123 vpImage(
unsigned int height,
unsigned int width) ;
125 vpImage(
unsigned int height,
unsigned int width, Type value) ;
129 void init(
unsigned int height,
unsigned int width) ;
131 void init(
unsigned int height,
unsigned int width, Type value) ;
133 void resize(
const unsigned int height,
const unsigned int width) ;
145 inline unsigned int getHeight()
const {
return height; }
154 inline unsigned int getWidth()
const {
return width; }
164 inline unsigned int getRows()
const {
return height ; }
173 inline unsigned int getCols()
const {
return width ; }
182 inline unsigned int getSize()
const {
return width*height ; }
193 Type
getValue(
double i,
double j)
const;
214 inline Type *
operator[](
const unsigned int i) {
return row[i];}
217 inline const Type *
operator[](
unsigned int i)
const {
return row[i];}
228 inline Type
operator()(
const unsigned int i,
const unsigned int j)
const
230 return bitmap[i*width+j] ;
241 inline void operator()(
const unsigned int i,
const unsigned int j,
259 unsigned int i = (
unsigned int) ip.
get_i();
260 unsigned int j = (
unsigned int) ip.
get_j();
262 return bitmap[i*width+j] ;
276 unsigned int i = (
unsigned int) ip.
get_i();
277 unsigned int j = (
unsigned int) ip.
get_j();
306 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
319 unsigned int npixels ;
321 unsigned int height ;
351 for (
unsigned int i=0 ; i < npixels ; i++)
375 if (height != this->height) {
383 if ((height != this->height) || (width != this->width))
385 if (bitmap != NULL) {
394 this->width = width ;
395 this->height = height ;
397 npixels=width*height;
400 if (bitmap == NULL) bitmap =
new Type[npixels] ;
407 "cannot allocate bitmap ")) ;
410 if (row == NULL) row =
new Type*[height] ;
416 "cannot allocate row ")) ;
420 for ( i =0 ; i < height ; i++)
421 row[i] = bitmap + i*width ;
446 this->height = this->width = 0 ;
449 init(height,width,0) ;
480 this->height = this->width = 0 ;
483 init(height,width,value) ;
509 this->height = this->width = 0 ;
534 init(height, width) ;
608 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
609 for (i =0 ; i < this->height ; i++) row[i] = bitmap + i*this->width ;
628 for (
unsigned int i=0 ; i < npixels ; i++)
630 if (bitmap[i]>m) m = bitmap[i] ;
644 for (
unsigned int i=0 ; i < npixels ; i++)
645 if (bitmap[i]<m) m = bitmap[i] ;
659 min = max = bitmap[0];
660 for (
unsigned int i=0 ; i < npixels ; i++)
662 if (bitmap[i]<min) min = bitmap[i] ;
663 if (bitmap[i]>max) max = bitmap[i] ;
683 this->width = I.width;
684 this->height = I.height;
685 this->npixels = I.npixels;
691 bitmap =
new Type[npixels] ;
697 "cannot allocate bitmap ")) ;
701 row =
new Type*[height] ;
706 "cannot allocate row ")) ;
709 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
711 for (
unsigned int i=0; i<this->height; i++){
712 row[i] = bitmap + i*this->width;
733 for (
unsigned int i=0 ; i < npixels ; i++)
750 for (
unsigned int i=0 ; i < npixels ; i++)
752 if (bitmap[i] != I.
bitmap[i])
770 for (
unsigned int i=0 ; i < npixels ; i++)
772 if (bitmap[i] == I.
bitmap[i])
827 int itl = (int)topLeft.
get_i();
828 int jtl = (int)topLeft.
get_j();
834 int dest_w = this->getWidth();
835 int dest_h = this->getHeight();
841 if (itl >= dest_h || jtl >= dest_w)
854 if (src_w - src_jbegin > dest_w - dest_jbegin)
855 wsize = dest_w - dest_jbegin;
857 wsize = src_w - src_jbegin;
859 if (src_h - src_ibegin > dest_h - dest_ibegin)
860 hsize = dest_h - dest_ibegin;
862 hsize = src_h - src_ibegin;
864 for (
int i = 0; i < hsize; i++)
866 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
867 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
869 memcpy(destBitmap,srcBitmap,wsize*
sizeof(Type));
906 unsigned int h = height/2;
907 unsigned int w = width/2;
909 for(
unsigned int i = 0; i < h; i++)
910 for(
unsigned int j = 0; j < w; j++)
911 res[i][j] = (*
this)[i<<1][j<<1];
940 unsigned int h = height/4;
941 unsigned int w = width/4;
943 for(
unsigned int i = 0; i < h; i++)
944 for(
unsigned int j = 0; j < w; j++)
945 res[i][j] = (*
this)[i<<2][j<<2];
990 for(
int i = 0; i < h; i++)
991 for(
int j = 0; j < w; j++)
992 res[i][j] = (*
this)[i>>1][j>>1];
1003 for(
int i = 0; i < h; i += 2)
1004 for(
int j = 1; j < w - 1; j += 2)
1005 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1006 + (*this)[i>>1][(j>>1) + 1]));
1009 for(
int i = 1; i < h - 1; i += 2)
1010 for(
int j = 0; j < w; j += 2)
1011 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1012 + (*this)[(i>>1)+1][j>>1]));
1015 for(
int i = 1; i < h - 1; i += 2)
1016 for(
int j = 1; j < w - 1; j += 2)
1017 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1018 + (*this)[i>>1][(j>>1)+1]
1019 + (*
this)[(i>>1)+1][j>>1]
1020 + (*
this)[(i>>1)+1][(j>>1)+1]));
1033 template<
class Type>
1059 unsigned int iround, jround;
1060 double rfrac, cfrac;
1062 iround = (
unsigned int)floor(i);
1063 jround = (
unsigned int)floor(j);
1065 if (iround >= height || jround >= width) {
1068 "Pixel outside the image"));
1072 i = (double)(height - 1);
1075 j = (double)(width - 1);
1077 double rratio = i - (double) iround;
1080 double cratio = j - (double) jround;
1084 rfrac = 1.0f - rratio;
1085 cfrac = 1.0f - cratio;
1088 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1089 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1114 unsigned int iround, jround;
1115 double rfrac, cfrac;
1117 iround = (
unsigned int)floor(i);
1118 jround = (
unsigned int)floor(j);
1120 if (iround >= height || jround >= width) {
1123 "Pixel outside the image"));
1127 i = (double)(height - 1);
1130 j = (double)(width - 1);
1132 double rratio = i - (double) iround;
1135 double cratio = j - (double) jround;
1139 rfrac = 1.0f - rratio;
1140 cfrac = 1.0f - cratio;
1143 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1144 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1151 unsigned int iround, jround;
1152 double rfrac, cfrac;
1154 iround = (
unsigned int)floor(i);
1155 jround = (
unsigned int)floor(j);
1157 if (iround >= height || jround >= width) {
1160 "Pixel outside the image"));
1164 i = (double)(height - 1);
1167 j = (double)(width - 1);
1169 double rratio = i - (double) iround;
1172 double cratio = j - (double) jround;
1176 rfrac = 1.0f - rratio;
1177 cfrac = 1.0f - cratio;
1179 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1180 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1181 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1182 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1183 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1184 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1198 template<
class Type>
1207 unsigned int iround, jround;
1208 double rfrac, cfrac;
1210 iround = (
unsigned int)floor(ip.
get_i());
1211 jround = (
unsigned int)floor(ip.
get_j());
1213 if (iround >= height || jround >= width) {
1216 "Pixel outside the image"));
1219 if (ip.
get_i() > height - 1)
1220 ip.
set_i((
double)(height - 1));
1222 if (ip.
get_j() > width - 1)
1223 ip.
set_j((
double)(width - 1));
1225 double rratio = ip.
get_i() - (double) iround;
1228 double cratio = ip.
get_j() - (double) jround;
1232 rfrac = 1.0f - rratio;
1233 cfrac = 1.0f - cratio;
1236 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1237 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1245 unsigned int iround, jround;
1246 double rfrac, cfrac;
1248 iround = (
unsigned int)floor(ip.
get_i());
1249 jround = (
unsigned int)floor(ip.
get_j());
1251 if (iround >= height || jround >= width) {
1254 "Pixel outside the image"));
1257 if (ip.
get_i() > height - 1)
1258 ip.
set_i((
double)(height - 1));
1260 if (ip.
get_j() > width - 1)
1261 ip.
set_j((
double)(width - 1));
1263 double rratio = ip.
get_i() - (double) iround;
1266 double cratio = ip.
get_j() - (double) jround;
1270 rfrac = 1.0f - rratio;
1271 cfrac = 1.0f - cratio;
1274 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1275 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1282 unsigned int iround, jround;
1283 double rfrac, cfrac;
1285 iround = (
unsigned int)floor(ip.
get_i());
1286 jround = (
unsigned int)floor(ip.
get_j());
1288 if (iround >= height || jround >= width) {
1291 "Pixel outside the image"));
1294 if (ip.
get_i() > height - 1)
1295 ip.
set_i((
double)(height - 1));
1297 if (ip.
get_j() > width - 1)
1298 ip.
set_j((
double)(width - 1));
1300 double rratio = ip.
get_i() - (double) iround;
1303 double cratio = ip.
get_j() - (double) jround;
1307 rfrac = 1.0f - rratio;
1308 cfrac = 1.0f - cratio;
1310 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1311 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1312 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1313 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1314 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1315 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1348 template<
class Type>
1354 if ((this->getHeight() != C.
getHeight())
1355 || (this->getWidth() != C.
getWidth()))
1356 C.
resize(this->getHeight(), this->getWidth());
1361 std::cout << me << std::endl ;
1367 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1369 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1372 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1389 template<
class Type>
1403 std::cout << me << std::endl ;
1409 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1411 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1419 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1431 template<
class Type>
1435 if (B == NULL || C == NULL) {
1437 "Images are not allocated in vpImage<>::sub()")) ;
1439 if ( (this->getWidth() != B->
getWidth())
1440 || (this->getHeight() != B->
getHeight())
1441 || (this->getWidth() != C->
getWidth())
1442 || (this->getHeight() != C->
getHeight()))
1444 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1446 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1449 for(
unsigned int i = 0; i < height * width; i++)
1466 template<
class Type>
1470 unsigned int r = height/2;
1471 unsigned int c = width/2;
1474 "Images are not allocated in vpImage<>::sub()")) ;
1478 for(
unsigned int y = 0; y < r; y++)
1479 for(
unsigned int x = 0; x < c; x++)
1480 (*res)[y][x] = (*this)[y*2][x*2];
1494 template<
class Type>
1498 unsigned int r = height/4;
1499 unsigned int c = width/4;
1502 "Images are not allocated in vpImage<>::sub()")) ;
1506 for(
unsigned int y = 0; y < r; y++)
1507 for(
unsigned int x = 0; x < c; x++)
1508 (*res)[y][x] = (*this)[y*4][x*4];
1522 template<
class Type>
1531 "Images are not allocated in vpImage<>::sub()")) ;
1536 for(
int j = 0; j < h; j++)
1537 for(
int i = 0; i < w; i++)
1538 (*res)[j][i] = (*this)[j/2][i/2];
1549 for(
int j = 0; j < h; j += 2)
1550 for(
int i = 1; i < w - 1; i += 2)
1551 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*
this)[j/2][i/2 + 1]));
1554 for(
int j = 1; j < h - 1; j += 2)
1555 for(
int i = 0; i < w; i += 2)
1556 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*this)[j/2+1][i/2]));
1559 for(
int j = 1; j < h - 1; j += 2)
1560 for(
int i = 1; i < w - 1; i += 2)
1561 (*res)[j][i] = (Type)(0.25 * ((*
this)[j/2][i/2] + (*this)[j/2][i/2+1] +
1562 (*this)[j/2+1][i/2] + (*this)[j/2+1][i/2+1]));
1565 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS