47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpException.h>
50 #include <visp3/core/vpImageException.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpRGBa.h>
124 vpImage(
unsigned int height,
unsigned int width) ;
126 vpImage(
unsigned int height,
unsigned int width, Type value) ;
128 vpImage(Type *
const array,
const unsigned int height,
const unsigned int width,
const bool copyData=
false) ;
132 void init(
unsigned int height,
unsigned int width) ;
134 void init(
unsigned int height,
unsigned int width, Type value) ;
136 void init(Type *
const array,
const unsigned int height,
const unsigned int width,
const bool copyData=
false);
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 ;
319 unsigned int npixels ;
321 unsigned int height ;
353 for (
unsigned int i=0 ; i < npixels ; i++)
379 if (h != this->height) {
387 if ((h != this->height) || (w != this->width))
389 if (bitmap != NULL) {
399 npixels=width*height;
401 if (bitmap == NULL) bitmap =
new Type[npixels] ;
408 "cannot allocate bitmap ")) ;
411 if (row == NULL) row =
new Type*[height] ;
417 "cannot allocate row ")) ;
421 for ( i =0 ; i < height ; i++)
422 row[i] = bitmap + i*width ;
441 if (h != this->height) {
449 if ( (copyData && ((h != this->height) || (w != this->width))) || !copyData ) {
450 if (bitmap != NULL) {
459 npixels = width*height;
462 if (bitmap == NULL) bitmap =
new Type[npixels];
464 if (bitmap == NULL) {
466 "cannot allocate bitmap ")) ;
470 memcpy(bitmap, array, (
size_t) (npixels *
sizeof(Type)));
476 if (row == NULL) row =
new Type*[height];
479 "cannot allocate row ")) ;
482 for (
unsigned int i = 0 ; i < height ; i++) {
483 row[i] = bitmap + i*width;
507 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
538 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
567 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
571 init(array, h, w, copyData);
590 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
715 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
720 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
721 for (
unsigned int i =0 ; i < this->height ; i++) row[i] = bitmap + i*this->width ;
739 for (
unsigned int i=0 ; i < npixels ; i++)
741 if (bitmap[i]>m) m = bitmap[i] ;
755 for (
unsigned int i=0 ; i < npixels ; i++)
756 if (bitmap[i]<m) m = bitmap[i] ;
770 min = max = bitmap[0];
771 for (
unsigned int i=0 ; i < npixels ; i++)
773 if (bitmap[i]<min) min = bitmap[i] ;
774 if (bitmap[i]>max) max = bitmap[i] ;
794 this->width = I.width;
795 this->height = I.height;
796 this->npixels = I.npixels;
802 bitmap =
new Type[npixels] ;
808 "cannot allocate bitmap ")) ;
812 row =
new Type*[height] ;
817 "cannot allocate row ")) ;
820 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
822 for (
unsigned int i=0; i<this->height; i++){
823 row[i] = bitmap + i*this->width;
845 for (
unsigned int i=0 ; i < npixels ; i++)
864 for (
unsigned int i=0 ; i < npixels ; i++)
866 if (bitmap[i] != I.
bitmap[i])
884 for (
unsigned int i=0 ; i < npixels ; i++)
886 if (bitmap[i] == I.
bitmap[i])
941 int itl = (int)topLeft.
get_i();
942 int jtl = (int)topLeft.
get_j();
948 int dest_w = (int)this->getWidth();
949 int dest_h = (int)this->getHeight();
955 if (itl >= dest_h || jtl >= dest_w)
968 if (src_w - src_jbegin > dest_w - dest_jbegin)
969 wsize = dest_w - dest_jbegin;
971 wsize = src_w - src_jbegin;
973 if (src_h - src_ibegin > dest_h - dest_ibegin)
974 hsize = dest_h - dest_ibegin;
976 hsize = src_h - src_ibegin;
978 for (
int i = 0; i < hsize; i++)
980 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
981 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
983 memcpy(destBitmap,srcBitmap,wsize*
sizeof(Type));
1016 template<
class Type>
1020 unsigned int h = height/2;
1021 unsigned int w = width/2;
1023 for(
unsigned int i = 0; i < h; i++)
1024 for(
unsigned int j = 0; j < w; j++)
1025 res[i][j] = (*
this)[i<<1][j<<1];
1050 template<
class Type>
1054 unsigned int h = height/4;
1055 unsigned int w = width/4;
1057 for(
unsigned int i = 0; i < h; i++)
1058 for(
unsigned int j = 0; j < w; j++)
1059 res[i][j] = (*
this)[i<<2][j<<2];
1095 template<
class Type>
1104 for(
int i = 0; i < h; i++)
1105 for(
int j = 0; j < w; j++)
1106 res[i][j] = (*
this)[i>>1][j>>1];
1117 for(
int i = 0; i < h; i += 2)
1118 for(
int j = 1; j < w - 1; j += 2)
1119 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1120 + (*this)[i>>1][(j>>1) + 1]));
1123 for(
int i = 1; i < h - 1; i += 2)
1124 for(
int j = 0; j < w; j += 2)
1125 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1126 + (*this)[(i>>1)+1][j>>1]));
1129 for(
int i = 1; i < h - 1; i += 2)
1130 for(
int j = 1; j < w - 1; j += 2)
1131 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1132 + (*this)[i>>1][(j>>1)+1]
1133 + (*
this)[(i>>1)+1][j>>1]
1134 + (*
this)[(i>>1)+1][(j>>1)+1]));
1147 template<
class Type>
1173 unsigned int iround, jround;
1174 double rfrac, cfrac;
1176 iround = (
unsigned int)floor(i);
1177 jround = (
unsigned int)floor(j);
1179 if (iround >= height || jround >= width) {
1182 "Pixel outside the image"));
1186 i = (double)(height - 1);
1189 j = (double)(width - 1);
1191 double rratio = i - (double) iround;
1194 double cratio = j - (double) jround;
1198 rfrac = 1.0f - rratio;
1199 cfrac = 1.0f - cratio;
1202 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1203 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1228 unsigned int iround, jround;
1229 double rfrac, cfrac;
1231 iround = (
unsigned int)floor(i);
1232 jround = (
unsigned int)floor(j);
1234 if (iround >= height || jround >= width) {
1237 "Pixel outside the image"));
1241 i = (double)(height - 1);
1244 j = (double)(width - 1);
1246 double rratio = i - (double) iround;
1249 double cratio = j - (double) jround;
1253 rfrac = 1.0f - rratio;
1254 cfrac = 1.0f - cratio;
1257 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1258 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1265 unsigned int iround, jround;
1266 double rfrac, cfrac;
1268 iround = (
unsigned int)floor(i);
1269 jround = (
unsigned int)floor(j);
1271 if (iround >= height || jround >= width) {
1274 "Pixel outside the image"));
1278 i = (double)(height - 1);
1281 j = (double)(width - 1);
1283 double rratio = i - (double) iround;
1286 double cratio = j - (double) jround;
1290 rfrac = 1.0f - rratio;
1291 cfrac = 1.0f - cratio;
1293 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1294 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1295 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1296 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1297 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1298 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1312 template<
class Type>
1321 unsigned int iround, jround;
1322 double rfrac, cfrac;
1324 iround = (
unsigned int)floor(ip.
get_i());
1325 jround = (
unsigned int)floor(ip.
get_j());
1327 if (iround >= height || jround >= width) {
1330 "Pixel outside the image"));
1333 if (ip.
get_i() > height - 1)
1334 ip.
set_i((
double)(height - 1));
1336 if (ip.
get_j() > width - 1)
1337 ip.
set_j((
double)(width - 1));
1339 double rratio = ip.
get_i() - (double) iround;
1342 double cratio = ip.
get_j() - (double) jround;
1346 rfrac = 1.0f - rratio;
1347 cfrac = 1.0f - cratio;
1350 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1351 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1359 unsigned int iround, jround;
1360 double rfrac, cfrac;
1362 iround = (
unsigned int)floor(ip.
get_i());
1363 jround = (
unsigned int)floor(ip.
get_j());
1365 if (iround >= height || jround >= width) {
1368 "Pixel outside the image"));
1371 if (ip.
get_i() > height - 1)
1372 ip.
set_i((
double)(height - 1));
1374 if (ip.
get_j() > width - 1)
1375 ip.
set_j((
double)(width - 1));
1377 double rratio = ip.
get_i() - (double) iround;
1380 double cratio = ip.
get_j() - (double) jround;
1384 rfrac = 1.0f - rratio;
1385 cfrac = 1.0f - cratio;
1388 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1389 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1396 unsigned int iround, jround;
1397 double rfrac, cfrac;
1399 iround = (
unsigned int)floor(ip.
get_i());
1400 jround = (
unsigned int)floor(ip.
get_j());
1402 if (iround >= height || jround >= width) {
1405 "Pixel outside the image"));
1408 if (ip.
get_i() > height - 1)
1409 ip.
set_i((
double)(height - 1));
1411 if (ip.
get_j() > width - 1)
1412 ip.
set_j((
double)(width - 1));
1414 double rratio = ip.
get_i() - (double) iround;
1417 double cratio = ip.
get_j() - (double) jround;
1421 rfrac = 1.0f - rratio;
1422 cfrac = 1.0f - cratio;
1424 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1425 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1426 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1427 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1428 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1429 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1462 template<
class Type>
1468 if ((this->getHeight() != C.
getHeight())
1469 || (this->getWidth() != C.
getWidth()))
1470 C.
resize(this->getHeight(), this->getWidth());
1475 std::cout << me << std::endl ;
1481 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1483 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1486 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1503 template<
class Type>
1517 std::cout << me << std::endl ;
1523 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1525 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1543 template<
class Type>
1547 std::cerr <<
"Not implemented !" << std::endl;
1558 unsigned char *ptrStart = (
unsigned char*) bitmap;
1559 unsigned char *ptrEnd = ptrStart + size;
1560 unsigned char *ptrCurrent = ptrStart;
1562 while(ptrCurrent != ptrEnd) {
1563 *ptrCurrent = lut[*ptrCurrent];
1576 unsigned char *ptrStart = (
unsigned char*) bitmap;
1577 unsigned char *ptrEnd = ptrStart + size*4;
1578 unsigned char *ptrCurrent = ptrStart;
1580 while(ptrCurrent != ptrEnd) {
1581 *ptrCurrent = lut[*ptrCurrent].R;
1584 *ptrCurrent = lut[*ptrCurrent].G;
1587 *ptrCurrent = lut[*ptrCurrent].B;
1590 *ptrCurrent = lut[*ptrCurrent].A;
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)
void performLut(const Type(&lut)[256])
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)