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) {
645 for (
unsigned int i = 0; i < npixels; ++i) {
673 for (
unsigned int i = 0; i < npixels; ++i) {
719 template <
class Type>
724 "values of an empty image"));
727 Type min = bitmap[0], max = bitmap[0];
729 for (
unsigned int i = 0; i < height; ++i) {
730 for (
unsigned int j = 0; j < width; ++j) {
731 if (row[i][j] < min) {
736 if (row[i][j] > max) {
743 if (minLoc !=
nullptr) {
747 if (maxLoc !=
nullptr) {
751 if (minVal !=
nullptr) {
755 if (maxVal !=
nullptr) {
772 if ((height == 0) || (width == 0)) {
775 unsigned int nbPointsInMask = 0;
776 double sum = getSum(p_mask, &nbPointsInMask);
777 if (nbPointsInMask == 0) {
781 *nbValidPoints = nbPointsInMask;
783 return sum / nbPointsInMask;
803 double mean = getMeanValue(p_mask, nbValidPoints);
804 return getStdev(mean, p_mask);
827 if ((height == 0) || (width == 0)) {
830 const unsigned int size = width * height;
832 unsigned int nbPointsInMask = 0;
837 for (
unsigned int i = 0; i < size; ++i) {
839 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
845 for (
unsigned int i = 0; i < size; ++i) {
846 sum += (bitmap[i] - mean) * (bitmap[i] - mean);
848 nbPointsInMask = size;
850 sum /=
static_cast<double>(nbPointsInMask);
852 *nbValidPoints = nbPointsInMask;
854 return std::sqrt(sum);
857 #ifndef DOXYGEN_SHOULD_SKIP_THIS
878 if ((height == 0) || (width == 0)) {
881 const unsigned int size = width * height;
883 unsigned int nbPointsInMask = 0;
888 for (
unsigned int i = 0; i < size; ++i) {
890 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
891 sum += (val - mean) * (val - mean);
897 for (
unsigned int i = 0; i < size; ++i) {
898 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
899 sum += (val - mean) * (val - mean);
901 nbPointsInMask = size;
903 sum /=
static_cast<double>(nbPointsInMask);
905 *nbValidPoints = nbPointsInMask;
907 return std::sqrt(sum);
930 if ((height == 0) || (width == 0)) {
933 const unsigned int size = width * height;
935 unsigned int nbPointsInMask = 0;
940 for (
unsigned int i = 0; i < size; ++i) {
942 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
943 sum += (val - mean) * (val - mean);
949 for (
unsigned int i = 0; i < size; ++i) {
950 double val =
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
951 sum += (val - mean) * (val - mean);
953 nbPointsInMask = size;
955 sum /=
static_cast<double>(nbPointsInMask);
957 *nbValidPoints = nbPointsInMask;
959 return std::sqrt(sum);
976 if ((height == 0) || (width == 0)) {
988 unsigned int nbPointsInMask = 0;
989 unsigned int size = height * width;
991 for (
unsigned int i = 0; i < size; ++i) {
993 res +=
static_cast<double>(bitmap[i]);
999 for (
unsigned int i = 0; i < size; ++i) {
1000 res +=
static_cast<double>(bitmap[i]);
1002 nbPointsInMask = size;
1004 if (nbValidPoints) {
1005 *nbValidPoints = nbPointsInMask;
1011 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1025 if ((height == 0) || (width == 0)) {
1029 unsigned int nbPointsInMask = 0;
1030 unsigned int size = height * width;
1035 for (
unsigned int i = 0; i < size; ++i) {
1037 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1043 for (
unsigned int i = 0; i < (height * width); ++i) {
1044 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1046 nbPointsInMask = size;
1048 if (nbValidPoints) {
1049 *nbValidPoints = nbPointsInMask;
1067 if ((height == 0) || (width == 0)) {
1071 unsigned int nbPointsInMask = 0;
1072 unsigned int size = height * width;
1077 for (
unsigned int i = 0; i < size; ++i) {
1079 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1085 for (
unsigned int i = 0; i < (height * width); ++i) {
1086 res +=
static_cast<double>(
bitmap[i].R) +
static_cast<double>(
bitmap[i].G) +
static_cast<double>(
bitmap[i].B);
1088 nbPointsInMask = size;
1090 if (nbValidPoints) {
1091 *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)