diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index beda009229..85918192d0 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -186,9 +186,7 @@ template class vpImage // Return the maximum value within the bitmap Type getMaxValue(bool onlyFiniteVal = true) const; // Return the mean value of the bitmap - double getMeanValue() const; - double getMeanValue(const vpImage *p_mask) const; - double getMeanValue(const vpImage *p_mask, unsigned int &nbValidPoints) const; + double getMeanValue(const vpImage *p_mask = nullptr, unsigned int *nbValidPoints = nullptr) const; // Return the minumum value within the bitmap Type getMinValue(bool onlyFiniteVal = true) const; @@ -225,13 +223,10 @@ template class vpImage */ inline unsigned int getSize() const { return width * height; } - double getStdev() const; - double getStdev(const vpImage *p_mask) const; - double getStdev(const double &mean) const; - double getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage *p_mask) const; + double getStdev(const vpImage *p_mask = nullptr, unsigned int *nbValidPoints = nullptr) const; + double getStdev(const double &mean, const vpImage *p_mask = nullptr, unsigned int *nbValidPoints = nullptr) const; - double getSum() const; - double getSum(const vpImage *p_mask, unsigned int &nbValidPoints) const; + double getSum(const vpImage *p_mask = nullptr, unsigned int *nbValidPoints = nullptr) const; // Gets the value of a pixel at a location. Type getValue(unsigned int i, unsigned int j) const; @@ -947,60 +942,29 @@ template <> inline float vpImage::getMaxValue(bool onlyFiniteVal) const } /*! - \brief Return the mean value of the bitmap -*/ -template double vpImage::getMeanValue() const + * \brief Return the mean value of the bitmap. + * + * For vpRGBa and vpRGBf image types, the sum of image intensities is computed by (R+G+B). + * + * \param[in] p_mask Optional parameter. If not set to nullptr, a boolean mask that indicates which points must be + * considered, if set to true. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. + */ +template double vpImage::getMeanValue(const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - - return getSum() / (height * width); -} - -/*! - \brief Return the mean value of the bitmap - - \param[in] p_mask A boolean mask that indicates which points must be considered, if set. -*/ -template double vpImage::getMeanValue(const vpImage *p_mask) const -{ - unsigned int nbValidPoints = 0; - return getMeanValue(p_mask, nbValidPoints); -} - -/*! - \brief Return the mean value of the bitmap - - \param[in] p_mask A boolean mask that indicates which points must be considered, if set. - \param[out] nbValidPoints Number of points that are valid according to the boolean mask. -*/ -template double vpImage::getMeanValue(const vpImage *p_mask, unsigned int &nbValidPoints) const -{ - nbValidPoints = 0; - if ((height == 0) || (width == 0)) { - return 0.0; + unsigned int nbPointsInMask = 0; + double sum = getSum(p_mask, &nbPointsInMask); + if (nbPointsInMask == 0) { + throw(vpException(vpException::divideByZeroError, "Division by zero in vpImage::getMeanValue()")); } - - double sum = getSum(p_mask, nbValidPoints); - return sum / nbValidPoints; -} - -/*! - * \brief Return the standard deviation of the bitmap. - * - * - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] - * - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] - * - * where \f$ \mu \f$ is the mean of the image as computed internally by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ - * is the size of the image. - */ -template double vpImage::getStdev() const -{ - double mean = getMeanValue(); - return getStdev(mean); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; + } + return sum / nbPointsInMask; } /*! @@ -1015,41 +979,13 @@ template double vpImage::getStdev() const * is the number of pixels to consider in the mask. * * \param[in] p_mask A boolean mask that indicates which points must be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. */ -template double vpImage::getStdev(const vpImage *p_mask) const +template double vpImage::getStdev(const vpImage *p_mask, unsigned int *nbValidPoints) const { - unsigned int nbValidPoints = 0; double mean = getMeanValue(p_mask, nbValidPoints); - return getStdev(mean, nbValidPoints, p_mask); -} - -/*! - * \brief Return the standard deviation of the bitmap. - * - * - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] - * - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] - * - * where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ - * is the size of the image. - * - * \param[in] mean The mean \f$ \mu \f$ of the image. - * \return The standard deviation of the color image. - */ -template double vpImage::getStdev(const double &mean) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - - const unsigned int size = width * height; - double sum = 0.; - for (unsigned int i = 0; i < size; ++i) { - sum += (bitmap[i] - mean) * (bitmap[i] - mean); - } - sum /= static_cast(size); - return std::sqrt(sum); + return getStdev(mean, p_mask); } /*! @@ -1064,64 +1000,45 @@ template double vpImage::getStdev(const double &mean) const * is the number of pixels to consider in the mask. * * \param[in] mean The mean of the image. -* \param[in] nbValidPoints Number of points that are valid according to the boolean mask. -* \param[in] p_mask A boolean mask that indicates which pixels must be considered, if set to true. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. * \return double The standard deviation taking into account only the points for which the mask is true. */ -template double vpImage::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage *p_mask) const +template double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - if (p_mask == nullptr) { - return getStdev(mean); - } - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } - const unsigned int size = width * height; double sum = 0.; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + unsigned int nbPointsInMask = 0; + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + sum += (bitmap[i] - mean) * (bitmap[i] - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { sum += (bitmap[i] - mean) * (bitmap[i] - mean); } + nbPointsInMask = size; + } + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } - sum /= static_cast(nbValidPoints); return std::sqrt(sum); } #ifndef DOXYGEN_SHOULD_SKIP_THIS -/*! - * \brief Return the standard deviation of the bitmap. - * - * - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] - * - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] - * - * where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ - * is the size of the image. - * - * \param[in] mean The mean \f$ \mu \f$ of the image. - * \return The standard deviation of the color image. - */ -template <> inline double vpImage::getStdev(const double &mean) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - - double res = 0.0; - const unsigned int size = height * width; - for (unsigned int i = 0; i < size; ++i) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - res += (val - mean) * (val - mean); - } - res /= static_cast(size); - return std::sqrt(res); -} - /*! * \brief Return the standard deviation of the bitmap * @@ -1134,61 +1051,44 @@ template <> inline double vpImage::getStdev(const double &mean) const * is the number of pixels to consider in the mask. * * \param[in] mean The mean of the image. -* \param[in] nbValidPoints Number of points that are valid according to the boolean mask. -* \param[in] p_mask A boolean mask that indicates which pixels must be considered, if set to true. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. * \return double The standard deviation taking into account only the points for which the mask is true. */ -template <> inline double vpImage::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage *p_mask) const +template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - if (p_mask == nullptr) { - return getStdev(mean); - } - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } const unsigned int size = width * height; double sum = 0.; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + unsigned int nbPointsInMask = 0; + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); sum += (val - mean) * (val - mean); } + nbPointsInMask = size; } - sum /= static_cast(nbValidPoints); - return std::sqrt(sum); -} - -/*! - * \brief Return the standard deviation of the bitmap. - * - * - For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2}\f] - * - For a unary type image (unsigned char, float, double), we compute the standard deviation as follow: - * \f[ stdev = \sqrt{\frac{1}{size} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c] - \mu)^2}\f] - * - * where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() and \f$ \mbox{size} \f$ - * is the size of the image. - * - * \param[in] mean The mean \f$ \mu \f$ of the image. - * \return The standard deviation of the color image. - */ -template <> inline double vpImage::getStdev(const double &mean) const -{ - if ((height == 0) || (width == 0)) { - return 0.0; - } - - double res = 0.0; - const unsigned int size = height * width; - for (unsigned int i = 0; i < size; ++i) { - double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - res += (val - mean) * (val - mean); + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } - res /= static_cast(size); - return std::sqrt(res); + return std::sqrt(sum); } /*! @@ -1203,31 +1103,43 @@ template <> inline double vpImage::getStdev(const double &mean) const * is the number of pixels to consider in the mask. * * \param[in] mean The mean of the image. -* \param[in] nbValidPoints Number of points that are valid according to the boolean mask. -* \param[in] p_mask A boolean mask that indicates which pixels must be considered, if set to true. +* \param[in] p_mask Optional parameter. When different from nullptr, a boolean mask that indicates which pixels must +* be considered, if set to true. +* \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are +* valid according to the boolean mask or image size when `p_mask` is set to nullptr. * \return double The standard deviation taking into account only the points for which the mask is true. */ -template <> inline double vpImage::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage *p_mask) const +template <> inline double vpImage::getStdev(const double &mean, const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - if (p_mask == nullptr) { - return getStdev(mean); - } - if (p_mask->getWidth() != width || p_mask->getHeight() != height) { - throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); - } - const unsigned int size = width * height; double sum = 0.; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + unsigned int nbPointsInMask = 0; + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute standard deviation: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + sum += (val - mean) * (val - mean); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { double val = static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); sum += (val - mean) * (val - mean); } + nbPointsInMask = size; + } + sum /= static_cast(nbPointsInMask); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } - sum /= static_cast(nbValidPoints); return std::sqrt(sum); } #endif // DOXYGEN_SHOULD_SKIP_THIS @@ -2138,119 +2050,93 @@ template <> inline vpRGBa vpImage::getValue(const vpImagePoint &ip) cons return getValue(ip.get_i(), ip.get_j()); } -/** - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - */ -template inline double vpImage::getSum() const -{ - if ((height == 0) || (width == 0)) - return 0.0; - - double res = 0.0; - for (unsigned int i = 0; i < height * width; ++i) { - res += static_cast(bitmap[i]); - } - return res; -} - /** * \brief Compute the sum of image intensities. * - For unary image types (unsigned char, float, double), compute the sum of image intensities. * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. * - * \param[in] p_mask Boolean mask that indicates the valid points by a true flag. - * \param[out] nbValidPoints The number of valid points according to the \b p_mask. + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. */ -template inline double vpImage::getSum(const vpImage *p_mask, unsigned int &nbValidPoints) const +template inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const { - if ((height == 0) || (width == 0)) + if ((height == 0) || (width == 0)) { + if (nbValidPoints) { + *nbValidPoints = 0; + } return 0.0; - if (p_mask == nullptr) { - nbValidPoints = height * width; - return getSum(); } - + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + } double res = 0.0; - nbValidPoints = 0; + unsigned int nbPointsInMask = 0; unsigned int size = height * width; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + if (p_mask) { + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i]); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < size; ++i) { res += static_cast(bitmap[i]); - ++nbValidPoints; } + nbPointsInMask = size; } - return res; -} - -#ifndef DOXYGEN_SHOULD_SKIP_THIS -/*! - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - */ -template <> inline double vpImage::getSum() const -{ - if ((height == 0) || (width == 0)) - return 0.0; - - double res = 0.0; - for (unsigned int i = 0; i < height * width; ++i) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } + return res; } +#ifndef DOXYGEN_SHOULD_SKIP_THIS /** * \brief Compute the sum of image intensities. * - For unary image types (unsigned char, float, double), compute the sum of image intensities. * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. * - * \param[in] p_mask Boolean mask that indicates the valid points by a true flag. - * \param[out] nbValidPoints The number of valid points according to the \b p_mask. + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. */ -template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int &nbValidPoints) const +template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - - if (p_mask == nullptr) { - nbValidPoints = height * width; - return getSum(); - } - double res = 0.0; - nbValidPoints = 0; + unsigned int nbPointsInMask = 0; unsigned int size = height * width; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < height * width; ++i) { res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - ++nbValidPoints; } + nbPointsInMask = size; } - return res; -} - -/*! - * \brief Compute the sum of image intensities. - * - For unary image types (unsigned char, float, double), compute the sum of image intensities. - * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. - * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. - */ -template <> inline double vpImage::getSum() const -{ - if ((height == 0) || (width == 0)) - return 0.0; - - double res = 0.0; - for (unsigned int i = 0; i < height * width; ++i) { - res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } return res; } @@ -2261,27 +2147,38 @@ template <> inline double vpImage::getSum() const * - For vpRGBa image type, compute the sum (R+G+B) of image intensities. * - For vpRGBf image type, compute the sum (R+G+B) of image intensities. * - * \param[in] p_mask Boolean mask that indicates the valid points by a true flag. - * \param[out] nbValidPoints The number of valid points according to the \b p_mask. + * \param[in] p_mask Optional parameter. If not set to nullptr, pointer to a boolean mask that indicates the valid + * points by a true flag. + * \param[out] nbValidPoints Optional parameter. When different from nullptr contains the number of points that are + * valid according to the boolean mask or image size when `p_mask` is set to nullptr. */ -template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int &nbValidPoints) const +template <> inline double vpImage::getSum(const vpImage *p_mask, unsigned int *nbValidPoints) const { if ((height == 0) || (width == 0)) { return 0.0; } - if (p_mask == nullptr) { - nbValidPoints = height * width; - return getSum(); - } - double res = 0.0; - nbValidPoints = 0; + unsigned int nbPointsInMask = 0; unsigned int size = height * width; - for (unsigned int i = 0; i < size; ++i) { - if (p_mask->bitmap[i]) { + if (p_mask) { + if (p_mask->getWidth() != width || p_mask->getHeight() != height) { + throw(vpException(vpException::fatalError, "Cannot compute sum: image and mask size differ")); + } + for (unsigned int i = 0; i < size; ++i) { + if (p_mask->bitmap[i]) { + res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); + ++nbPointsInMask; + } + } + } + else { + for (unsigned int i = 0; i < height * width; ++i) { res += static_cast(bitmap[i].R) + static_cast(bitmap[i].G) + static_cast(bitmap[i].B); - ++nbValidPoints; } + nbPointsInMask = size; + } + if (nbValidPoints) { + *nbValidPoints = nbPointsInMask; } return res; } diff --git a/modules/core/test/image/testImageMeanAndStdev.cpp b/modules/core/test/image/testImageMeanAndStdev.cpp index 16176290f7..71b0904c3b 100644 --- a/modules/core/test/image/testImageMeanAndStdev.cpp +++ b/modules/core/test/image/testImageMeanAndStdev.cpp @@ -224,8 +224,8 @@ int main(const int argc, const char *argv[]) } unsigned int nbValidPoints = 0; - nameTest = ("vpImage::getSum( const vpImage*, unsigned int& )"); - sum = I_uchar_ref.getSum(&I_mask, nbValidPoints); + nameTest = ("vpImage::getSum( const vpImage *, unsigned int * )"); + sum = I_uchar_ref.getSum(&I_mask, &nbValidPoints); success = vpMath::equal(sum, sum_uchar_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -240,8 +240,8 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getSum( const vpImage* = nullptr, unsigned int& )"); - sum = I_uchar_ref.getSum(nullptr, nbValidPoints); + nameTest = ("vpImage::getSum( vpImage * = nullptr, unsigned int * )"); + sum = I_uchar_ref.getSum(nullptr, &nbValidPoints); success = vpMath::equal(sum, sum_uchar_ref) && (nbValidPoints == (nbCols * nbRows)); if (!success) { ++nbFailedTests; @@ -271,8 +271,8 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getSum( const vpImage*, unsigned int& )"); - sum = I_rgba_ref.getSum(&I_mask, nbValidPoints); + nameTest = ("vpImage::getSum( vpImage *, unsigned int * )"); + sum = I_rgba_ref.getSum(&I_mask, &nbValidPoints); success = vpMath::equal(sum, sum_rgba_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -287,8 +287,8 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getSum( const vpImage* = nullptr, unsigned int& )"); - sum = I_rgba_ref.getSum(nullptr, nbValidPoints); + nameTest = ("vpImage::getSum( vpImage * = nullptr, unsigned int * )"); + sum = I_rgba_ref.getSum(nullptr, &nbValidPoints); success = vpMath::equal(sum, sum_rgba_ref) && (nbValidPoints == (nbCols * nbRows)); if (!success) { ++nbFailedTests; @@ -318,8 +318,8 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getSum( const vpImage*, unsigned int& )"); - sum = I_rgbf_ref.getSum(&I_mask, nbValidPoints); + nameTest = ("vpImage::getSum( vpImage *, unsigned int * )"); + sum = I_rgbf_ref.getSum(&I_mask, &nbValidPoints); success = vpMath::equal(sum, sum_rgbf_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -334,8 +334,8 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getSum( const vpImage* = nullptr, unsigned int& )"); - sum = I_rgbf_ref.getSum(nullptr, nbValidPoints); + nameTest = ("vpImage::getSum( vpImage * = nullptr, unsigned int * )"); + sum = I_rgbf_ref.getSum(nullptr, &nbValidPoints); success = vpMath::equal(sum, sum_rgbf_ref) && (nbValidPoints == (nbCols * nbRows)); if (!success) { ++nbFailedTests; @@ -371,7 +371,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage*)"; + nameTest = "vpImage::getMeanValue(vpImage *)"; mean = I_uchar_ref.getMeanValue(&I_mask); success = vpMath::equal(mean, mean_uchar_true); if (!success) { @@ -386,7 +386,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr)"; + nameTest = "vpImage::getMeanValue(vpImage * = nullptr)"; mean = I_uchar_ref.getMeanValue(nullptr); success = vpMath::equal(mean, mean_uchar_ref); if (!success) { @@ -402,8 +402,8 @@ int main(const int argc, const char *argv[]) } unsigned int nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage*, unsigned int &)"; - mean = I_uchar_ref.getMeanValue(&I_mask, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage *, unsigned int &)"; + mean = I_uchar_ref.getMeanValue(&I_mask, &nbValidPoints); success = vpMath::equal(mean, mean_uchar_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -419,8 +419,8 @@ int main(const int argc, const char *argv[]) } nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr, unsigned int &)"; - mean = I_uchar_ref.getMeanValue(nullptr, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage * = nullptr, unsigned int &)"; + mean = I_uchar_ref.getMeanValue(nullptr, &nbValidPoints); success = vpMath::equal(mean, mean_uchar_ref) && (nbValidPoints == (nbCols * nbRows)); if (!success) { ++nbFailedTests; @@ -450,7 +450,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage*)"; + nameTest = "vpImage::getMeanValue(vpImage *)"; mean = I_rgba_ref.getMeanValue(&I_mask); success = vpMath::equal(mean, mean_rgba_true); if (!success) { @@ -465,7 +465,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr)"; + nameTest = "vpImage::getMeanValue(vpImage * = nullptr)"; mean = I_rgba_ref.getMeanValue(nullptr); success = vpMath::equal(mean, mean_rgba_ref); if (!success) { @@ -481,8 +481,8 @@ int main(const int argc, const char *argv[]) } nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage*, unsigned int &)"; - mean = I_rgba_ref.getMeanValue(&I_mask, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage *, unsigned int &)"; + mean = I_rgba_ref.getMeanValue(&I_mask, &nbValidPoints); success = vpMath::equal(mean, mean_rgba_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -498,8 +498,8 @@ int main(const int argc, const char *argv[]) } nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr, unsigned int &)"; - mean = I_rgba_ref.getMeanValue(nullptr, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage * = nullptr, unsigned int &)"; + mean = I_rgba_ref.getMeanValue(nullptr, &nbValidPoints); success = vpMath::equal(mean, mean_rgba_ref) && (nbValidPoints == (nbRows * nbCols)); if (!success) { ++nbFailedTests; @@ -529,7 +529,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage*)"; + nameTest = "vpImage::getMeanValue(vpImage *)"; mean = I_rgbf_ref.getMeanValue(&I_mask); success = vpMath::equal(mean, mean_rgbf_true); if (!success) { @@ -544,7 +544,7 @@ int main(const int argc, const char *argv[]) } } - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr)"; + nameTest = "vpImage::getMeanValue(vpImage * = nullptr)"; mean = I_rgbf_ref.getMeanValue(nullptr); success = vpMath::equal(mean, mean_rgbf_ref); if (!success) { @@ -560,8 +560,8 @@ int main(const int argc, const char *argv[]) } nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage*, unsigned int &)"; - mean = I_rgbf_ref.getMeanValue(&I_mask, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage *, unsigned int &)"; + mean = I_rgbf_ref.getMeanValue(&I_mask, &nbValidPoints); success = vpMath::equal(mean, mean_rgbf_true) && (nbValidPoints == count_true); if (!success) { ++nbFailedTests; @@ -577,8 +577,8 @@ int main(const int argc, const char *argv[]) } nbValidPoints = 0; - nameTest = "vpImage::getMeanValue(const vpImage* = nullptr, unsigned int &)"; - mean = I_rgbf_ref.getMeanValue(nullptr, nbValidPoints); + nameTest = "vpImage::getMeanValue(vpImage * = nullptr, unsigned int &)"; + mean = I_rgbf_ref.getMeanValue(nullptr, &nbValidPoints); success = vpMath::equal(mean, mean_rgbf_ref) && (nbValidPoints == (nbRows * nbCols)); if (!success) { ++nbFailedTests; @@ -660,10 +660,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage*)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int *)"); unsigned int nbValidPoints = 0; - mean = I_uchar_ref.getMeanValue(&I_mask, nbValidPoints); - stdev = I_uchar_ref.getStdev(mean, nbValidPoints, &I_mask); + mean = I_uchar_ref.getMeanValue(&I_mask, &nbValidPoints); + stdev = I_uchar_ref.getStdev(mean, &I_mask, &nbValidPoints); success = vpMath::equal(stdev, stdev_uchar_true); if (!success) { ++nbFailedTests; @@ -677,10 +677,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage* = nullptr)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int * = nullptr)"); nbValidPoints = 0; - mean = I_uchar_ref.getMeanValue(nullptr, nbValidPoints); - stdev = I_uchar_ref.getStdev(mean, nbValidPoints, nullptr); + mean = I_uchar_ref.getMeanValue(nullptr, &nbValidPoints); + stdev = I_uchar_ref.getStdev(mean, nullptr, &nbValidPoints); success = vpMath::equal(stdev, stdev_uchar_ref) && (nbValidPoints == (nbRows * nbCols)); if (!success) { ++nbFailedTests; @@ -756,10 +756,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage*)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int *)"); nbValidPoints = 0; - mean = I_rgba_ref.getMeanValue(&I_mask, nbValidPoints); - stdev = I_rgba_ref.getStdev(mean, nbValidPoints, &I_mask); + mean = I_rgba_ref.getMeanValue(&I_mask, &nbValidPoints); + stdev = I_rgba_ref.getStdev(mean, &I_mask, &nbValidPoints); success = vpMath::equal(stdev, stdev_rgba_true); if (!success) { ++nbFailedTests; @@ -773,10 +773,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage* = nullptr)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int * = nullptr)"); nbValidPoints = 0; - mean = I_rgba_ref.getMeanValue(nullptr, nbValidPoints); - stdev = I_rgba_ref.getStdev(mean, nbValidPoints, nullptr); + mean = I_rgba_ref.getMeanValue(nullptr, &nbValidPoints); + stdev = I_rgba_ref.getStdev(mean, nullptr, &nbValidPoints); success = vpMath::equal(stdev, stdev_rgba_ref) && (nbValidPoints == (nbRows * nbCols)); if (!success) { ++nbFailedTests; @@ -852,10 +852,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage*)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int *)"); nbValidPoints = 0; - mean = I_rgbf_ref.getMeanValue(&I_mask, nbValidPoints); - stdev = I_rgbf_ref.getStdev(mean, nbValidPoints, &I_mask); + mean = I_rgbf_ref.getMeanValue(&I_mask, &nbValidPoints); + stdev = I_rgbf_ref.getStdev(mean, &I_mask, &nbValidPoints); success = vpMath::equal(stdev, stdev_rgbf_true); if (!success) { ++nbFailedTests; @@ -869,10 +869,10 @@ int main(const int argc, const char *argv[]) } } - nameTest = ("vpImage::getStdev(const double &, const unsigned int&, const vpImage* = nullptr)"); + nameTest = ("vpImage::getStdev(const double &, vpImage *, unsigned int * = nullptr)"); nbValidPoints = 0; - mean = I_rgbf_ref.getMeanValue(nullptr, nbValidPoints); - stdev = I_rgbf_ref.getStdev(mean, nbValidPoints, nullptr); + mean = I_rgbf_ref.getMeanValue(nullptr, &nbValidPoints); + stdev = I_rgbf_ref.getStdev(mean, nullptr, &nbValidPoints); success = vpMath::equal(stdev, stdev_rgbf_ref) && (nbValidPoints == (nbRows * nbCols)); if (!success) { ++nbFailedTests; @@ -889,17 +889,13 @@ int main(const int argc, const char *argv[]) } if (areTestOK) { - if (opt_verbose) { - std::cout << "All tests succeeded" << std::endl; - } + std::cout << "All tests succeeded" << std::endl; return EXIT_SUCCESS; } else { - if (opt_verbose) { - std::cerr << nbFailedTests << " tests failed: " << std::endl; - for (unsigned int i = 0; i < nbFailedTests; ++i) { - std::cerr << " - " << failedTestsNames[i] << std::endl; - } + std::cerr << nbFailedTests << " tests failed: " << std::endl; + for (unsigned int i = 0; i < nbFailedTests; ++i) { + std::cerr << " - " << failedTestsNames[i] << std::endl; } return EXIT_FAILURE; } diff --git a/modules/imgproc/src/vpImgproc.cpp b/modules/imgproc/src/vpImgproc.cpp index 9a9e9a66cb..24b6abf239 100644 --- a/modules/imgproc/src/vpImgproc.cpp +++ b/modules/imgproc/src/vpImgproc.cpp @@ -306,7 +306,7 @@ namespace { /** * \brief This method is an implementation of the article "Towards Real-time Hardware Gamma Correction - * for Dynamic Contrast Enhancement" by Jesse Scott, Michael Pusateri, IEEE Applied Imagery Pattern Recognition + * for Dynamic Contrast Enhancement" by Jesse Scott, Michael Pusateri, IEEE Applied Imagery Pattern Recognition * Workshop (AIPR 2009), 2009 * * The gamma factor depends on the mean of the original image and its intensity range. @@ -386,9 +386,8 @@ void gammaCorrectionNonLinearMethod(vpImage &I, const vpImage &I, const vpImage *p_mask) { - unsigned int nbValidPoints = 0; - double mean = I.getMeanValue(p_mask, nbValidPoints); - double stdev = I.getStdev(mean, nbValidPoints, p_mask); + double mean = I.getMeanValue(p_mask); + double stdev = I.getStdev(p_mask); double meanNormalized = mean / 255.; double stdevNormalized = stdev / 255.; const float tau = 3.f;