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) ;
140 void resize(
const unsigned int h,
const unsigned int w,
const Type val) ;
152 inline unsigned int getHeight()
const {
return height; }
161 inline unsigned int getWidth()
const {
return width; }
171 inline unsigned int getRows()
const {
return height ; }
180 inline unsigned int getCols()
const {
return width ; }
189 inline unsigned int getSize()
const {
return width*height ; }
200 Type
getValue(
double i,
double j)
const;
221 inline Type *
operator[](
const unsigned int i) {
return row[i];}
225 inline const Type *
operator[](
unsigned int i)
const {
return row[i];}
237 inline Type
operator()(
const unsigned int i,
const unsigned int j)
const
239 return bitmap[i*width+j] ;
250 inline void operator()(
const unsigned int i,
const unsigned int j,
253 bitmap[i*width+j] = v ;
268 unsigned int i = (
unsigned int) ip.
get_i();
269 unsigned int j = (
unsigned int) ip.
get_j();
271 return bitmap[i*width+j] ;
285 unsigned int i = (
unsigned int) ip.
get_i();
286 unsigned int j = (
unsigned int) ip.
get_j();
288 bitmap[i*width+j] = v ;
315 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
328 unsigned int npixels ;
330 unsigned int height ;
362 for (
unsigned int i=0 ; i < npixels ; i++)
389 if (h != this->height) {
397 if ((h != this->height) || (w != this->width))
399 if (bitmap != NULL) {
409 npixels=width*height;
411 if (bitmap == NULL) bitmap =
new Type[npixels] ;
418 "cannot allocate bitmap ")) ;
421 if (row == NULL) row =
new Type*[height] ;
427 "cannot allocate row ")) ;
431 for ( i =0 ; i < height ; i++)
432 row[i] = bitmap + i*width ;
455 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
486 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
510 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
635 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
641 for (
unsigned int i =0 ; i < this->height ; i++) row[i] =
bitmap + i*this->width ;
659 for (
unsigned int i=0 ; i < npixels ; i++)
661 if (bitmap[i]>m) m = bitmap[i] ;
675 for (
unsigned int i=0 ; i < npixels ; i++)
676 if (bitmap[i]<m) m = bitmap[i] ;
690 min = max = bitmap[0];
691 for (
unsigned int i=0 ; i < npixels ; i++)
693 if (bitmap[i]<min) min = bitmap[i] ;
694 if (bitmap[i]>max) max = bitmap[i] ;
714 this->width = I.width;
715 this->height = I.height;
716 this->npixels = I.npixels;
722 bitmap =
new Type[npixels] ;
728 "cannot allocate bitmap ")) ;
732 row =
new Type*[height] ;
737 "cannot allocate row ")) ;
740 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
742 for (
unsigned int i=0; i<this->height; i++){
743 row[i] = bitmap + i*this->width;
765 for (
unsigned int i=0 ; i < npixels ; i++)
784 for (
unsigned int i=0 ; i < npixels ; i++)
786 if (bitmap[i] != I.
bitmap[i])
804 for (
unsigned int i=0 ; i < npixels ; i++)
806 if (bitmap[i] == I.
bitmap[i])
861 int itl = (int)topLeft.
get_i();
862 int jtl = (int)topLeft.
get_j();
868 int dest_w = (int)this->getWidth();
869 int dest_h = (int)this->getHeight();
875 if (itl >= dest_h || jtl >= dest_w)
888 if (src_w - src_jbegin > dest_w - dest_jbegin)
889 wsize = dest_w - dest_jbegin;
891 wsize = src_w - src_jbegin;
893 if (src_h - src_ibegin > dest_h - dest_ibegin)
894 hsize = dest_h - dest_ibegin;
896 hsize = src_h - src_ibegin;
898 for (
int i = 0; i < hsize; i++)
900 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
901 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
903 memcpy(destBitmap,srcBitmap,wsize*
sizeof(Type));
940 unsigned int h = height/2;
941 unsigned int w = width/2;
943 for(
unsigned int i = 0; i < h; i++)
944 for(
unsigned int j = 0; j < w; j++)
945 res[i][j] = (*
this)[i<<1][j<<1];
974 unsigned int h = height/4;
975 unsigned int w = width/4;
977 for(
unsigned int i = 0; i < h; i++)
978 for(
unsigned int j = 0; j < w; j++)
979 res[i][j] = (*
this)[i<<2][j<<2];
1015 template<
class Type>
1024 for(
int i = 0; i < h; i++)
1025 for(
int j = 0; j < w; j++)
1026 res[i][j] = (*
this)[i>>1][j>>1];
1037 for(
int i = 0; i < h; i += 2)
1038 for(
int j = 1; j < w - 1; j += 2)
1039 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1040 + (*this)[i>>1][(j>>1) + 1]));
1043 for(
int i = 1; i < h - 1; i += 2)
1044 for(
int j = 0; j < w; j += 2)
1045 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1046 + (*this)[(i>>1)+1][j>>1]));
1049 for(
int i = 1; i < h - 1; i += 2)
1050 for(
int j = 1; j < w - 1; j += 2)
1051 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1052 + (*this)[i>>1][(j>>1)+1]
1053 + (*
this)[(i>>1)+1][j>>1]
1054 + (*
this)[(i>>1)+1][(j>>1)+1]));
1067 template<
class Type>
1093 unsigned int iround, jround;
1094 double rfrac, cfrac;
1096 iround = (
unsigned int)floor(i);
1097 jround = (
unsigned int)floor(j);
1099 if (iround >= height || jround >= width) {
1102 "Pixel outside the image"));
1106 i = (double)(height - 1);
1109 j = (double)(width - 1);
1111 double rratio = i - (double) iround;
1114 double cratio = j - (double) jround;
1118 rfrac = 1.0f - rratio;
1119 cfrac = 1.0f - cratio;
1122 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1123 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1148 unsigned int iround, jround;
1149 double rfrac, cfrac;
1151 iround = (
unsigned int)floor(i);
1152 jround = (
unsigned int)floor(j);
1154 if (iround >= height || jround >= width) {
1157 "Pixel outside the image"));
1161 i = (double)(height - 1);
1164 j = (double)(width - 1);
1166 double rratio = i - (double) iround;
1169 double cratio = j - (double) jround;
1173 rfrac = 1.0f - rratio;
1174 cfrac = 1.0f - cratio;
1177 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1178 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1185 unsigned int iround, jround;
1186 double rfrac, cfrac;
1188 iround = (
unsigned int)floor(i);
1189 jround = (
unsigned int)floor(j);
1191 if (iround >= height || jround >= width) {
1194 "Pixel outside the image"));
1198 i = (double)(height - 1);
1201 j = (double)(width - 1);
1203 double rratio = i - (double) iround;
1206 double cratio = j - (double) jround;
1210 rfrac = 1.0f - rratio;
1211 cfrac = 1.0f - cratio;
1213 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1214 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1215 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1216 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1217 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1218 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1232 template<
class Type>
1241 unsigned int iround, jround;
1242 double rfrac, cfrac;
1244 iround = (
unsigned int)floor(ip.
get_i());
1245 jround = (
unsigned int)floor(ip.
get_j());
1247 if (iround >= height || jround >= width) {
1250 "Pixel outside the image"));
1253 if (ip.
get_i() > height - 1)
1254 ip.
set_i((
double)(height - 1));
1256 if (ip.
get_j() > width - 1)
1257 ip.
set_j((
double)(width - 1));
1259 double rratio = ip.
get_i() - (double) iround;
1262 double cratio = ip.
get_j() - (double) jround;
1266 rfrac = 1.0f - rratio;
1267 cfrac = 1.0f - cratio;
1270 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1271 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1279 unsigned int iround, jround;
1280 double rfrac, cfrac;
1282 iround = (
unsigned int)floor(ip.
get_i());
1283 jround = (
unsigned int)floor(ip.
get_j());
1285 if (iround >= height || jround >= width) {
1288 "Pixel outside the image"));
1291 if (ip.
get_i() > height - 1)
1292 ip.
set_i((
double)(height - 1));
1294 if (ip.
get_j() > width - 1)
1295 ip.
set_j((
double)(width - 1));
1297 double rratio = ip.
get_i() - (double) iround;
1300 double cratio = ip.
get_j() - (double) jround;
1304 rfrac = 1.0f - rratio;
1305 cfrac = 1.0f - cratio;
1308 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1309 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1316 unsigned int iround, jround;
1317 double rfrac, cfrac;
1319 iround = (
unsigned int)floor(ip.
get_i());
1320 jround = (
unsigned int)floor(ip.
get_j());
1322 if (iround >= height || jround >= width) {
1325 "Pixel outside the image"));
1328 if (ip.
get_i() > height - 1)
1329 ip.
set_i((
double)(height - 1));
1331 if (ip.
get_j() > width - 1)
1332 ip.
set_j((
double)(width - 1));
1334 double rratio = ip.
get_i() - (double) iround;
1337 double cratio = ip.
get_j() - (double) jround;
1341 rfrac = 1.0f - rratio;
1342 cfrac = 1.0f - cratio;
1344 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1345 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1346 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1347 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1348 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1349 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1382 template<
class Type>
1388 if ((this->getHeight() != C.
getHeight())
1389 || (this->getWidth() != C.
getWidth()))
1390 C.
resize(this->getHeight(), this->getWidth());
1395 std::cout << me << std::endl ;
1401 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1403 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1406 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1423 template<
class Type>
1437 std::cout << me << std::endl ;
1443 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1445 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1453 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
1465 template<
class Type>
1469 if (B == NULL || C == NULL) {
1471 "Images are not allocated in vpImage<>::sub()")) ;
1473 if ( (this->getWidth() != B->
getWidth())
1474 || (this->getHeight() != B->
getHeight())
1475 || (this->getWidth() != C->
getWidth())
1476 || (this->getHeight() != C->
getHeight()))
1478 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1480 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1483 for(
unsigned int i = 0; i < height * width; i++)
1500 template<
class Type>
1504 unsigned int r = height/2;
1505 unsigned int c = width/2;
1508 "Images are not allocated in vpImage<>::sub()")) ;
1512 for(
unsigned int y = 0; y < r; y++)
1513 for(
unsigned int x = 0; x < c; x++)
1514 (*res)[y][x] = (*this)[y*2][x*2];
1528 template<
class Type>
1532 unsigned int r = height/4;
1533 unsigned int c = width/4;
1536 "Images are not allocated in vpImage<>::sub()")) ;
1540 for(
unsigned int y = 0; y < r; y++)
1541 for(
unsigned int x = 0; x < c; x++)
1542 (*res)[y][x] = (*this)[y*4][x*4];
1556 template<
class Type>
1565 "Images are not allocated in vpImage<>::sub()")) ;
1570 for(
int j = 0; j < h; j++)
1571 for(
int i = 0; i < w; i++)
1572 (*res)[j][i] = (*this)[j/2][i/2];
1583 for(
int j = 0; j < h; j += 2)
1584 for(
int i = 1; i < w - 1; i += 2)
1585 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*
this)[j/2][i/2 + 1]));
1588 for(
int j = 1; j < h - 1; j += 2)
1589 for(
int i = 0; i < w; i += 2)
1590 (*res)[j][i] = (Type)(0.5 * ((*
this)[j/2][i/2] + (*this)[j/2+1][i/2]));
1593 for(
int j = 1; j < h - 1; j += 2)
1594 for(
int i = 1; i < w - 1; i += 2)
1595 (*res)[j][i] = (Type)(0.25 * ((*
this)[j/2][i/2] + (*this)[j/2][i/2+1] +
1596 (*this)[j/2+1][i/2] + (*this)[j/2+1][i/2+1]));
1599 #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 without initializing it.
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)