34 #ifndef VP_IMAGE_GETTERS_H
35 #define VP_IMAGE_GETTERS_H
53 if ((i >= height) || (j >= width)) {
78 if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) {
81 if ((height * width) == 0) {
85 unsigned int iround =
static_cast<unsigned int>(floor(i));
86 unsigned int jround =
static_cast<unsigned int>(floor(j));
88 double rratio = i -
static_cast<double>(iround);
89 double cratio = j -
static_cast<double>(jround);
91 double rfrac = 1.0 - rratio;
92 double cfrac = 1.0 - cratio;
94 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
95 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
98 (((
static_cast<double>(row[iround][jround]) * rfrac) + (
static_cast<double>(row[iround_1][jround]) * rratio)) * cfrac) +
99 (((
static_cast<double>(row[iround][jround_1]) * rfrac) + (
static_cast<double>(row[iround_1][jround_1]) * rratio)) *
110 if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) {
113 if ((height * width) == 0) {
117 unsigned int iround =
static_cast<unsigned int>(floor(i));
118 unsigned int jround =
static_cast<unsigned int>(floor(j));
120 double rratio = i -
static_cast<double>(iround);
121 double cratio = j -
static_cast<double>(jround);
123 double rfrac = 1.0 - rratio;
124 double cfrac = 1.0 - cratio;
126 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
127 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
129 return (((row[iround][jround] * rfrac) + (row[iround_1][jround] * rratio)) * cfrac) +
130 (((row[iround][jround_1] * rfrac) + (row[iround_1][jround_1] * rratio)) * cratio);
138 if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) {
141 if ((height * width) == 0) {
146 #if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA))
148 const uint32_t magic_8 = 8;
149 const uint32_t magic_16 = 16;
150 const uint32_t magic_32 = 32;
151 const uint32_t magic_0x00FF = 0x00FF;
152 const uint32_t precision = 1U << magic_16;
153 uint64_t y =
static_cast<uint64_t
>(i * precision);
154 uint64_t x =
static_cast<uint64_t
>(j * precision);
156 uint64_t iround = y & (~0xFFFFU);
157 uint64_t jround = x & (~0xFFFFU);
159 uint64_t rratio = y - iround;
160 uint64_t cratio = x - jround;
162 uint64_t rfrac = precision - rratio;
163 uint64_t cfrac = precision - cratio;
165 uint64_t x_ = x >> magic_16;
166 uint64_t y_ = y >> magic_16;
168 if (((y_ + 1) < height) && ((x_ + 1) < width)) {
172 return static_cast<unsigned char>((((((up & magic_0x00FF) * rfrac) + ((down & magic_0x00FF) * rratio)) * cfrac)
173 + (((up >> magic_8) * rfrac) + ((down >> magic_8) * rratio)) * cratio) >> magic_32);
175 else if ((y_ + 1) < height) {
176 return static_cast<unsigned char>(((row[y_][x_] * rfrac) + (row[y_ + 1][x_] * rratio)) >> magic_16);
178 else if ((x_ + 1) < width) {
180 return static_cast<unsigned char>((((up & magic_0x00FF) * cfrac) + ((up >> magic_8) * cratio)) >> magic_16);
186 unsigned int iround =
static_cast<unsigned int>(floor(i));
187 unsigned int jround =
static_cast<unsigned int>(floor(j));
189 if (iround >= height || jround >= width) {
193 double rratio = i -
static_cast<double>(iround);
194 double cratio = j -
static_cast<double>(jround);
196 double rfrac = 1.0 - rratio;
197 double cfrac = 1.0 - cratio;
199 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
200 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
203 (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
204 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) *
215 if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) {
218 if ((height * width) == 0) {
222 unsigned int iround =
static_cast<unsigned int>(floor(i));
223 unsigned int jround =
static_cast<unsigned int>(floor(j));
225 double rratio = i -
static_cast<double>(iround);
226 double cratio = j -
static_cast<double>(jround);
228 double rfrac = 1.0 - rratio;
229 double cfrac = 1.0 - cratio;
231 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
232 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
235 (((
static_cast<double>(row[iround][jround].R) * rfrac) + (
static_cast<double>(row[iround_1][jround].R) * rratio)) *
237 (((
static_cast<double>(row[iround][jround_1].R) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].R) * rratio)) *
240 (((
static_cast<double>(row[iround][jround].G) * rfrac) + (
static_cast<double>(row[iround_1][jround].G) * rratio)) *
242 (((
static_cast<double>(row[iround][jround_1].G) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].G) * rratio)) *
245 (((
static_cast<double>(row[iround][jround].B) * rfrac) + (
static_cast<double>(row[iround_1][jround].B) * rratio)) *
247 (((
static_cast<double>(row[iround][jround_1].B) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].B) * rratio)) *
259 if ((i < 0) || (j < 0) || ((i + 1) > height) || ((j + 1) > width)) {
262 if ((height * width) == 0) {
266 unsigned int iround =
static_cast<unsigned int>(floor(i));
267 unsigned int jround =
static_cast<unsigned int>(floor(j));
269 double rratio = i -
static_cast<double>(iround);
270 double cratio = j -
static_cast<double>(jround);
272 double rfrac = 1.0 - rratio;
273 double cfrac = 1.0 - cratio;
275 unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
276 unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);
279 (((
static_cast<double>(row[iround][jround].R) * rfrac) + (
static_cast<double>(row[iround_1][jround].R) * rratio)) *
281 (((
static_cast<double>(row[iround][jround_1].R) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].R) * rratio)) *
284 (((
static_cast<double>(row[iround][jround].G) * rfrac) + (
static_cast<double>(row[iround_1][jround].G) * rratio)) *
286 (((
static_cast<double>(row[iround][jround_1].G) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].G) * rratio)) *
289 (((
static_cast<double>(row[iround][jround].B) * rfrac) + (
static_cast<double>(row[iround_1][jround].B) * rratio)) *
291 (((
static_cast<double>(row[iround][jround_1].B) * rfrac) + (
static_cast<double>(row[iround_1][jround_1].B) * rratio)) *
294 return vpRGBf(
static_cast<float>(valueR),
static_cast<float>(valueG),
static_cast<float>(valueB));
355 for (
unsigned int i = 0; i < npixels; ++i) {
379 for (
unsigned int i = 0; i < npixels; ++i) {
386 for (
unsigned int i = 0; i < npixels; ++i) {
410 for (
unsigned int i = 0; i < npixels; ++i) {
417 for (
unsigned int i = 0; i < npixels; ++i) {
439 for (
unsigned int i = 0; i < npixels; ++i) {
463 for (
unsigned int i = 0; i < npixels; ++i) {
470 for (
unsigned int i = 0; i < npixels; ++i) {
494 for (
unsigned int i = 0; i < npixels; ++i) {
501 for (
unsigned int i = 0; i < npixels; ++i) {
528 for (
unsigned int i = 0; i < npixels; ++i) {
529 if (bitmap[i] < min) {
532 if (bitmap[i] > max) {
559 for (
unsigned int i = 0; i < npixels; ++i) {
571 for (
unsigned int i = 0; i < npixels; ++i) {
602 for (
unsigned int i = 0; i < npixels; ++i) {
614 for (
unsigned int i = 0; i < npixels; ++i) {
644 for (
unsigned int i = 0; i < npixels; ++i) {
646 if (bitmap[i].R < min.
R) {
649 if (bitmap[i].R > max.
R) {
654 if (bitmap[i].G < min.
G) {
657 if (bitmap[i].G > max.
G) {
662 if (bitmap[i].B < min.
B) {
665 if (bitmap[i].B > max.
B) {
672 for (
unsigned int i = 0; i < npixels; ++i) {
673 if (bitmap[i].R < min.
R) {
676 if (bitmap[i].R > max.
R) {
680 if (bitmap[i].G < min.
G) {
683 if (bitmap[i].G > max.
G) {
687 if (bitmap[i].B < min.
B) {
690 if (bitmap[i].B > max.
B) {
718 template <
class Type>
723 "values of an empty image"));
726 Type min = bitmap[0], max = bitmap[0];
728 for (
unsigned int i = 0; i < height; ++i) {
729 for (
unsigned int j = 0; j < width; ++j) {
730 if (row[i][j] < min) {
735 if (row[i][j] > max) {
742 if (minLoc !=
nullptr) {
746 if (maxLoc !=
nullptr) {
750 if (minVal !=
nullptr) {
754 if (maxVal !=
nullptr) {
771 if ((height == 0) || (width == 0)) {
774 unsigned int nbPointsInMask = 0;
775 double sum = getSum(p_mask, &nbPointsInMask);
776 if (nbPointsInMask == 0) {
780 *nbValidPoints = nbPointsInMask;
782 return sum / nbPointsInMask;
802 double mean = getMeanValue(p_mask, nbValidPoints);
803 return getStdev(mean, p_mask);
826 if ((height == 0) || (width == 0)) {
829 const unsigned int size = width * height;
831 unsigned int nbPointsInMask = 0;
836 for (
unsigned int i = 0; i < size; ++i) {
838 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
844 for (
unsigned int i = 0; i < size; ++i) {
845 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
847 nbPointsInMask = size;
849 sum /=
static_cast<double>(nbPointsInMask);
851 *nbValidPoints = nbPointsInMask;
853 return std::sqrt(sum);
856 #ifndef DOXYGEN_SHOULD_SKIP_THIS
877 if ((height == 0) || (width == 0)) {
880 const unsigned int size = width * height;
882 unsigned int nbPointsInMask = 0;
887 for (
unsigned int i = 0; i < size; ++i) {
889 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
890 sum += (val - mean) * (val - mean);
896 for (
unsigned int i = 0; i < size; ++i) {
897 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
898 sum += (val - mean) * (val - mean);
900 nbPointsInMask = size;
902 sum /=
static_cast<double>(nbPointsInMask);
904 *nbValidPoints = nbPointsInMask;
906 return std::sqrt(sum);
929 if ((height == 0) || (width == 0)) {
932 const unsigned int size = width * height;
934 unsigned int nbPointsInMask = 0;
939 for (
unsigned int i = 0; i < size; ++i) {
941 double val =
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
942 sum += (val - mean) * (val - mean);
948 for (
unsigned int i = 0; i < size; ++i) {
949 double val =
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
950 sum += (val - mean) * (val - mean);
952 nbPointsInMask = size;
954 sum /=
static_cast<double>(nbPointsInMask);
956 *nbValidPoints = nbPointsInMask;
958 return std::sqrt(sum);
975 if ((height == 0) || (width == 0)) {
987 unsigned int nbPointsInMask = 0;
988 unsigned int size = height * width;
990 for (
unsigned int i = 0; i < size; ++i) {
992 res +=
static_cast<double>(bitmap[i]);
998 for (
unsigned int i = 0; i < size; ++i) {
999 res +=
static_cast<double>(bitmap[i]);
1001 nbPointsInMask = size;
1003 if (nbValidPoints) {
1004 *nbValidPoints = nbPointsInMask;
1010 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1024 if ((height == 0) || (width == 0)) {
1028 unsigned int nbPointsInMask = 0;
1029 unsigned int size = height * width;
1034 for (
unsigned int i = 0; i < size; ++i) {
1036 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1042 for (
unsigned int i = 0; i < (height * width); ++i) {
1043 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1045 nbPointsInMask = size;
1047 if (nbValidPoints) {
1048 *nbValidPoints = nbPointsInMask;
1066 if ((height == 0) || (width == 0)) {
1070 unsigned int nbPointsInMask = 0;
1071 unsigned int size = height * width;
1076 for (
unsigned int i = 0; i < size; ++i) {
1078 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1084 for (
unsigned int i = 0; i < (height * width); ++i) {
1085 res +=
static_cast<double>(bitmap[i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[i].B);
1087 nbPointsInMask = size;
1089 if (nbValidPoints) {
1090 *nbValidPoints = nbPointsInMask;
error that can be emitted by ViSP classes.
@ divideByZeroError
Division by zero.
@ 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)
double getSum(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Compute the sum of image intensities.
Type getMinValue(bool onlyFiniteVal=true) const
Return the minimum value within the bitmap.
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...
unsigned int getWidth() const
Type getValue(unsigned int i, unsigned int j) const
double getValue(double i, double j) const
Type * bitmap
points toward the bitmap
double getStdev(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Return the standard deviation of the bitmap.
Type getMaxValue(bool onlyFiniteVal=true) const
Return the maximum value within the bitmap.
unsigned int getHeight() const
void getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal=true) const
Look for the minimum and the maximum value within the bitmap.
double getMeanValue(const vpImage< bool > *p_mask=nullptr, unsigned int *nbValidPoints=nullptr) const
Return the mean value of the bitmap.
static int round(double x)
static bool isFinite(double value)
VISP_EXPORT uint16_t reinterpret_cast_uchar_to_uint16_LE(unsigned char *const ptr)