64 #include <visp3/core/vpHistogram.h> 65 #include <visp3/core/vpImageConvert.h> 66 #include <visp3/core/vpImageFilter.h> 67 #include <visp3/core/vpMath.h> 68 #include <visp3/core/vpGaussianFilter.h> 69 #include <visp3/imgproc/vpImgproc.h> 84 unsigned char lut[256];
85 for (
unsigned int i = 0; i < 256; i++) {
86 lut[i] = vpMath::saturate<unsigned char>(alpha * i + beta);
126 for (
unsigned int i = 0; i < 256; i++) {
127 lut[i].
R = vpMath::saturate<unsigned char>(alpha * i + beta);
128 lut[i].
G = vpMath::saturate<unsigned char>(alpha * i + beta);
129 lut[i].
B = vpMath::saturate<unsigned char>(alpha * i + beta);
130 lut[i].
A = vpMath::saturate<unsigned char>(alpha * i + beta);
176 unsigned int cdf[256];
177 unsigned int cdfMin = UINT_MAX, cdfMax = 0;
178 unsigned int minValue =
183 if (cdf[0] < cdfMin && cdf[0] > 0) {
188 for (
unsigned int i = 1; i < 256; i++) {
189 cdf[i] = cdf[i - 1] + hist[i];
191 if (cdf[i] < cdfMin && cdf[i] > 0) {
196 if (cdf[i] > cdfMax) {
203 if (nbPixels == cdfMin) {
209 unsigned char lut[256];
210 for (
unsigned int x = minValue; x <= maxValue; x++) {
211 lut[x] =
vpMath::round((cdf[x] - cdfMin) / (
double)(nbPixels - cdfMin) * 255.0);
268 unsigned char *ptrStart = (
unsigned char *)I.
bitmap;
269 unsigned char *ptrEnd = ptrStart + size * 4;
270 unsigned char *ptrCurrent = ptrStart;
272 unsigned int cpt = 0;
273 while (ptrCurrent != ptrEnd) {
274 *ptrCurrent = pR.bitmap[cpt];
277 *ptrCurrent = pG.bitmap[cpt];
280 *ptrCurrent = pB.bitmap[cpt];
283 *ptrCurrent = pa.bitmap[cpt];
296 (
unsigned char *)saturation.bitmap, (
unsigned char *)value.bitmap, size);
303 (
unsigned char *)value.bitmap, (
unsigned char *)I.
bitmap, size);
337 double inverse_gamma = 1.0;
339 inverse_gamma = 1.0 / gamma;
345 unsigned char lut[256];
346 for (
unsigned int i = 0; i < 256; i++) {
347 lut[i] = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
378 double inverse_gamma = 1.0;
380 inverse_gamma = 1.0 / gamma;
387 for (
unsigned int i = 0; i < 256; i++) {
388 lut[i].
R = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
389 lut[i].
G = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
390 lut[i].
B = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
391 lut[i].
A = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
422 unsigned char min = 255, max = 0;
425 unsigned char range = max - min;
428 unsigned char lut[256];
430 for (
unsigned int x = min; x <= max; x++) {
431 lut[x] = 255 * (x - min) / range;
465 vpRGBa min = 255, max = 0;
475 unsigned char minChannel, maxChannel;
476 pR.getMinMaxValue(minChannel, maxChannel);
480 pG.getMinMaxValue(minChannel, maxChannel);
484 pB.getMinMaxValue(minChannel, maxChannel);
488 pa.getMinMaxValue(minChannel, maxChannel);
494 unsigned char rangeR = max.
R - min.
R;
496 for (
unsigned int x = min.
R; x <= max.R; x++) {
497 lut[x].
R = 255 * (x - min.
R) / rangeR;
500 lut[min.
R].
R = min.
R;
503 unsigned char rangeG = max.G - min.
G;
505 for (
unsigned int x = min.
G; x <= max.G; x++) {
506 lut[x].
G = 255 * (x - min.
G) / rangeG;
509 lut[min.
G].
G = min.
G;
512 unsigned char rangeB = max.B - min.
B;
514 for (
unsigned int x = min.
B; x <= max.B; x++) {
515 lut[x].
B = 255 * (x - min.
B) / rangeB;
518 lut[min.
B].
B = min.
B;
521 unsigned char rangeA = max.A - min.
A;
523 for (
unsigned int x = min.
A; x <= max.A; x++) {
524 lut[x].
A = 255 * (x - min.
A) / rangeA;
527 lut[min.
A].
A = min.
A;
567 double minSaturation, maxSaturation, minValue, maxValue;
568 saturationImage.getMinMaxValue(minSaturation, maxSaturation);
569 valueImage.getMinMaxValue(minValue, maxValue);
571 double *ptrStart = saturationImage.bitmap;
572 double *ptrEnd = saturationImage.bitmap + size;
573 double *ptrCurrent = ptrStart;
576 if (maxSaturation - minSaturation > 0.0) {
577 while (ptrCurrent != ptrEnd) {
578 *ptrCurrent = (*ptrCurrent - minSaturation) / (maxSaturation - minSaturation);
584 if (maxValue - minValue > 0.0) {
585 ptrStart = valueImage.bitmap;
586 ptrEnd = valueImage.bitmap + size;
587 ptrCurrent = ptrStart;
589 while (ptrCurrent != ptrEnd) {
590 *ptrCurrent = (*ptrCurrent - minValue) / (maxValue - minValue);
627 if (weight < 1.0 && weight >= 0.0) {
631 gaussian_filter.apply(I, I_blurred);
634 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
635 double val = (I.
bitmap[cpt] - weight * I_blurred.bitmap[cpt]) / (1 - weight);
636 I.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
670 if (weight < 1.0 && weight >= 0.0) {
674 gaussian_filter.apply(I, I_blurred);
677 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
678 double val_R = (I.
bitmap[cpt].
R - weight * I_blurred.bitmap[cpt].R) / (1 - weight);
679 double val_G = (I.
bitmap[cpt].
G - weight * I_blurred.bitmap[cpt].G) / (1 - weight);
680 double val_B = (I.
bitmap[cpt].
B - weight * I_blurred.bitmap[cpt].B) / (1 - weight);
682 I.
bitmap[cpt].
R = vpMath::saturate<unsigned char>(val_R);
683 I.
bitmap[cpt].
G = vpMath::saturate<unsigned char>(val_G);
684 I.
bitmap[cpt].
B = vpMath::saturate<unsigned char>(val_B);
706 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS 721 if (weight < 1.0 && weight >= 0.0) {
727 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
728 double val = (I.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
729 I.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
757 if (weight < 1.0 && weight >= 0.0) {
763 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
764 double val = (I2.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
765 I2.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
785 if (weight < 1.0 && weight >= 0.0) {
796 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
797 double val_R = (I.
bitmap[cpt].
R - weight * I_blurred_R.
bitmap[cpt]) / (1 - weight);
798 double val_G = (I.
bitmap[cpt].
G - weight * I_blurred_G.
bitmap[cpt]) / (1 - weight);
799 double val_B = (I.
bitmap[cpt].
B - weight * I_blurred_B.
bitmap[cpt]) / (1 - weight);
801 I.
bitmap[cpt].
R = vpMath::saturate<unsigned char>(val_R);
802 I.
bitmap[cpt].
G = vpMath::saturate<unsigned char>(val_G);
803 I.
bitmap[cpt].
B = vpMath::saturate<unsigned char>(val_B);
830 if (weight < 1.0 && weight >= 0.0) {
841 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
842 double val_R = (I2.
bitmap[cpt].
R - weight * I_blurred_R.
bitmap[cpt]) / (1 - weight);
843 double val_G = (I2.
bitmap[cpt].
G - weight * I_blurred_G.
bitmap[cpt]) / (1 - weight);
844 double val_B = (I2.
bitmap[cpt].
B - weight * I_blurred_B.
bitmap[cpt]) / (1 - weight);
846 I2.
bitmap[cpt].
R = vpMath::saturate<unsigned char>(val_R);
847 I2.
bitmap[cpt].
G = vpMath::saturate<unsigned char>(val_G);
848 I2.
bitmap[cpt].
B = vpMath::saturate<unsigned char>(val_B);
Used to indicate that a value is not in the allowed range.
void performLut(const Type(&lut)[256], unsigned int nbThreads=1)
unsigned int getWidth() const
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
unsigned char B
Blue component.
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
Type * bitmap
points toward the bitmap
error that can be emited by ViSP classes.
Class to compute a gray level image histogram.
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
unsigned char G
Green component.
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
VISP_EXPORT void adjust(vpImage< unsigned char > &I, double alpha, double beta)
unsigned int getSize() const
unsigned char A
Additionnal component.
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< double > &GI, unsigned int size=7, double sigma=0., bool normalize=true)
void calculate(const vpImage< unsigned char > &I, unsigned int nbins=256, unsigned int nbThreads=1)
static void HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, unsigned int size)
static int round(double x)
unsigned char R
Red component.
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
VISP_EXPORT void gammaCorrection(vpImage< unsigned char > &I, double gamma)
unsigned int getHeight() const
vp_deprecated VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, unsigned int size=7, double weight=0.6)