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) {
377 double m = bitmap[0];
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) {
461 double m = bitmap[0];
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) {
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) {
724 "values of an empty image"));
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;
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) {
845 for (
unsigned int i = 0; i < size; ++i) {
848 nbPointsInMask = size;
850 sum /=
static_cast<double>(nbPointsInMask);
852 *nbValidPoints = nbPointsInMask;
854 return std::sqrt(sum);
857#ifndef DOXYGEN_SHOULD_SKIP_THIS
879 if ((height == 0) || (width == 0)) {
884 unsigned int nbPointsInMask = 0;
889 for (
unsigned int i = 0;
i < size; ++
i) {
891 double val =
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
892 sum += (val - mean) * (val - mean);
898 for (
unsigned int i = 0;
i < size; ++
i) {
899 double val =
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
900 sum += (val - mean) * (val - mean);
902 nbPointsInMask = size;
904 sum /=
static_cast<double>(nbPointsInMask);
906 *nbValidPoints = nbPointsInMask;
908 return std::sqrt(sum);
932 if ((height == 0) || (width == 0)) {
937 unsigned int nbPointsInMask = 0;
942 for (
unsigned int i = 0;
i < size; ++
i) {
944 double val =
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
945 sum += (val - mean) * (val - mean);
951 for (
unsigned int i = 0;
i < size; ++
i) {
952 double val =
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
953 sum += (val - mean) * (val - mean);
955 nbPointsInMask = size;
957 sum /=
static_cast<double>(nbPointsInMask);
959 *nbValidPoints = nbPointsInMask;
961 return std::sqrt(sum);
978 if ((height == 0) || (width == 0)) {
990 unsigned int nbPointsInMask = 0;
991 unsigned int size = height * width;
993 for (
unsigned int i = 0; i < size; ++i) {
995 res +=
static_cast<double>(
bitmap[i]);
1001 for (
unsigned int i = 0; i < size; ++i) {
1002 res +=
static_cast<double>(
bitmap[i]);
1004 nbPointsInMask = size;
1006 if (nbValidPoints) {
1007 *nbValidPoints = nbPointsInMask;
1013#ifndef DOXYGEN_SHOULD_SKIP_THIS
1028 if ((height == 0) || (width == 0)) {
1032 unsigned int nbPointsInMask = 0;
1038 for (
unsigned int i = 0;
i < size; ++
i) {
1040 res +=
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
1047 res +=
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
1049 nbPointsInMask = size;
1051 if (nbValidPoints) {
1052 *nbValidPoints = nbPointsInMask;
1071 if ((height == 0) || (width == 0)) {
1075 unsigned int nbPointsInMask = 0;
1081 for (
unsigned int i = 0;
i < size; ++
i) {
1083 res +=
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
1090 res +=
static_cast<double>(bitmap[
i].R) +
static_cast<double>(bitmap[i].G) +
static_cast<double>(bitmap[
i].B);
1092 nbPointsInMask = size;
1094 if (nbValidPoints) {
1095 *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)
Definition of the vpImage class member functions.
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
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)