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 h,
const unsigned int w) ;
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];}
223 inline const Type *
operator[](
unsigned int i)
const {
return row[i];}
235 inline Type
operator()(
const unsigned int i,
const unsigned int j)
const
237 return bitmap[i*width+j] ;
248 inline void operator()(
const unsigned int i,
const unsigned int j,
251 bitmap[i*width+j] = v ;
266 unsigned int i = (
unsigned int) ip.
get_i();
267 unsigned int j = (
unsigned int) ip.
get_j();
269 return bitmap[i*width+j] ;
283 unsigned int i = (
unsigned int) ip.
get_i();
284 unsigned int j = (
unsigned int) ip.
get_j();
286 bitmap[i*width+j] = v ;
313 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
326 unsigned int npixels ;
328 unsigned int height ;
360 for (
unsigned int i=0 ; i < npixels ; i++)
387 if (h != this->height) {
395 if ((h != this->height) || (w != this->width))
397 if (bitmap != NULL) {
407 npixels=width*height;
409 if (bitmap == NULL) bitmap =
new Type[npixels] ;
416 "cannot allocate bitmap ")) ;
419 if (row == NULL) row =
new Type*[height] ;
425 "cannot allocate row ")) ;
429 for ( i =0 ; i < height ; i++)
430 row[i] = bitmap + i*width ;
453 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
484 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
508 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
596 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
602 for (
unsigned int i =0 ; i < this->height ; i++) row[i] =
bitmap + i*this->width ;
620 for (
unsigned int i=0 ; i < npixels ; i++)
622 if (bitmap[i]>m) m = bitmap[i] ;
636 for (
unsigned int i=0 ; i < npixels ; i++)
637 if (bitmap[i]<m) m = bitmap[i] ;
651 min = max = bitmap[0];
652 for (
unsigned int i=0 ; i < npixels ; i++)
654 if (bitmap[i]<min) min = bitmap[i] ;
655 if (bitmap[i]>max) max = bitmap[i] ;
675 this->width = I.width;
676 this->height = I.height;
677 this->npixels = I.npixels;
683 bitmap =
new Type[npixels] ;
689 "cannot allocate bitmap ")) ;
693 row =
new Type*[height] ;
698 "cannot allocate row ")) ;
701 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
703 for (
unsigned int i=0; i<this->height; i++){
704 row[i] = bitmap + i*this->width;
726 for (
unsigned int i=0 ; i < npixels ; i++)
745 for (
unsigned int i=0 ; i < npixels ; i++)
747 if (bitmap[i] != I.
bitmap[i])
765 for (
unsigned int i=0 ; i < npixels ; i++)
767 if (bitmap[i] == I.
bitmap[i])
822 int itl = (int)topLeft.
get_i();
823 int jtl = (int)topLeft.
get_j();
829 int dest_w = this->getWidth();
830 int dest_h = this->getHeight();
836 if (itl >= dest_h || jtl >= dest_w)
849 if (src_w - src_jbegin > dest_w - dest_jbegin)
850 wsize = dest_w - dest_jbegin;
852 wsize = src_w - src_jbegin;
854 if (src_h - src_ibegin > dest_h - dest_ibegin)
855 hsize = dest_h - dest_ibegin;
857 hsize = src_h - src_ibegin;
859 for (
int i = 0; i < hsize; i++)
861 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
862 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
864 memcpy(destBitmap,srcBitmap,wsize*
sizeof(Type));
901 unsigned int h = height/2;
902 unsigned int w = width/2;
904 for(
unsigned int i = 0; i < h; i++)
905 for(
unsigned int j = 0; j < w; j++)
906 res[i][j] = (*
this)[i<<1][j<<1];
935 unsigned int h = height/4;
936 unsigned int w = width/4;
938 for(
unsigned int i = 0; i < h; i++)
939 for(
unsigned int j = 0; j < w; j++)
940 res[i][j] = (*
this)[i<<2][j<<2];
985 for(
int i = 0; i < h; i++)
986 for(
int j = 0; j < w; j++)
987 res[i][j] = (*
this)[i>>1][j>>1];
998 for(
int i = 0; i < h; i += 2)
999 for(
int j = 1; j < w - 1; j += 2)
1000 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1001 + (*this)[i>>1][(j>>1) + 1]));
1004 for(
int i = 1; i < h - 1; i += 2)
1005 for(
int j = 0; j < w; j += 2)
1006 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1007 + (*this)[(i>>1)+1][j>>1]));
1010 for(
int i = 1; i < h - 1; i += 2)
1011 for(
int j = 1; j < w - 1; j += 2)
1012 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1013 + (*this)[i>>1][(j>>1)+1]
1014 + (*
this)[(i>>1)+1][j>>1]
1015 + (*
this)[(i>>1)+1][(j>>1)+1]));
1028 template<
class Type>
1054 unsigned int iround, jround;
1055 double rfrac, cfrac;
1057 iround = (
unsigned int)floor(i);
1058 jround = (
unsigned int)floor(j);
1060 if (iround >= height || jround >= width) {
1063 "Pixel outside the image"));
1067 i = (double)(height - 1);
1070 j = (double)(width - 1);
1072 double rratio = i - (double) iround;
1075 double cratio = j - (double) jround;
1079 rfrac = 1.0f - rratio;
1080 cfrac = 1.0f - cratio;
1083 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1084 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1109 unsigned int iround, jround;
1110 double rfrac, cfrac;
1112 iround = (
unsigned int)floor(i);
1113 jround = (
unsigned int)floor(j);
1115 if (iround >= height || jround >= width) {
1118 "Pixel outside the image"));
1122 i = (double)(height - 1);
1125 j = (double)(width - 1);
1127 double rratio = i - (double) iround;
1130 double cratio = j - (double) jround;
1134 rfrac = 1.0f - rratio;
1135 cfrac = 1.0f - cratio;
1138 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1139 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1146 unsigned int iround, jround;
1147 double rfrac, cfrac;
1149 iround = (
unsigned int)floor(i);
1150 jround = (
unsigned int)floor(j);
1152 if (iround >= height || jround >= width) {
1155 "Pixel outside the image"));
1159 i = (double)(height - 1);
1162 j = (double)(width - 1);
1164 double rratio = i - (double) iround;
1167 double cratio = j - (double) jround;
1171 rfrac = 1.0f - rratio;
1172 cfrac = 1.0f - cratio;
1174 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1175 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1176 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1177 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1178 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1179 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1193 template<
class Type>
1202 unsigned int iround, jround;
1203 double rfrac, cfrac;
1205 iround = (
unsigned int)floor(ip.
get_i());
1206 jround = (
unsigned int)floor(ip.
get_j());
1208 if (iround >= height || jround >= width) {
1211 "Pixel outside the image"));
1214 if (ip.
get_i() > height - 1)
1215 ip.
set_i((
double)(height - 1));
1217 if (ip.
get_j() > width - 1)
1218 ip.
set_j((
double)(width - 1));
1220 double rratio = ip.
get_i() - (double) iround;
1223 double cratio = ip.
get_j() - (double) jround;
1227 rfrac = 1.0f - rratio;
1228 cfrac = 1.0f - cratio;
1231 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1232 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1240 unsigned int iround, jround;
1241 double rfrac, cfrac;
1243 iround = (
unsigned int)floor(ip.
get_i());
1244 jround = (
unsigned int)floor(ip.
get_j());
1246 if (iround >= height || jround >= width) {
1249 "Pixel outside the image"));
1252 if (ip.
get_i() > height - 1)
1253 ip.
set_i((
double)(height - 1));
1255 if (ip.
get_j() > width - 1)
1256 ip.
set_j((
double)(width - 1));
1258 double rratio = ip.
get_i() - (double) iround;
1261 double cratio = ip.
get_j() - (double) jround;
1265 rfrac = 1.0f - rratio;
1266 cfrac = 1.0f - cratio;
1269 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1270 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1277 unsigned int iround, jround;
1278 double rfrac, cfrac;
1280 iround = (
unsigned int)floor(ip.
get_i());
1281 jround = (
unsigned int)floor(ip.
get_j());
1283 if (iround >= height || jround >= width) {
1286 "Pixel outside the image"));
1289 if (ip.
get_i() > height - 1)
1290 ip.
set_i((
double)(height - 1));
1292 if (ip.
get_j() > width - 1)
1293 ip.
set_j((
double)(width - 1));
1295 double rratio = ip.
get_i() - (double) iround;
1298 double cratio = ip.
get_j() - (double) jround;
1302 rfrac = 1.0f - rratio;
1303 cfrac = 1.0f - cratio;
1305 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1306 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1307 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1308 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1309 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1310 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1343 template<
class Type>
1349 if ((this->getHeight() != C.
getHeight())
1350 || (this->getWidth() != C.
getWidth()))
1351 C.
resize(this->getHeight(), this->getWidth());
1356 std::cout << me << std::endl ;
1362 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1364 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1367 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1384 template<
class Type>
1398 std::cout << me << std::endl ;
1404 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1406 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1414 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1426 template<
class Type>
1430 if (B == NULL || C == NULL) {
1432 "Images are not allocated in vpImage<>::sub()")) ;
1434 if ( (this->getWidth() != B->
getWidth())
1435 || (this->getHeight() != B->
getHeight())
1436 || (this->getWidth() != C->
getWidth())
1437 || (this->getHeight() != C->
getHeight()))
1439 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1441 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1444 for(
unsigned int i = 0; i < height * width; i++)
1461 template<
class Type>
1465 unsigned int r = height/2;
1466 unsigned int c = width/2;
1469 "Images are not allocated in vpImage<>::sub()")) ;
1473 for(
unsigned int y = 0; y < r; y++)
1474 for(
unsigned int x = 0; x < c; x++)
1475 (*res)[y][x] = (*this)[y*2][x*2];
1489 template<
class Type>
1493 unsigned int r = height/4;
1494 unsigned int c = width/4;
1497 "Images are not allocated in vpImage<>::sub()")) ;
1501 for(
unsigned int y = 0; y < r; y++)
1502 for(
unsigned int x = 0; x < c; x++)
1503 (*res)[y][x] = (*this)[y*4][x*4];
1517 template<
class Type>
1526 "Images are not allocated in vpImage<>::sub()")) ;
1531 for(
int j = 0; j < h; j++)
1532 for(
int i = 0; i < w; i++)
1533 (*res)[j][i] = (*this)[j/2][i/2];
1544 for(
int j = 0; j < h; j += 2)
1545 for(
int i = 1; i < w - 1; i += 2)
1546 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*
this)[j/2][i/2 + 1]));
1549 for(
int j = 1; j < h - 1; j += 2)
1550 for(
int i = 0; i < w; i += 2)
1551 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*this)[j/2+1][i/2]));
1554 for(
int j = 1; j < h - 1; j += 2)
1555 for(
int i = 1; i < w - 1; i += 2)
1556 (*res)[j][i] = (Type)(0.25 * ((*
this)[j/2][i/2] + (*this)[j/2][i/2+1] +
1557 (*this)[j/2+1][i/2] + (*this)[j/2+1][i/2+1]));
1560 #endif // VISP_BUILD_DEPRECATED_FUNCTIONS
unsigned int getCols() const
void doubleSizeImage(vpImage< Type > &res)
Class that defines generic functionnalities for display.
unsigned int getWidth() const
void init(unsigned int height, unsigned int width)
set the size of the image
Type operator()(const unsigned int i, const unsigned int j) const
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
void halfSizeImage(vpImage< Type > &res)
Type * bitmap
points toward the bitmap
Type operator()(const vpImagePoint &ip) const
error that can be emited by ViSP classes.
Type getValue(double i, double j) const
Type getMinValue() const
Return the minimum value within the bitmap.
Type * operator[](const unsigned int i)
operator[] allows operation like I[i] = x.
virtual ~vpImage()
destructor
static int round(const double x)
Class that defines a RGB 32 bits structure.
void quarterSizeImage(vpImage< Type > &res)
unsigned int getRows() const
void set_i(const double ii)
vpImage< Type > & operator=(const vpImage< Type > &I)
Copy operator.
unsigned int getSize() const
bool operator!=(const vpImage< Type > &I)
void operator()(const vpImagePoint &ip, const Type &v)
Type getMaxValue() const
Return the maximum value within the bitmap.
const Type * operator[](int i) const
unsigned int getNumberOfPixel() const
void resize(const unsigned int h, const unsigned int w)
set the size of the image
const Type * operator[](unsigned int i) const
operator[] allows operation like x = I[i]
void set_j(const double jj)
void insert(const vpImage< Type > &src, const vpImagePoint topLeft)
Type * operator[](const int i)
vpImage< Type > operator-(const vpImage< Type > &B)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void operator()(const unsigned int i, const unsigned int j, const Type &v)
Definition of the vpImage class member functions.
bool operator==(const vpImage< Type > &I)
void sub(const vpImage< Type > &B, vpImage< Type > &C)