Skip to content

Commit

Permalink
Introduce mask in equalizeHistogram()
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Mar 20, 2024
1 parent 1fae635 commit 7ff4042
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
21 changes: 12 additions & 9 deletions modules/imgproc/include/visp3/imgproc/vpImgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ VISP_EXPORT void clahe(const vpImage<vpRGBa> &I1, vpImage<vpRGBa> &I2, int block
* 255] range such as the cumulative histogram distribution becomes linear.
*
* \param I : The grayscale image to apply histogram equalization.
*/
VISP_EXPORT void equalizeHistogram(vpImage<unsigned char> &I);
* \param p_mask : If set, a boolean mask to take into account only the points for which the mask is true.
*/
VISP_EXPORT void equalizeHistogram(vpImage<unsigned char> &I, const vpImage<bool> *p_mask = nullptr);

/*!
* \ingroup group_imgproc_histogram
Expand All @@ -311,8 +312,10 @@ VISP_EXPORT void equalizeHistogram(vpImage<unsigned char> &I);
*
* \param I1 : The first grayscale image.
* \param I2 : The second grayscale image after histogram equalization.
* \param p_mask : If set, a boolean mask to take into account only the points for which the mask is true.
*/
VISP_EXPORT void equalizeHistogram(const vpImage<unsigned char> &I1, vpImage<unsigned char> &I2);
VISP_EXPORT void equalizeHistogram(const vpImage<unsigned char> &I1, vpImage<unsigned char> &I2,
const vpImage<bool> *p_mask = nullptr);

/*!
* \ingroup group_imgproc_histogram
Expand Down Expand Up @@ -355,9 +358,9 @@ VISP_EXPORT void equalizeHistogram(const vpImage<vpRGBa> &I1, vpImage<vpRGBa> &I
* technique. If equals to -2, use automatic Gamma correction based on a logarithmic technique.
* If equals to -3, uses automatic Gamma correction based on classification. If equals to -4, uses automatic Gamma
* correction based on probabilistic.
* \param[in] method: The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma
* \param[in] method : The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma
* factor, or one of the automatic method if \b gamma is negative.
* \param[in] p_mask If different from nullptr, permits to indicate which points must be taken into account by setting
* \param[in] p_mask : If different from nullptr, permits to indicate which points must be taken into account by setting
* them to true.
*/
VISP_EXPORT void gammaCorrection(vpImage<unsigned char> &I, const float &gamma, const vpGammaMethod &method = vp::GAMMA_MANUAL,
Expand All @@ -374,9 +377,9 @@ VISP_EXPORT void gammaCorrection(vpImage<unsigned char> &I, const float &gamma,
* technique. If equals to -2, use automatic Gamma correction based on a logarithmic technique.
* If equals to -3, uses automatic Gamma correction based on classification. If equals to -4, uses automatic Gamma
* correction based on probabilistic.
* \param[in] method: The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma
* \param[in] method : The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma
* factor, or one of the automatic method if \b gamma is negative.
* \param[in] p_mask If different from nullptr, permits to indicate which points must be taken into account by setting
* \param[in] p_mask : If different from nullptr, permits to indicate which points must be taken into account by setting
* them to true.
*/
VISP_EXPORT void gammaCorrection(const vpImage<unsigned char> &I1, vpImage<unsigned char> &I2, const float &gamma,
Expand Down Expand Up @@ -407,9 +410,9 @@ VISP_EXPORT void gammaCorrection(vpImage<vpRGBa> &I, const float &gamma, const v
* \param[out] I2 : The second color image after gamma correction.
* \param[in] gamma : Gamma value.
* \param[in] colorHandling : How to handle the colors of the image.
* \param[in] method: The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma factor,
* \param[in] method : The method to use: either \b GAMMA_MANUAL if the user wants to use a positive constant \b gamma factor,
* or one of the automatic method if \b gamma is negative.
* \param[in] p_mask If different from nullptr, permits to indicate which points must be taken into account by setting
* \param[in] p_mask : If different from nullptr, permits to indicate which points must be taken into account by setting
* them to true.
*/
VISP_EXPORT void gammaCorrection(const vpImage<vpRGBa> &I1, vpImage<vpRGBa> &I2, const float &gamma,
Expand Down
8 changes: 5 additions & 3 deletions modules/imgproc/src/vpImgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,22 @@ void adjust(const vpImage<vpRGBa> &I1, vpImage<vpRGBa> &I2, double alpha, double
vp::adjust(I2, alpha, beta);
}

void equalizeHistogram(vpImage<unsigned char> &I)
void equalizeHistogram(vpImage<unsigned char> &I, const vpImage<bool> *p_mask)
{
vpImage<unsigned char> Icpy = I;
vp::equalizeHistogram(Icpy, I);
vp::equalizeHistogram(Icpy, I, p_mask);
}

void equalizeHistogram(const vpImage<unsigned char> &I1, vpImage<unsigned char> &I2)
void equalizeHistogram(const vpImage<unsigned char> &I1, vpImage<unsigned char> &I2,
const vpImage<bool> *p_mask)
{
if (I1.getWidth() * I1.getHeight() == 0) {
return;
}

// Calculate the histogram
vpHistogram hist;
hist.setMask(p_mask);
hist.equalize(I1, I2);
}

Expand Down

0 comments on commit 7ff4042

Please sign in to comment.