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
146 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
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; }
214 inline unsigned int getRows()
const {
return height; }
223 inline unsigned int getSize()
const {
return width * height; }
226 Type
getValue(
unsigned int i,
unsigned int j)
const;
242 inline unsigned int getWidth()
const {
return width; }
248 void init(
unsigned int height,
unsigned int width);
250 void init(
unsigned int height,
unsigned int width, Type value);
252 void init(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
263 inline const Type *
operator[](
unsigned int i)
const {
return row[i]; }
264 inline const Type *
operator[](
int i)
const {
return row[i]; }
272 inline Type
operator()(
unsigned int i,
unsigned int j)
const {
return bitmap[i * width + j]; }
278 inline void operator()(
unsigned int i,
unsigned int j,
const Type &v) {
bitmap[i * width + j] = v; }
292 unsigned int i = (
unsigned int)ip.
get_i();
293 unsigned int j = (
unsigned int)ip.
get_j();
295 return bitmap[i * width + j];
308 unsigned int i = (
unsigned int)ip.
get_i();
309 unsigned int j = (
unsigned int)ip.
get_j();
311 bitmap[i * width + j] = v;
322 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
329 void performLut(
const Type(&lut)[256],
unsigned int nbThreads = 1);
335 void resize(
unsigned int h,
unsigned int w);
337 void resize(
unsigned int h,
unsigned int w,
const Type &val);
348 unsigned int npixels;
361 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
362 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
384 std::ios_base::fmtflags original_flags = s.flags();
386 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
387 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
388 s << std::setw(3) << static_cast<unsigned>(I[i][j]) <<
" ";
392 s << std::setw(3) << static_cast<unsigned>(I[i][I.
getWidth() - 1]);
400 s.flags(original_flags);
410 std::ios_base::fmtflags original_flags = s.flags();
412 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
413 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
414 s << std::setw(4) << static_cast<int>(I[i][j]) <<
" ";
418 s << std::setw(4) << static_cast<int>(I[i][I.
getWidth() - 1]);
426 s.flags(original_flags);
436 std::ios_base::fmtflags original_flags = s.flags();
439 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
440 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
453 s.flags(original_flags);
463 std::ios_base::fmtflags original_flags = s.flags();
466 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
467 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
480 s.flags(original_flags);
484 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
487 struct vpImageLut_Param_t
489 unsigned int m_start_index;
490 unsigned int m_end_index;
492 unsigned char m_lut[256];
493 unsigned char *m_bitmap;
495 vpImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) { }
497 vpImageLut_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
498 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
504 vpImageLut_Param_t *imageLut_param =
static_cast<vpImageLut_Param_t *
>(args);
505 unsigned int start_index = imageLut_param->m_start_index;
506 unsigned int end_index = imageLut_param->m_end_index;
508 unsigned char *bitmap = imageLut_param->m_bitmap;
510 unsigned char *ptrStart = bitmap + start_index;
511 unsigned char *ptrEnd = bitmap + end_index;
512 unsigned char *ptrCurrent = ptrStart;
519 if (end_index - start_index >= 8) {
521 for (; ptrCurrent <= ptrEnd - 8;) {
522 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
525 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
528 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
531 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
534 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
537 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
540 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
543 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
548 for (; ptrCurrent != ptrEnd; ++ptrCurrent) {
549 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
555 struct vpImageLutRGBa_Param_t
557 unsigned int m_start_index;
558 unsigned int m_end_index;
561 unsigned char *m_bitmap;
563 vpImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) { }
565 vpImageLutRGBa_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
566 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
572 vpImageLutRGBa_Param_t *imageLut_param =
static_cast<vpImageLutRGBa_Param_t *
>(args);
573 unsigned int start_index = imageLut_param->m_start_index;
574 unsigned int end_index = imageLut_param->m_end_index;
576 unsigned char *bitmap = imageLut_param->m_bitmap;
578 unsigned char *ptrStart = bitmap + start_index * 4;
579 unsigned char *ptrEnd = bitmap + end_index * 4;
580 unsigned char *ptrCurrent = ptrStart;
582 if (end_index - start_index >= 4 * 2) {
584 for (; ptrCurrent <= ptrEnd - 4 * 2;) {
585 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
587 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
589 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
591 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
594 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
596 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
598 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
600 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
605 while (ptrCurrent != ptrEnd) {
606 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
609 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
612 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
615 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
633 std::fill(bitmap, bitmap + npixels, value);
641 if (h != this->height) {
649 if ((h != this->height) || (w != this->width)) {
650 if (bitmap != NULL) {
662 npixels = width * height;
664 if (bitmap == NULL) {
665 bitmap =
new Type[npixels];
669 if (bitmap == NULL) {
674 row =
new Type *[height];
679 for (
unsigned int i = 0; i < height; i++)
680 row[i] = bitmap + i * width;
686 template <
class Type>
void vpImage<Type>::init(Type *
const array,
unsigned int h,
unsigned int w,
bool copyData)
688 if (h != this->height) {
696 if ((copyData && ((h != this->height) || (w != this->width))) || !copyData) {
697 if (bitmap != NULL) {
705 hasOwnership = copyData;
709 npixels = width * height;
713 bitmap =
new Type[npixels];
715 if (bitmap == NULL) {
720 memcpy(
static_cast<void *
>(bitmap),
static_cast<void *
>(array), (
size_t)(npixels *
sizeof(Type)));
728 row =
new Type *[height];
733 for (
unsigned int i = 0; i < height; i++) {
734 row[i] = bitmap + i * width;
741 template <
class Type>
743 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
751 template <
class Type>
753 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
761 template <
class Type>
763 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
765 init(array, h, w, copyData);
771 template <
class Type>
828 if (bitmap != NULL) {
856 template <
class Type>
858 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
861 memcpy(
static_cast<void *
>(
bitmap),
static_cast<void *
>(I.
bitmap), I.npixels *
sizeof(Type));
864 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
868 template <
class Type>
870 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row),
871 hasOwnership(I.hasOwnership)
879 I.hasOwnership =
false;
895 for (
unsigned int i = 0; i < npixels; i++) {
918 for (
unsigned int i = 0; i < npixels; i++) {
924 for (
unsigned int i = 0; i < npixels; i++) {
946 for (
unsigned int i = 0; i < npixels; i++) {
952 for (
unsigned int i = 0; i < npixels; i++) {
965 if ((height == 0) || (width == 0))
968 return getSum() / (height * width);
983 for (
unsigned int i = 0; i < npixels; i++) {
1005 if (onlyFiniteVal) {
1006 for (
unsigned int i = 0; i < npixels; i++)
1011 for (
unsigned int i = 0; i < npixels; i++)
1031 if (onlyFiniteVal) {
1032 for (
unsigned int i = 0; i < npixels; i++)
1037 for (
unsigned int i = 0; i < npixels; i++)
1059 min = max = bitmap[0];
1060 for (
unsigned int i = 0; i < npixels; i++) {
1061 if (bitmap[i] < min)
1063 if (bitmap[i] > max)
1066 (void)onlyFiniteVal;
1086 if (onlyFiniteVal) {
1087 for (
unsigned int i = 0; i < npixels; i++) {
1097 for (
unsigned int i = 0; i < npixels; i++) {
1123 if (onlyFiniteVal) {
1124 for (
unsigned int i = 0; i < npixels; i++) {
1134 for (
unsigned int i = 0; i < npixels; i++) {
1158 min = max = bitmap[0];
1159 if (onlyFiniteVal) {
1160 for (
unsigned int i = 0; i < npixels; i++) {
1162 if (bitmap[i].R < min.
R)
1163 min.
R = bitmap[i].R;
1164 if (bitmap[i].R > max.
R)
1165 max.
R = bitmap[i].R;
1168 if (bitmap[i].G < min.
G)
1169 min.
G = bitmap[i].G;
1170 if (bitmap[i].G > max.
G)
1171 max.
G = bitmap[i].G;
1174 if (bitmap[i].B < min.
B)
1175 min.
B = bitmap[i].B;
1176 if (bitmap[i].B > max.
B)
1177 max.
B = bitmap[i].B;
1182 for (
unsigned int i = 0; i < npixels; i++) {
1183 if (bitmap[i].R < min.
R)
1184 min.
R = bitmap[i].R;
1185 if (bitmap[i].R > max.
R)
1186 max.
R = bitmap[i].R;
1188 if (bitmap[i].G < min.
G)
1189 min.
G = bitmap[i].G;
1190 if (bitmap[i].G > max.
G)
1191 max.
G = bitmap[i].G;
1193 if (bitmap[i].B < min.
B)
1194 min.
B = bitmap[i].B;
1195 if (bitmap[i].B > max.
B)
1196 max.
B = bitmap[i].B;
1222 template <
class Type>
1227 "values of an empty image"));
1229 Type min = bitmap[0], max = bitmap[0];
1231 for (
unsigned int i = 0; i < height; i++) {
1232 for (
unsigned int j = 0; j < width; j++) {
1233 if (row[i][j] < min) {
1238 if (row[i][j] > max) {
1282 for (
unsigned int i = 0; i < npixels; i++)
1302 for (
unsigned int i = 0; i < npixels; i++) {
1303 if (bitmap[i] != I.
bitmap[i]) {
1363 int itl = (int)topLeft.
get_i();
1364 int jtl = (int)topLeft.
get_j();
1366 int dest_ibegin = 0;
1367 int dest_jbegin = 0;
1370 int dest_w = (int)this->getWidth();
1371 int dest_h = (int)this->getHeight();
1377 if (itl >= dest_h || jtl >= dest_w)
1390 if (src_w - src_jbegin > dest_w - dest_jbegin)
1391 wsize = dest_w - dest_jbegin;
1393 wsize = src_w - src_jbegin;
1395 if (src_h - src_ibegin > dest_h - dest_ibegin)
1396 hsize = dest_h - dest_ibegin;
1398 hsize = src_h - src_ibegin;
1400 for (
int i = 0; i < hsize; i++) {
1401 Type *srcBitmap = src.
bitmap + ((src_ibegin + i) * src_w + src_jbegin);
1402 Type *destBitmap = this->bitmap + ((dest_ibegin + i) * dest_w + dest_jbegin);
1404 memcpy(
static_cast<void *
>(destBitmap),
static_cast<void *
>(srcBitmap), (
size_t)wsize *
sizeof(Type));
1440 unsigned int h = height / 2;
1441 unsigned int w = width / 2;
1443 for (
unsigned int i = 0; i < h; i++)
1444 for (
unsigned int j = 0; j < w; j++)
1445 res[i][j] = (*
this)[i << 1][j << 1];
1465 template <
class Type>
1468 if (v_scale == 1 && h_scale == 1) {
1472 unsigned int h = height / v_scale;
1473 unsigned int w = width / h_scale;
1475 for (
unsigned int i = 0; i < h; i++)
1476 for (
unsigned int j = 0; j < w; j++)
1477 sampled[i][j] = (*
this)[i * v_scale][j * h_scale];
1504 unsigned int h = height / 4;
1505 unsigned int w = width / 4;
1507 for (
unsigned int i = 0; i < h; i++)
1508 for (
unsigned int j = 0; j < w; j++)
1509 res[i][j] = (*
this)[i << 2][j << 2];
1551 for (
int i = 0; i < h; i++)
1552 for (
int j = 0; j < w; j++)
1553 res[i][j] = (*
this)[i >> 1][j >> 1];
1564 for (
int i = 0; i < h; i += 2)
1565 for (
int j = 1; j < w - 1; j += 2)
1566 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
1569 for (
int i = 1; i < h - 1; i += 2)
1570 for (
int j = 0; j < w; j += 2)
1571 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
1574 for (
int i = 1; i < h - 1; i += 2)
1575 for (
int j = 1; j < w - 1; j += 2)
1576 res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
1577 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
1594 if (i >= height || j >= width) {
1619 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1622 if (height * width == 0) {
1626 unsigned int iround =
static_cast<unsigned int>(floor(i));
1627 unsigned int jround =
static_cast<unsigned int>(floor(j));
1629 double rratio = i -
static_cast<double>(iround);
1630 double cratio = j -
static_cast<double>(jround);
1632 double rfrac = 1.0 - rratio;
1633 double cfrac = 1.0 - cratio;
1635 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1636 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1639 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1640 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1651 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1654 if (height * width == 0) {
1658 unsigned int iround =
static_cast<unsigned int>(floor(i));
1659 unsigned int jround =
static_cast<unsigned int>(floor(j));
1661 double rratio = i -
static_cast<double>(iround);
1662 double cratio = j -
static_cast<double>(jround);
1664 double rfrac = 1.0 - rratio;
1665 double cfrac = 1.0 - cratio;
1667 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1668 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1670 return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac +
1671 (row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio;
1679 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1682 if (height * width == 0) {
1687 #if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA))
1689 const int32_t precision = 1 << 16;
1690 int64_t y =
static_cast<int64_t
>(i * precision);
1691 int64_t x =
static_cast<int64_t
>(j * precision);
1693 int64_t iround = y & (~0xFFFF);
1694 int64_t jround = x & (~0xFFFF);
1696 int64_t rratio = y - iround;
1697 int64_t cratio = x - jround;
1699 int64_t rfrac = precision - rratio;
1700 int64_t cfrac = precision - cratio;
1702 int64_t x_ = x >> 16;
1703 int64_t y_ = y >> 16;
1705 if (y_ + 1 < height && x_ + 1 < width) {
1709 return static_cast<unsigned char>((((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cfrac +
1710 ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >>
1713 else if (y_ + 1 < height) {
1714 return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
1716 else if (x_ + 1 < width) {
1718 return static_cast<unsigned char>(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16);
1724 unsigned int iround =
static_cast<unsigned int>(floor(i));
1725 unsigned int jround =
static_cast<unsigned int>(floor(j));
1727 if (iround >= height || jround >= width) {
1732 double rratio = i -
static_cast<double>(iround);
1733 double cratio = j -
static_cast<double>(jround);
1735 double rfrac = 1.0 - rratio;
1736 double cfrac = 1.0 - cratio;
1738 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1739 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1742 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1743 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
1754 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1757 if (height * width == 0) {
1761 unsigned int iround =
static_cast<unsigned int>(floor(i));
1762 unsigned int jround =
static_cast<unsigned int>(floor(j));
1764 double rratio = i -
static_cast<double>(iround);
1765 double cratio = j -
static_cast<double>(jround);
1767 double rfrac = 1.0 - rratio;
1768 double cfrac = 1.0 - cratio;
1770 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1771 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1774 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
1776 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
1779 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
1781 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
1784 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
1786 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
1798 if (i < 0 || j < 0 || i + 1 > height || j + 1 > width) {
1801 if (height * width == 0) {
1805 unsigned int iround =
static_cast<unsigned int>(floor(i));
1806 unsigned int jround =
static_cast<unsigned int>(floor(j));
1808 double rratio = i -
static_cast<double>(iround);
1809 double cratio = j -
static_cast<double>(jround);
1811 double rfrac = 1.0 - rratio;
1812 double cfrac = 1.0 - cratio;
1814 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1815 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1818 (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) *
1820 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) *
1823 (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) *
1825 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) *
1828 (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) *
1830 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) *
1833 return vpRGBf(
static_cast<float>(valueR),
static_cast<float>(valueG),
static_cast<float>(valueB));
1887 if ((height == 0) || (width == 0))
1891 for (
unsigned int i = 0; i < height * width; ++i) {
1892 res +=
static_cast<double>(bitmap[i]);
1902 if ((height == 0) || (width == 0))
1906 for (
unsigned int i = 0; i < height * width; ++i) {
1907 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1917 if ((height == 0) || (width == 0))
1921 for (
unsigned int i = 0; i < height * width; ++i) {
1922 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1961 C.
resize(this->getHeight(), this->getWidth());
1964 std::cout << me << std::endl;
1968 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
1972 for (
unsigned int i = 0; i < this->getWidth() * this->getHeight(); i++) {
1996 std::cout << me << std::endl;
2019 std::cerr <<
"Not implemented !" << std::endl;
2035 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2036 unsigned char *ptrEnd = ptrStart + size;
2037 unsigned char *ptrCurrent = ptrStart;
2039 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2040 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
2041 use_single_thread =
true;
2044 if (!use_single_thread &&
getSize() <= nbThreads) {
2045 use_single_thread =
true;
2048 if (use_single_thread) {
2051 while (ptrCurrent != ptrEnd) {
2052 *ptrCurrent = lut[*ptrCurrent];
2057 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
2060 std::vector<vpThread *> threadpool;
2061 std::vector<vpImageLut_Param_t *> imageLutParams;
2063 unsigned int image_size =
getSize();
2064 unsigned int step = image_size / nbThreads;
2065 unsigned int last_step = image_size - step * (nbThreads - 1);
2067 for (
unsigned int index = 0; index < nbThreads; index++) {
2068 unsigned int start_index = index * step;
2069 unsigned int end_index = (index + 1) * step;
2071 if (index == nbThreads - 1) {
2072 end_index = start_index + last_step;
2075 vpImageLut_Param_t *imageLut_param =
new vpImageLut_Param_t(start_index, end_index,
bitmap);
2076 memcpy(imageLut_param->m_lut, lut, 256 *
sizeof(
unsigned char));
2078 imageLutParams.push_back(imageLut_param);
2082 threadpool.push_back(imageLut_thread);
2085 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2087 threadpool[cpt]->join();
2091 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2092 delete threadpool[cpt];
2095 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2096 delete imageLutParams[cpt];
2115 unsigned char *ptrStart = (
unsigned char *)
bitmap;
2116 unsigned char *ptrEnd = ptrStart + size * 4;
2117 unsigned char *ptrCurrent = ptrStart;
2119 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
2120 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
2121 use_single_thread =
true;
2124 if (!use_single_thread &&
getSize() <= nbThreads) {
2125 use_single_thread =
true;
2128 if (use_single_thread) {
2130 while (ptrCurrent != ptrEnd) {
2131 *ptrCurrent = lut[*ptrCurrent].R;
2134 *ptrCurrent = lut[*ptrCurrent].G;
2137 *ptrCurrent = lut[*ptrCurrent].B;
2140 *ptrCurrent = lut[*ptrCurrent].A;
2145 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
2147 std::vector<vpThread *> threadpool;
2148 std::vector<vpImageLutRGBa_Param_t *> imageLutParams;
2150 unsigned int image_size =
getSize();
2151 unsigned int step = image_size / nbThreads;
2152 unsigned int last_step = image_size - step * (nbThreads - 1);
2154 for (
unsigned int index = 0; index < nbThreads; index++) {
2155 unsigned int start_index = index * step;
2156 unsigned int end_index = (index + 1) * step;
2158 if (index == nbThreads - 1) {
2159 end_index = start_index + last_step;
2162 vpImageLutRGBa_Param_t *imageLut_param =
new vpImageLutRGBa_Param_t(start_index, end_index, (
unsigned char *)
bitmap);
2163 memcpy(
static_cast<void *
>(imageLut_param->m_lut), lut, 256 *
sizeof(
vpRGBa));
2165 imageLutParams.push_back(imageLut_param);
2169 threadpool.push_back(imageLut_thread);
2172 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2174 threadpool[cpt]->join();
2178 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2179 delete threadpool[cpt];
2182 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2183 delete imageLutParams[cpt];
2194 swap(first.npixels, second.npixels);
2195 swap(first.width, second.width);
2196 swap(first.height, second.height);
2197 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 getMinMaxLoc(vpImagePoint *minLoc, vpImagePoint *maxLoc, Type *minVal=NULL, Type *maxVal=NULL) const
Get the position of the minimum and/or the maximum pixel value within the bitmap and the correspondin...
void quarterSizeImage(vpImage< Type > &res) const
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)