42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDebug.h>
44 #include <visp3/core/vpEndian.h>
45 #include <visp3/core/vpException.h>
46 #include <visp3/core/vpImageException.h>
47 #include <visp3/core/vpImagePoint.h>
48 #include <visp3/core/vpRGBa.h>
49 #include <visp3/core/vpRGBf.h>
51 #if defined(VISP_HAVE_THREADS)
62 #if defined(_MSC_VER) && (_MSC_VER < 1700)
63 typedef long long int64_t;
64 typedef unsigned short uint16_t;
122 template <
class Type>
class vpImage;
134 template <
class Type>
class vpImage
146 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
148 vpImage(vpImage<Type> &&);
151 vpImage(
unsigned int height,
unsigned int width);
153 vpImage(
unsigned int height,
unsigned int width, Type value);
155 vpImage(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
175 inline unsigned int getCols()
const {
return width; }
184 inline unsigned int getHeight()
const {
return height; }
220 inline unsigned int getRows()
const {
return height; }
229 inline unsigned int getSize()
const {
return width * height; }
232 Type
getValue(
unsigned int i,
unsigned int j)
const;
249 inline unsigned int getWidth()
const {
return width; }
255 void init(
unsigned int height,
unsigned int width);
257 void init(
unsigned int height,
unsigned int width, Type value);
259 void init(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
270 inline const Type *
operator[](
unsigned int i)
const {
return row[i]; }
271 inline const Type *
operator[](
int i)
const {
return row[i]; }
279 inline Type
operator()(
unsigned int i,
unsigned int j)
const {
return bitmap[i * width + j]; }
285 inline void operator()(
unsigned int i,
unsigned int j,
const Type &v) {
bitmap[i * width + j] = v; }
299 unsigned int i = (
unsigned int)ip.
get_i();
300 unsigned int j = (
unsigned int)ip.
get_j();
302 return bitmap[i * width + j];
315 unsigned int i = (
unsigned int)ip.
get_i();
316 unsigned int j = (
unsigned int)ip.
get_j();
318 bitmap[i * width + j] = v;
329 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
336 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
342 void resize(
unsigned int h,
unsigned int w);
344 void resize(
unsigned int h,
unsigned int w,
const Type &val);
355 unsigned int npixels;
364 if (I.
bitmap ==
nullptr) {
368 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
369 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
387 if (I.
bitmap ==
nullptr) {
391 std::ios_base::fmtflags original_flags = s.flags();
393 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
394 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
395 s << std::setw(3) << static_cast<unsigned>(I[i][j]) <<
" ";
399 s << std::setw(3) << static_cast<unsigned>(I[i][I.
getWidth() - 1]);
407 s.flags(original_flags);
413 if (I.
bitmap ==
nullptr) {
417 std::ios_base::fmtflags original_flags = s.flags();
419 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
420 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
421 s << std::setw(4) << static_cast<int>(I[i][j]) <<
" ";
425 s << std::setw(4) << static_cast<int>(I[i][I.
getWidth() - 1]);
433 s.flags(original_flags);
439 if (I.
bitmap ==
nullptr) {
443 std::ios_base::fmtflags original_flags = s.flags();
446 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
447 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
460 s.flags(original_flags);
466 if (I.
bitmap ==
nullptr) {
470 std::ios_base::fmtflags original_flags = s.flags();
473 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
474 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
487 s.flags(original_flags);
491 #if defined(VISP_HAVE_THREADS)
494 struct vpImageLut_Param_t
496 unsigned int m_start_index;
497 unsigned int m_end_index;
499 unsigned char m_lut[256];
500 unsigned char *m_bitmap;
502 vpImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { }
504 vpImageLut_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
505 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
509 void performLutThread(vpImageLut_Param_t *imageLut_param)
511 unsigned int start_index = imageLut_param->m_start_index;
512 unsigned int end_index = imageLut_param->m_end_index;
514 unsigned char *bitmap = imageLut_param->m_bitmap;
516 unsigned char *ptrStart = bitmap + start_index;
517 unsigned char *ptrEnd = bitmap + end_index;
518 unsigned char *ptrCurrent = ptrStart;
520 if (end_index - start_index >= 8) {
522 for (; ptrCurrent <= ptrEnd - 8;) {
523 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
526 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
529 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
532 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
535 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
538 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
541 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
544 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
549 for (; ptrCurrent != ptrEnd; ++ptrCurrent) {
550 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
554 struct vpImageLutRGBa_Param_t
556 unsigned int m_start_index;
557 unsigned int m_end_index;
560 unsigned char *m_bitmap;
562 vpImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { }
564 vpImageLutRGBa_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
565 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
569 void performLutRGBaThread(vpImageLutRGBa_Param_t *imageLut_param)
571 unsigned int start_index = imageLut_param->m_start_index;
572 unsigned int end_index = imageLut_param->m_end_index;
574 unsigned char *bitmap = imageLut_param->m_bitmap;
576 unsigned char *ptrStart = bitmap + start_index * 4;
577 unsigned char *ptrEnd = bitmap + end_index * 4;
578 unsigned char *ptrCurrent = ptrStart;
580 if (end_index - start_index >= 4 * 2) {
582 for (; ptrCurrent <= ptrEnd - 4 * 2;) {
583 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
585 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
587 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
589 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
592 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
594 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
596 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
598 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
603 while (ptrCurrent != ptrEnd) {
604 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
607 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
610 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
613 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
629 std::fill(bitmap, bitmap + npixels, value);
637 if (h != this->height) {
638 if (row !=
nullptr) {
644 if ((h != this->height) || (w != this->width)) {
645 if (bitmap !=
nullptr) {
656 npixels = width * height;
658 if (bitmap ==
nullptr) {
659 bitmap =
new Type[npixels];
662 if (bitmap ==
nullptr) {
666 row =
new Type *[height];
667 if (row ==
nullptr) {
671 for (
unsigned int i = 0; i < height; i++)
672 row[i] = bitmap + i * width;
678 template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
680 if (h != this->height) {
681 if (row !=
nullptr) {
688 if ((copyData && ((h != this->height) || (w != this->width))) || !copyData) {
689 if (bitmap !=
nullptr) {
697 hasOwnership = copyData;
701 npixels = width * height;
704 if (bitmap ==
nullptr)
705 bitmap =
new Type[npixels];
707 if (bitmap ==
nullptr) {
712 memcpy(
static_cast<void *
>(bitmap),
static_cast<void *
>(array), (
size_t)(npixels *
sizeof(Type)));
720 row =
new Type *[height];
721 if (row ==
nullptr) {
725 for (
unsigned int i = 0; i < height; i++) {
726 row[i] = bitmap + i * width;
733 template <
class Type>
735 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
743 template <
class Type>
745 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
753 template <
class Type>
755 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
757 init(array, h, w, copyData);
763 template <
class Type>
764 vpImage<Type>::vpImage() : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
818 if (bitmap !=
nullptr) {
825 if (row !=
nullptr) {
842 template <
class Type>
844 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
848 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.
bitmap), I.npixels *
sizeof(Type));
852 #if ((__cplusplus >= 201103L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L)))
856 template <class Type>
858 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row),
859 hasOwnership(I.hasOwnership)
867 I.hasOwnership =
false;
883 for (
unsigned int i = 0; i < npixels; i++) {
906 for (
unsigned int i = 0; i < npixels; i++) {
912 for (
unsigned int i = 0; i < npixels; i++) {
934 for (
unsigned int i = 0; i < npixels; i++) {
940 for (
unsigned int i = 0; i < npixels; i++) {
953 if ((height == 0) || (width == 0)) {
957 return getSum() / (height * width);
967 unsigned int nbValidPoints = 0;
968 return getMeanValue(p_mask, nbValidPoints);
980 if ((height == 0) || (width == 0)) {
984 double sum =
getSum(p_mask, nbValidPoints);
985 return sum / nbValidPoints;
993 double mean = getMeanValue();
994 return getStdev(mean);
1004 unsigned int nbValidPoints = 0;
1005 double mean = getMeanValue(p_mask, nbValidPoints);
1006 return getStdev(mean, nbValidPoints, p_mask);
1022 const unsigned int size = width * height;
1024 for (
unsigned int i = 0; i < size; ++i) {
1025 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
1027 sum /=
static_cast<double>(size);
1028 return std::sqrt(sum);
1047 if (p_mask ==
nullptr) {
1048 return getStdev(mean);
1050 const unsigned int size = width * height;
1052 for (
unsigned int i = 0; i < size; ++i) {
1054 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
1057 sum /=
static_cast<double>(nbValidPoints);
1058 return std::sqrt(sum);
1076 if ((height == 0) || (width == 0)) {
1081 const unsigned int size = height * width;
1082 for (
unsigned int i = 0; i < size; ++i) {
1083 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1084 res += (val - mean) * (val - mean);
1086 res /=
static_cast<double>(size);
1087 return std::sqrt(res);
1107 if ((height == 0) || (width == 0)) {
1111 if (p_mask ==
nullptr) {
1115 const unsigned int size = width * height;
1117 for (
unsigned int i = 0; i < size; ++i) {
1119 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1120 sum += (val - mean) * (val - mean);
1123 sum /=
static_cast<double>(nbValidPoints);
1124 return std::sqrt(sum);
1145 if ((height == 0) || (width == 0)) {
1150 const unsigned int size = height * width;
1151 for (
unsigned int i = 0; i < size; ++i) {
1152 double val =
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1153 res += (val - mean) * (val - mean);
1155 res /=
static_cast<double>(size);
1156 return std::sqrt(res);
1179 if ((height == 0) || (width == 0)) {
1183 if (p_mask ==
nullptr) {
1184 return getStdev(mean);
1187 const unsigned int size = width * height;
1189 for (
unsigned int i = 0; i < size; ++i) {
1191 double val =
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1192 sum += (val - mean) * (val - mean);
1195 sum /=
static_cast<double>(nbValidPoints);
1196 return std::sqrt(sum);
1211 for (
unsigned int i = 0; i < npixels; i++) {
1212 if (bitmap[i] < m) {
1216 (void)onlyFiniteVal;
1233 if (onlyFiniteVal) {
1234 for (
unsigned int i = 0; i < npixels; i++)
1239 for (
unsigned int i = 0; i < npixels; i++)
1259 if (onlyFiniteVal) {
1260 for (
unsigned int i = 0; i < npixels; i++)
1265 for (
unsigned int i = 0; i < npixels; i++)
1287 min = max = bitmap[0];
1288 for (
unsigned int i = 0; i < npixels; i++) {
1289 if (bitmap[i] < min)
1291 if (bitmap[i] > max)
1294 (void)onlyFiniteVal;
1314 if (onlyFiniteVal) {
1315 for (
unsigned int i = 0; i < npixels; i++) {
1325 for (
unsigned int i = 0; i < npixels; i++) {
1351 if (onlyFiniteVal) {
1352 for (
unsigned int i = 0; i < npixels; i++) {
1362 for (
unsigned int i = 0; i < npixels; i++) {
1386 min = max = bitmap[0];
1387 if (onlyFiniteVal) {
1388 for (
unsigned int i = 0; i < npixels; i++) {
1390 if (bitmap[i].R < min.
R)
1391 min.
R = bitmap[i].R;
1392 if (bitmap[i].R > max.
R)
1393 max.
R = bitmap[i].R;
1396 if (bitmap[i].G < min.
G)
1397 min.
G = bitmap[i].G;
1398 if (bitmap[i].G > max.
G)
1399 max.
G = bitmap[i].G;
1402 if (bitmap[i].B < min.
B)
1403 min.
B = bitmap[i].B;
1404 if (bitmap[i].B > max.
B)
1405 max.
B = bitmap[i].B;
1410 for (
unsigned int i = 0; i < npixels; i++) {
1411 if (bitmap[i].R < min.
R)
1412 min.
R = bitmap[i].R;
1413 if (bitmap[i].R > max.
R)
1414 max.
R = bitmap[i].R;
1416 if (bitmap[i].G < min.
G)
1417 min.
G = bitmap[i].G;
1418 if (bitmap[i].G > max.
G)
1419 max.
G = bitmap[i].G;
1421 if (bitmap[i].B < min.
B)
1422 min.
B = bitmap[i].B;
1423 if (bitmap[i].B > max.
B)
1424 max.
B = bitmap[i].B;
1450 template <
class Type>
1455 "values of an empty image"));
1457 Type min = bitmap[0], max = bitmap[0];
1459 for (
unsigned int i = 0; i < height; i++) {
1460 for (
unsigned int j = 0; j < width; j++) {
1461 if (row[i][j] < min) {
1466 if (row[i][j] > max) {
1473 if (minLoc !=
nullptr)
1476 if (maxLoc !=
nullptr)
1479 if (minVal !=
nullptr)
1482 if (maxVal !=
nullptr)
1506 for (
unsigned int i = 0; i < npixels; i++)
1526 for (
unsigned int i = 0; i < npixels; i++) {
1527 if (bitmap[i] != I.
bitmap[i]) {
1587 int itl = (int)topLeft.
get_i();
1588 int jtl = (int)topLeft.
get_j();
1590 int dest_ibegin = 0;
1591 int dest_jbegin = 0;
1594 int dest_w = (int)this->getWidth();
1595 int dest_h = (int)this->getHeight();
1601 if (itl >= dest_h || jtl >= dest_w)
1614 if (src_w - src_jbegin > dest_w - dest_jbegin)
1615 wsize = dest_w - dest_jbegin;
1617 wsize = src_w - src_jbegin;
1619 if (src_h - src_ibegin > dest_h - dest_ibegin)
1620 hsize = dest_h - dest_ibegin;
1622 hsize = src_h - src_ibegin;
1624 for (
int i = 0; i < hsize; i++) {
1625 Type *srcBitmap = src.
bitmap + ((src_ibegin + i) * src_w + src_jbegin);
1626 Type *destBitmap = this->bitmap + ((dest_ibegin + i) * dest_w + dest_jbegin);
1628 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap), (
size_t)wsize *
sizeof(Type));
1664 unsigned int h = height / 2;
1665 unsigned int w = width / 2;
1667 for (
unsigned int i = 0; i < h; i++)
1668 for (
unsigned int j = 0; j < w; j++)
1669 res[i][j] = (*
this)[i << 1][j << 1];
1689 template <
class Type>
1692 if (v_scale == 1 && h_scale == 1) {
1696 unsigned int h = height / v_scale;
1697 unsigned int w = width / h_scale;
1699 for (
unsigned int i = 0; i < h; i++)
1700 for (
unsigned int j = 0; j < w; j++)
1701 sampled[i][j] = (*
this)[i * v_scale][j * h_scale];
1728 unsigned int h = height / 4;
1729 unsigned int w = width / 4;
1731 for (
unsigned int i = 0; i < h; i++)
1732 for (
unsigned int j = 0; j < w; j++)
1733 res[i][j] = (*
this)[i << 2][j << 2];
1775 for (
int i = 0; i < h; i++)
1776 for (
int j = 0; j < w; j++)
1777 res[i][j] = (*
this)[i >> 1][j >> 1];
1788 for (
int i = 0; i < h; i += 2)
1789 for (
int j = 1; j < w - 1; j += 2)
1790 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
1793 for (
int i = 1; i < h - 1; i += 2)
1794 for (
int j = 0; j < w; j += 2)
1795 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
1798 for (
int i = 1; i < h - 1; i += 2)
1799 for (
int j = 1; j < w - 1; j += 2)
1800 res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
1801 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
1818 if (i >= height || j >= width) {
1843 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1846 if (height * width == 0) {
1850 unsigned int iround =
static_cast<unsigned int>(floor(i));
1851 unsigned int jround =
static_cast<unsigned int>(floor(j));
1853 double rratio = i -
static_cast<double>(iround);
1854 double cratio = j -
static_cast<double>(jround);
1856 double rfrac = 1.0 - rratio;
1857 double cfrac = 1.0 - cratio;
1859 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
1860 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
1863 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1864 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1875 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1878 if (height * width == 0) {
1882 unsigned int iround =
static_cast<unsigned int>(floor(i));
1883 unsigned int jround =
static_cast<unsigned int>(floor(j));
1885 double rratio = i -
static_cast<double>(iround);
1886 double cratio = j -
static_cast<double>(jround);
1888 double rfrac = 1.0 - rratio;
1889 double cfrac = 1.0 - cratio;
1891 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
1892 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
1894 return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac +
1895 (row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio;
1903 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1906 if (height * width == 0) {
1911 #if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA))
1913 const int32_t precision = 1 << 16;
1914 int64_t y =
static_cast<int64_t
>(i * precision);
1915 int64_t x =
static_cast<int64_t
>(j * precision);
1917 int64_t iround = y & (~0xFFFF);
1918 int64_t jround = x & (~0xFFFF);
1920 int64_t rratio = y - iround;
1921 int64_t cratio = x - jround;
1923 int64_t rfrac = precision - rratio;
1924 int64_t cfrac = precision - cratio;
1926 int64_t x_ = x >> 16;
1927 int64_t y_ = y >> 16;
1929 if (y_ + 1 < height && x_ + 1 < width) {
1933 return static_cast<unsigned char>((((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cfrac +
1934 ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >>
1937 else if (y_ + 1 < height) {
1938 return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
1940 else if (x_ + 1 < width) {
1942 return static_cast<unsigned char>(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16);
1948 unsigned int iround =
static_cast<unsigned int>(floor(i));
1949 unsigned int jround =
static_cast<unsigned int>(floor(j));
1951 if (iround >= height || jround >= width) {
1956 double rratio = i -
static_cast<double>(iround);
1957 double cratio = j -
static_cast<double>(jround);
1959 double rfrac = 1.0 - rratio;
1960 double cfrac = 1.0 - cratio;
1962 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
1963 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
1966 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1967 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1978 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1981 if (height * width == 0) {
1985 unsigned int iround =
static_cast<unsigned int>(floor(i));
1986 unsigned int jround =
static_cast<unsigned int>(floor(j));
1988 double rratio = i -
static_cast<double>(iround);
1989 double cratio = j -
static_cast<double>(jround);
1991 double rfrac = 1.0 - rratio;
1992 double cfrac = 1.0 - cratio;
1994 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
1995 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
1998 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
2000 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
2003 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
2005 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
2008 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
2010 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
2022 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
2025 if (height * width == 0) {
2029 unsigned int iround =
static_cast<unsigned int>(floor(i));
2030 unsigned int jround =
static_cast<unsigned int>(floor(j));
2032 double rratio = i -
static_cast<double>(iround);
2033 double cratio = j -
static_cast<double>(jround);
2035 double rfrac = 1.0 - rratio;
2036 double cfrac = 1.0 - cratio;
2038 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
2039 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
2042 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
2044 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
2047 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
2049 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
2052 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
2054 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
2057 return vpRGBf(
static_cast<float>(valueR),
static_cast<float>(valueG),
static_cast<float>(valueB));
2111 if ((height == 0) || (width == 0))
2115 for (
unsigned int i = 0; i < height * width; ++i) {
2116 res +=
static_cast<double>(bitmap[i]);
2130 if ((height == 0) || (width == 0))
2132 if (p_mask ==
nullptr) {
2133 nbValidPoints = height * width;
2139 unsigned int size = height * width;
2140 for (
unsigned int i = 0; i < size; ++i) {
2142 res +=
static_cast<double>(bitmap[i]);
2159 if ((height == 0) || (width == 0))
2163 for (
unsigned int i = 0; i < height * width; ++i) {
2164 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
2182 if ((height == 0) || (width == 0)) {
2186 if (p_mask ==
nullptr) {
2187 nbValidPoints = height * width;
2193 unsigned int size = height * width;
2194 for (
unsigned int i = 0; i < size; ++i) {
2196 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
2212 if ((height == 0) || (width == 0))
2216 for (
unsigned int i = 0; i < height * width; ++i) {
2217 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
2235 if ((height == 0) || (width == 0)) {
2238 if (p_mask ==
nullptr) {
2239 nbValidPoints = height * width;
2245 unsigned int size = height * width;
2246 for (
unsigned int i = 0; i < size; ++i) {
2248 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
2289 C.
resize(this->getHeight(), this->getWidth());
2292 std::cout << me << std::endl;
2296 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
2300 for (
unsigned int i = 0; i < this->getWidth() * this->getHeight(); i++) {
2324 std::cout << me << std::endl;
2347 std::cerr <<
"Not implemented !" << std::endl;
2363 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2364 unsigned char *ptrEnd = ptrStart + size;
2365 unsigned char *ptrCurrent = ptrStart;
2367 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2368 #if !defined(VISP_HAVE_THREADS)
2369 use_single_thread =
true;
2372 if (!use_single_thread &&
getSize() <= nbThreads) {
2373 use_single_thread =
true;
2376 if (use_single_thread) {
2379 while (ptrCurrent != ptrEnd) {
2380 *ptrCurrent = lut[*ptrCurrent];
2385 #if defined(VISP_HAVE_THREADS)
2387 std::vector<std::thread *> threadpool;
2388 std::vector<vpImageLut_Param_t *> imageLutParams;
2390 unsigned int image_size =
getSize();
2391 unsigned int step = image_size / nbThreads;
2392 unsigned int last_step = image_size - step * (nbThreads - 1);
2394 for (
unsigned int index = 0; index < nbThreads; index++) {
2395 unsigned int start_index = index * step;
2396 unsigned int end_index = (index + 1) * step;
2398 if (index == nbThreads - 1) {
2399 end_index = start_index + last_step;
2402 vpImageLut_Param_t *imageLut_param =
new vpImageLut_Param_t(start_index, end_index,
bitmap);
2403 memcpy(imageLut_param->m_lut, lut, 256 *
sizeof(
unsigned char));
2405 imageLutParams.push_back(imageLut_param);
2408 std::thread *imageLut_thread =
new std::thread(&performLutThread, imageLut_param);
2409 threadpool.push_back(imageLut_thread);
2412 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2414 threadpool[cpt]->join();
2418 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2419 delete threadpool[cpt];
2422 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2423 delete imageLutParams[cpt];
2442 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2443 unsigned char *ptrEnd = ptrStart + size * 4;
2444 unsigned char *ptrCurrent = ptrStart;
2446 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2447 #if !defined(VISP_HAVE_THREADS)
2448 use_single_thread =
true;
2451 if (!use_single_thread &&
getSize() <= nbThreads) {
2452 use_single_thread =
true;
2455 if (use_single_thread) {
2457 while (ptrCurrent != ptrEnd) {
2458 *ptrCurrent = lut[*ptrCurrent].R;
2461 *ptrCurrent = lut[*ptrCurrent].G;
2464 *ptrCurrent = lut[*ptrCurrent].B;
2467 *ptrCurrent = lut[*ptrCurrent].A;
2472 #if defined(VISP_HAVE_THREADS)
2474 std::vector<std::thread *> threadpool;
2475 std::vector<vpImageLutRGBa_Param_t *> imageLutParams;
2477 unsigned int image_size =
getSize();
2478 unsigned int step = image_size / nbThreads;
2479 unsigned int last_step = image_size - step * (nbThreads - 1);
2481 for (
unsigned int index = 0; index < nbThreads; index++) {
2482 unsigned int start_index = index * step;
2483 unsigned int end_index = (index + 1) * step;
2485 if (index == nbThreads - 1) {
2486 end_index = start_index + last_step;
2489 vpImageLutRGBa_Param_t *imageLut_param =
new vpImageLutRGBa_Param_t(start_index, end_index, (
unsigned char *)
bitmap);
2490 memcpy(
static_cast<void *
>(imageLut_param->m_lut), lut, 256 *
sizeof(
vpRGBa));
2492 imageLutParams.push_back(imageLut_param);
2495 std::thread *imageLut_thread =
new std::thread(&performLutRGBaThread, imageLut_param);
2496 threadpool.push_back(imageLut_thread);
2499 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2501 threadpool[cpt]->join();
2505 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2506 delete threadpool[cpt];
2509 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2510 delete imageLutParams[cpt];
2521 swap(first.npixels, second.npixels);
2522 swap(first.width, second.width);
2523 swap(first.height, second.height);
2524 swap(first.row, second.row);
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Class that defines generic functionalities for display.
error that can be emitted by ViSP classes.
@ memoryAllocationError
Memory allocation error.
@ notInitializedError
Image not initialized.
@ notInTheImage
Pixel not in the image.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_ij(double ii, double jj)
Definition of the vpImage class member functions.
Type operator()(const vpImagePoint &ip) const
void destroy()
Destructor : Memory de-allocation.
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
void halfSizeImage(vpImage< Type > &res) const
vpImage< Type > & operator=(vpImage< Type > other)
Copy operator.
Type getMinValue(bool onlyFiniteVal=true) const
Return the minimum value within the bitmap.
void quarterSizeImage(vpImage< Type > &res) const
void getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal=nullptr, Type *maxVal=nullptr) const
Get the position of the minimum and/or the maximum pixel value within the bitmap and the correspondin...
void init(unsigned int height, unsigned int width)
Set the size of the image.
Type * operator[](unsigned int i)
operator[] allows operation like I[i] = x.
void resize(unsigned int h, unsigned int w, const Type &val)
resize the image : Image initialization
unsigned int getWidth() const
friend std::ostream & operator<<(std::ostream &s, const vpImage< unsigned char > &I)
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
double getMeanValue(const vpImage< bool > *p_mask, unsigned int &nbValidPoints) const
Return the mean value of the bitmap.
unsigned int getNumberOfPixel() const
double getSum() const
Get the sum of the image. For a vpRGBf image, we takes the sum of the R, G and B components.
Type getValue(double i, double j) const
void doubleSizeImage(vpImage< Type > &res)
vpImage(unsigned int height, unsigned int width, Type value)
constructor set the size of the image and init all the pixel
void performLut(const Type(&lut)[256], unsigned int nbThreads=1)
const Type * operator[](int i) const
double getMeanValue() const
Return the mean value of the bitmap.
friend std::ostream & operator<<(std::ostream &s, const vpImage< float > &I)
bool operator==(const vpImage< Type > &I) const
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
void sub(const vpImage< Type > &A, const vpImage< Type > &B, vpImage< Type > &C) const
Type getValue(unsigned int i, unsigned int j) const
double getValue(double i, double j) const
double getStdev() const
Return the standard deviation of the bitmap.
double getSum() const
Compute the sum of image intensities. For vpRGBa image type, compute the sum (R+G+B) of image intensi...
vpImage< Type > operator-(const vpImage< Type > &B) const
void init(unsigned int height, unsigned int width, Type value)
Set the size of the image.
unsigned int getSize() const
friend void swap(vpImage< Type > &first, vpImage< Type > &second)
unsigned int getCols() const
Type * bitmap
points toward the bitmap
const Type * operator[](unsigned int i) const
operator[] allows operation like x = I[i]
double getMeanValue(const vpImage< bool > *p_mask) const
Return the mean value of the bitmap.
Type getValue(const vpImagePoint &ip) const
void sub(const vpImage< Type > &B, vpImage< Type > &C) const
vpImage(Type *const array, unsigned int height, unsigned int width, bool copyData=false)
constructor from an image stored as a continuous array in memory
void init(Type *const array, unsigned int height, unsigned int width, bool copyData=false)
init from an image stored as a continuous array in memory
Type getMaxValue(bool onlyFiniteVal=true) const
Return the maximum value within the bitmap.
virtual ~vpImage()
destructor
unsigned int getHeight() const
double getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage< bool > *p_mask) const
Return the standard deviation of the bitmap.
unsigned int getRows() const
friend std::ostream & operator<<(std::ostream &s, const vpImage< double > &I)
void getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal=true) const
Look for the minimum and the maximum value within the bitmap.
vpImage< Type > & operator=(const Type &v)
= operator : Set all the element of the bitmap to a given value v.
friend std::ostream & operator<<(std::ostream &s, const vpImage< char > &I)
void operator()(const vpImagePoint &ip, const Type &v)
Type operator()(unsigned int i, unsigned int j) const
bool operator!=(const vpImage< Type > &I) const
double getSum(const vpImage< bool > *p_mask, unsigned int &nbValidPoints) const
Compute the sum of image intensities. For vpRGBa image type, compute the sum (R+G+B) of image intensi...
void init(unsigned int h, unsigned int w, Type value)
vpImage(const vpImage< Type > &)
copy constructor
vpImage(unsigned int height, unsigned int width)
constructor set the size of the image
double getStdev(const double &mean) const
Return the standard deviation of the bitmap For a vpRGBa or a vpRGBf image, we compute the standard d...
double getStdev(const vpImage< bool > *p_mask) const
Return the standard deviation of the bitmap.
void operator()(unsigned int i, unsigned int j, const Type &v)
static int round(double x)
static bool isFinite(double value)
VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char *const ptr)