Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vpImage::getStdev specialization #1349

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 180 additions & 4 deletions modules/core/include/visp3/core/vpImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,14 @@ template <class Type> double vpImage<Type>::getStdev(const vpImage<bool> *p_mask

/*!
* \brief Return the standard deviation of the bitmap
*
* \param[in] mean The mean of the image.
* For a vpRGBa or a vpRGBf image, we compute the standard deviation as follow:
*
* \f$ stdev = \sqrt{\frac{1}{nbValidPoints} \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$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* \param[in] mean The mean of the image.
* \return double The standard deviation of the color image.
*/
template <class Type> double vpImage<Type>::getStdev(const double &mean) const
{
Expand All @@ -1023,9 +1029,16 @@ template <class Type> double vpImage<Type>::getStdev(const double &mean) const
/*!
* \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}{nbValidPoints} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2 \delta(r,c)} where \delta(r,c) = 1 if p_mask[r][c], 0 otherwise\f$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* \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 points must be considered, if set.
* \return double The standard deviation taking into account only the points for which the mask is true.
*/
template <class Type> double vpImage<Type>::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage<bool> *p_mask) const
{
Expand All @@ -1043,6 +1056,144 @@ template <class Type> double vpImage<Type>::getStdev(const double &mean, const u
return std::sqrt(sum);
}

/*
/!\ Did not use Doxygen for this method because it does not handle template specialization
* 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}{width * height} \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$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* param[in] mean The mean of the image.
* return The standard deviation.
*/
template <> inline double vpImage<vpRGBa>::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<double>(bitmap[i].R) + static_cast<double>(bitmap[i].G) + static_cast<double>(bitmap[i].B);
res += (val - mean) * (val - mean);
}
res /= static_cast<double>(size);
return std::sqrt(res);
}

/*
/!\ Did not use Doxygen for this method because it does not handle template specialization
* 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}{nbValidPoints} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2 \delta(r,c)} where \delta(r,c) = 1 if p_mask[r][c], 0 otherwise\f$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* 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 points must be considered, if set.
* return The standard deviation taking into account only the points for which the mask is true.The standard deviation taking into account only the points for which the mask is true.
*/
template <> inline double vpImage<vpRGBa>::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage<bool> *p_mask) const
{
if ((height == 0) || (width == 0)) {
return 0.0;
}

if (p_mask == nullptr) {
return getStdev(mean);
}

const unsigned int size = width * height;
double sum = 0.;
for (unsigned int i = 0; i < size; ++i) {
if (p_mask->bitmap[i]) {
double val = static_cast<double>(bitmap[i].R) + static_cast<double>(bitmap[i].G) + static_cast<double>(bitmap[i].B);
sum += (val - mean) * (val - mean);
}
}
sum /= static_cast<double>(nbValidPoints);
return std::sqrt(sum);
}

/*
/!\ Did not use Doxygen for this method because it does not handle template specialization
* 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}{width * height} \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$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* param[in] mean The mean of the image.
* return The standard deviation.
*/
/**
* \brief \copybrief double vpImage::getStdev(const double &) const
*/
template <> inline double vpImage<vpRGBf>::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<double>(bitmap[i].R) + static_cast<double>(bitmap[i].G) + static_cast<double>(bitmap[i].B);
res += (val - mean) * (val - mean);
}
res /= static_cast<double>(size);
return std::sqrt(res);
}

/*
/!\ Did not use Doxygen for this method because it does not handle template specialization
* 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}{nbValidPoints} \sum_{r = 0}^{height-1} \sum_{c = 0}^{width-1} (I[r][c].R + I[r][c].G + I[r][c].B - \mu)^2 \delta(r,c)} where \delta(r,c) = 1 if p_mask[r][c], 0 otherwise\f$
*
* where \f$ \mu \f$ is the mean of the image as computed by \b vpImage::getMeanValue() .
*
* 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 points must be considered, if set.
* return The standard deviation taking into account only the points for which the mask is true.
*/
/**
* \brief \copybrief double vpImage::getStdev(const double &, const unsigned int&, const vpImage<bool>*) const
*/
template <> inline double vpImage<vpRGBf>::getStdev(const double &mean, const unsigned int &nbValidPoints, const vpImage<bool> *p_mask) const
{
if ((height == 0) || (width == 0)) {
return 0.0;
}

if (p_mask == nullptr) {
return getStdev(mean);
}

const unsigned int size = width * height;
double sum = 0.;
for (unsigned int i = 0; i < size; ++i) {
if (p_mask->bitmap[i]) {
double val = static_cast<double>(bitmap[i].R) + static_cast<double>(bitmap[i].G) + static_cast<double>(bitmap[i].B);
sum += (val - mean) * (val - mean);
}
}
sum /= static_cast<double>(nbValidPoints);
return std::sqrt(sum);
}

/*!
* \brief Return the minimum value within the bitmap
* \param onlyFiniteVal : This parameter is ignored for non double or non float bitmap.
Expand Down Expand Up @@ -1950,7 +2101,7 @@ template <> inline vpRGBa vpImage<vpRGBa>::getValue(const vpImagePoint &ip) cons
}

/**
* Compute the sum of image intensities.
* \brief Compute the sum of image intensities.
* For vpRGBa image type, compute the sum (R+G+B) of image intensities.
*/
template <class Type> inline double vpImage<Type>::getSum() const
Expand All @@ -1966,7 +2117,7 @@ template <class Type> inline double vpImage<Type>::getSum() const
}

/**
* Compute the sum of image intensities.
* \brief Compute the sum of image intensities.
* For vpRGBa 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.
Expand Down Expand Up @@ -1995,6 +2146,11 @@ template <class Type> inline double vpImage<Type>::getSum(const vpImage<bool> *p

/**
* \relates vpImage
*
* \brief Get the sum of the image.
* For a vpRGBf image, we takes the sum of the R, G and B components.
*
* \return The sum of the R, G and B components of all pixels.
*/
template <> inline double vpImage<vpRGBa>::getSum() const
{
Expand All @@ -2010,6 +2166,14 @@ template <> inline double vpImage<vpRGBa>::getSum() const

/**
* \relates vpImage
* \brief Get the sum of the image, taking into account the boolean mask \b p_mask
* for which a true value indicates to consider a pixel and false means to ignore it.
* For a vpRGBa image, we takes the sum of the R, G and B components.
*
* \param[in] p_mask If different from nullptr, boolean mask that tells which pixels are
* to be considered.
* \param[out] nbValidPoints The number of pixels which were taken into account.
* \return The sum of the R, G and B components of all pixels that were taken into account.
*/
template <> inline double vpImage<vpRGBa>::getSum(const vpImage<bool> *p_mask, unsigned int &nbValidPoints) const
{
Expand All @@ -2036,6 +2200,10 @@ template <> inline double vpImage<vpRGBa>::getSum(const vpImage<bool> *p_mask, u

/**
* \relates vpImage
* \brief Get the sum of the image.
* For a vpRGBf image, we takes the sum of the R, G and B components.
*
* \return The sum of the R, G and B components of all pixels.
*/
template <> inline double vpImage<vpRGBf>::getSum() const
{
Expand All @@ -2051,6 +2219,14 @@ template <> inline double vpImage<vpRGBf>::getSum() const

/**
* \relates vpImage
* \brief Get the sum of the image, taking into account the boolean mask \b p_mask
* for which a true value indicates to consider a pixel and false means to ignore it.
* For a vpRGBf image, we takes the sum of the R, G and B components.
*
* \param[in] p_mask If different from nullptr, boolean mask that tells which pixels are
* to be considered.
* \param[out] nbValidPoints The number of pixels which were taken into account.
* \return The sum of the R, G and B components of all pixels that were taken into account.
*/
template <> inline double vpImage<vpRGBf>::getSum(const vpImage<bool> *p_mask, unsigned int &nbValidPoints) const
{
Expand Down
Loading
Loading