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_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
52 #include <visp3/core/vpThread.h>
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
149 vpImage(
unsigned int height,
unsigned int width);
151 vpImage(
unsigned int height,
unsigned int width, Type value);
153 vpImage(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
173 inline unsigned int getCols()
const {
return width; }
182 inline unsigned int getHeight()
const {
return height; }
212 inline unsigned int getRows()
const {
return height; }
221 inline unsigned int getSize()
const {
return width * height; }
224 Type
getValue(
unsigned int i,
unsigned int j)
const;
240 inline unsigned int getWidth()
const {
return width; }
246 void init(
unsigned int height,
unsigned int width);
248 void init(
unsigned int height,
unsigned int width, Type value);
250 void init(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
261 inline const Type *
operator[](
unsigned int i)
const {
return row[i]; }
262 inline const Type *
operator[](
int i)
const {
return row[i]; }
270 inline Type
operator()(
unsigned int i,
unsigned int j)
const {
return bitmap[i * width + j]; }
276 inline void operator()(
unsigned int i,
unsigned int j,
const Type &v) {
bitmap[i * width + j] = v; }
290 unsigned int i = (
unsigned int)ip.
get_i();
291 unsigned int j = (
unsigned int)ip.
get_j();
293 return bitmap[i * width + j];
306 unsigned int i = (
unsigned int)ip.
get_i();
307 unsigned int j = (
unsigned int)ip.
get_j();
309 bitmap[i * width + j] = v;
320 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
327 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
333 void resize(
unsigned int h,
unsigned int w);
335 void resize(
unsigned int h,
unsigned int w,
const Type &val);
346 unsigned int npixels;
355 if (I.
bitmap ==
nullptr) {
359 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
360 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
378 if (I.
bitmap ==
nullptr) {
382 std::ios_base::fmtflags original_flags = s.flags();
384 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
385 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
386 s << std::setw(3) << static_cast<unsigned>(I[i][j]) <<
" ";
390 s << std::setw(3) << static_cast<unsigned>(I[i][I.
getWidth() - 1]);
398 s.flags(original_flags);
404 if (I.
bitmap ==
nullptr) {
408 std::ios_base::fmtflags original_flags = s.flags();
410 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
411 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
412 s << std::setw(4) << static_cast<int>(I[i][j]) <<
" ";
416 s << std::setw(4) << static_cast<int>(I[i][I.
getWidth() - 1]);
424 s.flags(original_flags);
430 if (I.
bitmap ==
nullptr) {
434 std::ios_base::fmtflags original_flags = s.flags();
437 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
438 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
451 s.flags(original_flags);
457 if (I.
bitmap ==
nullptr) {
461 std::ios_base::fmtflags original_flags = s.flags();
464 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
465 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
478 s.flags(original_flags);
482 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
485 struct vpImageLut_Param_t
487 unsigned int m_start_index;
488 unsigned int m_end_index;
490 unsigned char m_lut[256];
491 unsigned char *m_bitmap;
493 vpImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { }
495 vpImageLut_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
496 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
502 vpImageLut_Param_t *imageLut_param =
static_cast<vpImageLut_Param_t *
>(args);
503 unsigned int start_index = imageLut_param->m_start_index;
504 unsigned int end_index = imageLut_param->m_end_index;
506 unsigned char *bitmap = imageLut_param->m_bitmap;
508 unsigned char *ptrStart = bitmap + start_index;
509 unsigned char *ptrEnd = bitmap + end_index;
510 unsigned char *ptrCurrent = ptrStart;
517 if (end_index - start_index >= 8) {
519 for (; ptrCurrent <= ptrEnd - 8;) {
520 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
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];
546 for (; ptrCurrent != ptrEnd; ++ptrCurrent) {
547 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
553 struct vpImageLutRGBa_Param_t
555 unsigned int m_start_index;
556 unsigned int m_end_index;
559 unsigned char *m_bitmap;
561 vpImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(nullptr) { }
563 vpImageLutRGBa_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
564 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
570 vpImageLutRGBa_Param_t *imageLut_param =
static_cast<vpImageLutRGBa_Param_t *
>(args);
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;
631 std::fill(bitmap, bitmap + npixels, value);
639 if (h != this->height) {
640 if (row !=
nullptr) {
647 if ((h != this->height) || (w != this->width)) {
648 if (bitmap !=
nullptr) {
660 npixels = width * height;
662 if (bitmap ==
nullptr) {
663 bitmap =
new Type[npixels];
667 if (bitmap ==
nullptr) {
672 row =
new Type *[height];
673 if (row ==
nullptr) {
677 for (
unsigned int i = 0; i < height; i++)
678 row[i] = bitmap + i * width;
684 template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
686 if (h != this->height) {
687 if (row !=
nullptr) {
694 if ((copyData && ((h != this->height) || (w != this->width))) || !copyData) {
695 if (bitmap !=
nullptr) {
703 hasOwnership = copyData;
707 npixels = width * height;
710 if (bitmap ==
nullptr)
711 bitmap =
new Type[npixels];
713 if (bitmap ==
nullptr) {
718 memcpy(
static_cast<void *
>(bitmap),
static_cast<void *
>(array), (
size_t)(npixels *
sizeof(Type)));
726 row =
new Type *[height];
727 if (row ==
nullptr) {
731 for (
unsigned int i = 0; i < height; i++) {
732 row[i] = bitmap + i * width;
739 template <
class Type>
741 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
749 template <
class Type>
751 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
759 template <
class Type>
761 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
763 init(array, h, w, copyData);
769 template <
class Type>
770 vpImage<Type>::vpImage() : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
826 if (bitmap !=
nullptr) {
835 if (row !=
nullptr) {
854 template <
class Type>
856 : bitmap(nullptr), display(nullptr), npixels(0), width(0), height(0), row(nullptr), hasOwnership(true)
859 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.
bitmap), I.npixels *
sizeof(Type));
865 template <
class Type>
867 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row),
868 hasOwnership(I.hasOwnership)
876 I.hasOwnership =
false;
891 for (
unsigned int i = 0; i < npixels; i++) {
914 for (
unsigned int i = 0; i < npixels; i++) {
920 for (
unsigned int i = 0; i < npixels; i++) {
942 for (
unsigned int i = 0; i < npixels; i++) {
948 for (
unsigned int i = 0; i < npixels; i++) {
961 if ((height == 0) || (width == 0))
964 return getSum() / (height * width);
979 for (
unsigned int i = 0; i < npixels; i++) {
1001 if (onlyFiniteVal) {
1002 for (
unsigned int i = 0; i < npixels; i++)
1007 for (
unsigned int i = 0; i < npixels; i++)
1027 if (onlyFiniteVal) {
1028 for (
unsigned int i = 0; i < npixels; i++)
1033 for (
unsigned int i = 0; i < npixels; i++)
1055 min = max = bitmap[0];
1056 for (
unsigned int i = 0; i < npixels; i++) {
1057 if (bitmap[i] < min)
1059 if (bitmap[i] > max)
1062 (void)onlyFiniteVal;
1082 if (onlyFiniteVal) {
1083 for (
unsigned int i = 0; i < npixels; i++) {
1093 for (
unsigned int i = 0; i < npixels; i++) {
1119 if (onlyFiniteVal) {
1120 for (
unsigned int i = 0; i < npixels; i++) {
1130 for (
unsigned int i = 0; i < npixels; i++) {
1154 min = max = bitmap[0];
1155 if (onlyFiniteVal) {
1156 for (
unsigned int i = 0; i < npixels; i++) {
1158 if (bitmap[i].R < min.
R)
1159 min.
R = bitmap[i].R;
1160 if (bitmap[i].R > max.
R)
1161 max.
R = bitmap[i].R;
1164 if (bitmap[i].G < min.
G)
1165 min.
G = bitmap[i].G;
1166 if (bitmap[i].G > max.
G)
1167 max.
G = bitmap[i].G;
1170 if (bitmap[i].B < min.
B)
1171 min.
B = bitmap[i].B;
1172 if (bitmap[i].B > max.
B)
1173 max.
B = bitmap[i].B;
1178 for (
unsigned int i = 0; i < npixels; i++) {
1179 if (bitmap[i].R < min.
R)
1180 min.
R = bitmap[i].R;
1181 if (bitmap[i].R > max.
R)
1182 max.
R = bitmap[i].R;
1184 if (bitmap[i].G < min.
G)
1185 min.
G = bitmap[i].G;
1186 if (bitmap[i].G > max.
G)
1187 max.
G = bitmap[i].G;
1189 if (bitmap[i].B < min.
B)
1190 min.
B = bitmap[i].B;
1191 if (bitmap[i].B > max.
B)
1192 max.
B = bitmap[i].B;
1218 template <
class Type>
1223 "values of an empty image"));
1225 Type min = bitmap[0], max = bitmap[0];
1227 for (
unsigned int i = 0; i < height; i++) {
1228 for (
unsigned int j = 0; j < width; j++) {
1229 if (row[i][j] < min) {
1234 if (row[i][j] > max) {
1241 if (minLoc !=
nullptr)
1244 if (maxLoc !=
nullptr)
1247 if (minVal !=
nullptr)
1250 if (maxVal !=
nullptr)
1278 for (
unsigned int i = 0; i < npixels; i++)
1298 for (
unsigned int i = 0; i < npixels; i++) {
1299 if (bitmap[i] != I.
bitmap[i]) {
1359 int itl = (int)topLeft.
get_i();
1360 int jtl = (int)topLeft.
get_j();
1362 int dest_ibegin = 0;
1363 int dest_jbegin = 0;
1366 int dest_w = (int)this->getWidth();
1367 int dest_h = (int)this->getHeight();
1373 if (itl >= dest_h || jtl >= dest_w)
1386 if (src_w - src_jbegin > dest_w - dest_jbegin)
1387 wsize = dest_w - dest_jbegin;
1389 wsize = src_w - src_jbegin;
1391 if (src_h - src_ibegin > dest_h - dest_ibegin)
1392 hsize = dest_h - dest_ibegin;
1394 hsize = src_h - src_ibegin;
1396 for (
int i = 0; i < hsize; i++) {
1397 Type *srcBitmap = src.
bitmap + ((src_ibegin + i) * src_w + src_jbegin);
1398 Type *destBitmap = this->bitmap + ((dest_ibegin + i) * dest_w + dest_jbegin);
1400 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap), (
size_t)wsize *
sizeof(Type));
1436 unsigned int h = height / 2;
1437 unsigned int w = width / 2;
1439 for (
unsigned int i = 0; i < h; i++)
1440 for (
unsigned int j = 0; j < w; j++)
1441 res[i][j] = (*
this)[i << 1][j << 1];
1461 template <
class Type>
1464 if (v_scale == 1 && h_scale == 1) {
1468 unsigned int h = height / v_scale;
1469 unsigned int w = width / h_scale;
1471 for (
unsigned int i = 0; i < h; i++)
1472 for (
unsigned int j = 0; j < w; j++)
1473 sampled[i][j] = (*
this)[i * v_scale][j * h_scale];
1500 unsigned int h = height / 4;
1501 unsigned int w = width / 4;
1503 for (
unsigned int i = 0; i < h; i++)
1504 for (
unsigned int j = 0; j < w; j++)
1505 res[i][j] = (*
this)[i << 2][j << 2];
1547 for (
int i = 0; i < h; i++)
1548 for (
int j = 0; j < w; j++)
1549 res[i][j] = (*
this)[i >> 1][j >> 1];
1560 for (
int i = 0; i < h; i += 2)
1561 for (
int j = 1; j < w - 1; j += 2)
1562 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
1565 for (
int i = 1; i < h - 1; i += 2)
1566 for (
int j = 0; j < w; j += 2)
1567 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
1570 for (
int i = 1; i < h - 1; i += 2)
1571 for (
int j = 1; j < w - 1; j += 2)
1572 res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
1573 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
1590 if (i >= height || j >= width) {
1615 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1618 if (height * width == 0) {
1622 unsigned int iround =
static_cast<unsigned int>(floor(i));
1623 unsigned int jround =
static_cast<unsigned int>(floor(j));
1625 double rratio = i -
static_cast<double>(iround);
1626 double cratio = j -
static_cast<double>(jround);
1628 double rfrac = 1.0 - rratio;
1629 double cfrac = 1.0 - cratio;
1631 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1632 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1635 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1636 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1647 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1650 if (height * width == 0) {
1654 unsigned int iround =
static_cast<unsigned int>(floor(i));
1655 unsigned int jround =
static_cast<unsigned int>(floor(j));
1657 double rratio = i -
static_cast<double>(iround);
1658 double cratio = j -
static_cast<double>(jround);
1660 double rfrac = 1.0 - rratio;
1661 double cfrac = 1.0 - cratio;
1663 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1664 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1666 return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac +
1667 (row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio;
1675 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1678 if (height * width == 0) {
1683 #if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA))
1685 const int32_t precision = 1 << 16;
1686 int64_t y =
static_cast<int64_t
>(i * precision);
1687 int64_t x =
static_cast<int64_t
>(j * precision);
1689 int64_t iround = y & (~0xFFFF);
1690 int64_t jround = x & (~0xFFFF);
1692 int64_t rratio = y - iround;
1693 int64_t cratio = x - jround;
1695 int64_t rfrac = precision - rratio;
1696 int64_t cfrac = precision - cratio;
1698 int64_t x_ = x >> 16;
1699 int64_t y_ = y >> 16;
1701 if (y_ + 1 < height && x_ + 1 < width) {
1705 return static_cast<unsigned char>((((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cfrac +
1706 ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >>
1709 else if (y_ + 1 < height) {
1710 return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
1712 else if (x_ + 1 < width) {
1714 return static_cast<unsigned char>(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16);
1720 unsigned int iround =
static_cast<unsigned int>(floor(i));
1721 unsigned int jround =
static_cast<unsigned int>(floor(j));
1723 if (iround >= height || jround >= width) {
1728 double rratio = i -
static_cast<double>(iround);
1729 double cratio = j -
static_cast<double>(jround);
1731 double rfrac = 1.0 - rratio;
1732 double cfrac = 1.0 - cratio;
1734 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1735 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1738 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1739 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1750 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1753 if (height * width == 0) {
1757 unsigned int iround =
static_cast<unsigned int>(floor(i));
1758 unsigned int jround =
static_cast<unsigned int>(floor(j));
1760 double rratio = i -
static_cast<double>(iround);
1761 double cratio = j -
static_cast<double>(jround);
1763 double rfrac = 1.0 - rratio;
1764 double cfrac = 1.0 - cratio;
1766 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1767 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1770 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
1772 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
1775 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
1777 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
1780 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
1782 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
1794 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1797 if (height * width == 0) {
1801 unsigned int iround =
static_cast<unsigned int>(floor(i));
1802 unsigned int jround =
static_cast<unsigned int>(floor(j));
1804 double rratio = i -
static_cast<double>(iround);
1805 double cratio = j -
static_cast<double>(jround);
1807 double rfrac = 1.0 - rratio;
1808 double cfrac = 1.0 - cratio;
1810 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1811 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1814 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
1816 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
1819 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
1821 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
1824 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
1826 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
1829 return vpRGBf(
static_cast<float>(valueR),
static_cast<float>(valueG),
static_cast<float>(valueB));
1883 if ((height == 0) || (width == 0))
1887 for (
unsigned int i = 0; i < height * width; ++i) {
1888 res +=
static_cast<double>(bitmap[i]);
1898 if ((height == 0) || (width == 0))
1902 for (
unsigned int i = 0; i < height * width; ++i) {
1903 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1913 if ((height == 0) || (width == 0))
1917 for (
unsigned int i = 0; i < height * width; ++i) {
1918 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1957 C.
resize(this->getHeight(), this->getWidth());
1960 std::cout << me << std::endl;
1964 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
1968 for (
unsigned int i = 0; i < this->getWidth() * this->getHeight(); i++) {
1992 std::cout << me << std::endl;
2015 std::cerr <<
"Not implemented !" << std::endl;
2031 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2032 unsigned char *ptrEnd = ptrStart + size;
2033 unsigned char *ptrCurrent = ptrStart;
2035 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2036 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
2037 use_single_thread =
true;
2040 if (!use_single_thread &&
getSize() <= nbThreads) {
2041 use_single_thread =
true;
2044 if (use_single_thread) {
2047 while (ptrCurrent != ptrEnd) {
2048 *ptrCurrent = lut[*ptrCurrent];
2053 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
2056 std::vector<vpThread *> threadpool;
2057 std::vector<vpImageLut_Param_t *> imageLutParams;
2059 unsigned int image_size =
getSize();
2060 unsigned int step = image_size / nbThreads;
2061 unsigned int last_step = image_size - step * (nbThreads - 1);
2063 for (
unsigned int index = 0; index < nbThreads; index++) {
2064 unsigned int start_index = index * step;
2065 unsigned int end_index = (index + 1) * step;
2067 if (index == nbThreads - 1) {
2068 end_index = start_index + last_step;
2071 vpImageLut_Param_t *imageLut_param =
new vpImageLut_Param_t(start_index, end_index,
bitmap);
2072 memcpy(imageLut_param->m_lut, lut, 256 *
sizeof(
unsigned char));
2074 imageLutParams.push_back(imageLut_param);
2078 threadpool.push_back(imageLut_thread);
2081 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2083 threadpool[cpt]->join();
2087 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2088 delete threadpool[cpt];
2091 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2092 delete imageLutParams[cpt];
2111 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2112 unsigned char *ptrEnd = ptrStart + size * 4;
2113 unsigned char *ptrCurrent = ptrStart;
2115 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2116 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
2117 use_single_thread =
true;
2120 if (!use_single_thread &&
getSize() <= nbThreads) {
2121 use_single_thread =
true;
2124 if (use_single_thread) {
2126 while (ptrCurrent != ptrEnd) {
2127 *ptrCurrent = lut[*ptrCurrent].R;
2130 *ptrCurrent = lut[*ptrCurrent].G;
2133 *ptrCurrent = lut[*ptrCurrent].B;
2136 *ptrCurrent = lut[*ptrCurrent].A;
2141 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
2143 std::vector<vpThread *> threadpool;
2144 std::vector<vpImageLutRGBa_Param_t *> imageLutParams;
2146 unsigned int image_size =
getSize();
2147 unsigned int step = image_size / nbThreads;
2148 unsigned int last_step = image_size - step * (nbThreads - 1);
2150 for (
unsigned int index = 0; index < nbThreads; index++) {
2151 unsigned int start_index = index * step;
2152 unsigned int end_index = (index + 1) * step;
2154 if (index == nbThreads - 1) {
2155 end_index = start_index + last_step;
2158 vpImageLutRGBa_Param_t *imageLut_param =
new vpImageLutRGBa_Param_t(start_index, end_index, (
unsigned char *)
bitmap);
2159 memcpy(
static_cast<void *
>(imageLut_param->m_lut), lut, 256 *
sizeof(
vpRGBa));
2161 imageLutParams.push_back(imageLut_param);
2165 threadpool.push_back(imageLut_thread);
2168 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2170 threadpool[cpt]->join();
2174 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2175 delete threadpool[cpt];
2178 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2179 delete imageLutParams[cpt];
2190 swap(first.npixels, second.npixels);
2191 swap(first.width, second.width);
2192 swap(first.height, second.height);
2193 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 getMeanValue() const
Return the mean value of the bitmap.
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
unsigned int getNumberOfPixel() const
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
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
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]
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
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
vpImage(vpImage< Type > &&)
move constructor
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
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)