59 #include <visp3/core/vpGaussianFilter.h>
60 #include <visp3/core/vpHistogram.h>
61 #include <visp3/core/vpImageConvert.h>
62 #include <visp3/core/vpImageFilter.h>
63 #include <visp3/core/vpMath.h>
64 #include <visp3/imgproc/vpImgproc.h>
71 unsigned char lut[256];
72 for (
unsigned int i = 0; i < 256; i++) {
73 lut[i] = vpMath::saturate<unsigned char>(alpha * i + beta);
92 for (
unsigned int i = 0; i < 256; i++) {
93 lut[i].
R = vpMath::saturate<unsigned char>(alpha * i + beta);
94 lut[i].
G = vpMath::saturate<unsigned char>(alpha * i + beta);
95 lut[i].
B = vpMath::saturate<unsigned char>(alpha * i + beta);
96 lut[i].
A = vpMath::saturate<unsigned char>(alpha * i + beta);
122 unsigned int cdf[256];
123 unsigned int cdfMin = UINT_MAX, cdfMax = 0;
124 unsigned int minValue =
129 if (cdf[0] < cdfMin && cdf[0] > 0) {
134 for (
unsigned int i = 1; i < 256; i++) {
135 cdf[i] = cdf[i - 1] + hist[i];
137 if (cdf[i] < cdfMin && cdf[i] > 0) {
142 if (cdf[i] > cdfMax) {
149 if (nbPixels == cdfMin) {
155 unsigned char lut[256];
156 for (
unsigned int x = minValue; x <= maxValue; x++) {
157 lut[x] =
vpMath::round((cdf[x] - cdfMin) / (
double)(nbPixels - cdfMin) * 255.0);
191 unsigned char *ptrStart = (
unsigned char *)I.
bitmap;
192 unsigned char *ptrEnd = ptrStart + size * 4;
193 unsigned char *ptrCurrent = ptrStart;
195 unsigned int cpt = 0;
196 while (ptrCurrent != ptrEnd) {
197 *ptrCurrent = pR.
bitmap[cpt];
200 *ptrCurrent = pG.
bitmap[cpt];
203 *ptrCurrent = pB.
bitmap[cpt];
206 *ptrCurrent = pa.
bitmap[cpt];
220 (
unsigned char *)saturation.
bitmap, (
unsigned char *)value.
bitmap, size);
227 (
unsigned char *)value.
bitmap, (
unsigned char *)I.
bitmap, size);
239 double inverse_gamma = 1.0;
241 inverse_gamma = 1.0 / gamma;
248 unsigned char lut[256];
249 for (
unsigned int i = 0; i < 256; i++) {
250 lut[i] = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
264 double inverse_gamma = 1.0;
266 inverse_gamma = 1.0 / gamma;
274 for (
unsigned int i = 0; i < 256; i++) {
275 lut[i].
R = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
276 lut[i].
G = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
277 lut[i].
B = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
278 lut[i].
A = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
293 unsigned char min = 255, max = 0;
296 unsigned char range = max - min;
299 unsigned char lut[256];
301 for (
unsigned int x = min; x <= max; x++) {
302 lut[x] = 255 * (x - min) / range;
322 vpRGBa min = 255, max = 0;
332 unsigned char minChannel, maxChannel;
351 unsigned char rangeR = max.
R - min.
R;
353 for (
unsigned int x = min.
R; x <= max.R; x++) {
354 lut[x].
R = 255 * (x - min.
R) / rangeR;
358 lut[min.
R].
R = min.
R;
361 unsigned char rangeG = max.G - min.
G;
363 for (
unsigned int x = min.
G; x <= max.G; x++) {
364 lut[x].
G = 255 * (x - min.
G) / rangeG;
368 lut[min.
G].
G = min.
G;
371 unsigned char rangeB = max.B - min.
B;
373 for (
unsigned int x = min.
B; x <= max.B; x++) {
374 lut[x].
B = 255 * (x - min.
B) / rangeB;
378 lut[min.
B].
B = min.
B;
381 unsigned char rangeA = max.A - min.
A;
383 for (
unsigned int x = min.
A; x <= max.A; x++) {
384 lut[x].
A = 255 * (x - min.
A) / rangeA;
388 lut[min.
A].
A = min.
A;
412 double minSaturation, maxSaturation, minValue, maxValue;
413 saturationImage.getMinMaxValue(minSaturation, maxSaturation);
416 double *ptrStart = saturationImage.bitmap;
417 double *ptrEnd = saturationImage.bitmap + size;
418 double *ptrCurrent = ptrStart;
421 if (maxSaturation - minSaturation > 0.0) {
422 while (ptrCurrent != ptrEnd) {
423 *ptrCurrent = (*ptrCurrent - minSaturation) / (maxSaturation - minSaturation);
429 if (maxValue - minValue > 0.0) {
430 ptrStart = valueImage.
bitmap;
431 ptrEnd = valueImage.
bitmap + size;
432 ptrCurrent = ptrStart;
434 while (ptrCurrent != ptrEnd) {
435 *ptrCurrent = (*ptrCurrent - minValue) / (maxValue - minValue);
454 if (weight < 1.0 && weight >= 0.0) {
458 gaussian_filter.
apply(I, I_blurred);
461 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
462 double val = (I.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
463 I.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
477 if (weight < 1.0 && weight >= 0.0) {
481 gaussian_filter.
apply(I, I_blurred);
484 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
485 double val_R = (I.
bitmap[cpt].R - weight * I_blurred.
bitmap[cpt].
R) / (1 - weight);
486 double val_G = (I.
bitmap[cpt].G - weight * I_blurred.
bitmap[cpt].
G) / (1 - weight);
487 double val_B = (I.
bitmap[cpt].B - weight * I_blurred.
bitmap[cpt].
B) / (1 - weight);
489 I.
bitmap[cpt].R = vpMath::saturate<unsigned char>(val_R);
490 I.
bitmap[cpt].G = vpMath::saturate<unsigned char>(val_G);
491 I.
bitmap[cpt].B = vpMath::saturate<unsigned char>(val_B);
503 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
518 if (weight < 1.0 && weight >= 0.0) {
524 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
525 double val = (I.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
526 I.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
554 if (weight < 1.0 && weight >= 0.0) {
560 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
561 double val = (I2.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
562 I2.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
582 if (weight < 1.0 && weight >= 0.0) {
593 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
594 double val_R = (I.
bitmap[cpt].R - weight * I_blurred_R.
bitmap[cpt]) / (1 - weight);
595 double val_G = (I.
bitmap[cpt].G - weight * I_blurred_G.
bitmap[cpt]) / (1 - weight);
596 double val_B = (I.
bitmap[cpt].B - weight * I_blurred_B.
bitmap[cpt]) / (1 - weight);
598 I.
bitmap[cpt].R = vpMath::saturate<unsigned char>(val_R);
599 I.
bitmap[cpt].G = vpMath::saturate<unsigned char>(val_G);
600 I.
bitmap[cpt].B = vpMath::saturate<unsigned char>(val_B);
627 if (weight < 1.0 && weight >= 0.0) {
638 for (
unsigned int cpt = 0; cpt < I2.
getSize(); cpt++) {
639 double val_R = (I2.
bitmap[cpt].
R - weight * I_blurred_R.
bitmap[cpt]) / (1 - weight);
640 double val_G = (I2.
bitmap[cpt].
G - weight * I_blurred_G.
bitmap[cpt]) / (1 - weight);
641 double val_B = (I2.
bitmap[cpt].
B - weight * I_blurred_B.
bitmap[cpt]) / (1 - weight);
643 I2.
bitmap[cpt].
R = vpMath::saturate<unsigned char>(val_R);
644 I2.
bitmap[cpt].
G = vpMath::saturate<unsigned char>(val_G);
645 I2.
bitmap[cpt].
B = vpMath::saturate<unsigned char>(val_B);
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
void apply(const vpImage< unsigned char > &I, vpImage< unsigned char > &I_blur)
Class to compute a gray level image histogram.
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 void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size)
static void gaussianBlur(const vpImage< unsigned char > &I, vpImage< FilterType > &GI, unsigned int size=7, FilterType sigma=0., bool normalize=true)
unsigned int getWidth() const
void performLut(const Type(&lut)[256], unsigned int nbThreads=1)
unsigned int getSize() const
Type * bitmap
points toward 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.
static int round(double x)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.
VISP_EXPORT void adjust(vpImage< unsigned char > &I, double alpha, double beta)
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
VISP_EXPORT void gammaCorrection(vpImage< unsigned char > &I, double gamma)
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
vp_deprecated VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, unsigned int size=7, double weight=0.6)