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/imgproc/vpImgproc.h> 83 unsigned char lut[256];
84 for (
unsigned int i = 0; i < 256; i++) {
85 lut[i] = vpMath::saturate<unsigned char>(alpha * i + beta);
125 for (
unsigned int i = 0; i < 256; i++) {
126 lut[i].
R = vpMath::saturate<unsigned char>(alpha * i + beta);
127 lut[i].
G = vpMath::saturate<unsigned char>(alpha * i + beta);
128 lut[i].
B = vpMath::saturate<unsigned char>(alpha * i + beta);
129 lut[i].
A = vpMath::saturate<unsigned char>(alpha * i + beta);
175 unsigned int cdf[256];
176 unsigned int cdfMin = UINT_MAX, cdfMax = 0;
177 unsigned int minValue =
182 if (cdf[0] < cdfMin && cdf[0] > 0) {
187 for (
unsigned int i = 1; i < 256; i++) {
188 cdf[i] = cdf[i - 1] + hist[i];
190 if (cdf[i] < cdfMin && cdf[i] > 0) {
195 if (cdf[i] > cdfMax) {
202 if (nbPixels == cdfMin) {
208 unsigned char lut[256];
209 for (
unsigned int x = minValue; x <= maxValue; x++) {
210 lut[x] =
vpMath::round((cdf[x] - cdfMin) / (
double)(nbPixels - cdfMin) * 255.0);
267 unsigned char *ptrStart = (
unsigned char *)I.
bitmap;
268 unsigned char *ptrEnd = ptrStart + size * 4;
269 unsigned char *ptrCurrent = ptrStart;
271 unsigned int cpt = 0;
272 while (ptrCurrent != ptrEnd) {
273 *ptrCurrent = pR.bitmap[cpt];
276 *ptrCurrent = pG.bitmap[cpt];
279 *ptrCurrent = pB.bitmap[cpt];
282 *ptrCurrent = pa.bitmap[cpt];
295 (
unsigned char *)saturation.bitmap, (
unsigned char *)value.bitmap, size);
302 (
unsigned char *)value.bitmap, (
unsigned char *)I.
bitmap, size);
336 double inverse_gamma = 1.0;
338 inverse_gamma = 1.0 / gamma;
344 unsigned char lut[256];
345 for (
unsigned int i = 0; i < 256; i++) {
346 lut[i] = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
377 double inverse_gamma = 1.0;
379 inverse_gamma = 1.0 / gamma;
386 for (
unsigned int i = 0; i < 256; i++) {
387 lut[i].
R = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
388 lut[i].
G = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
389 lut[i].
B = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
390 lut[i].
A = vpMath::saturate<unsigned char>(pow((
double)i / 255.0, inverse_gamma) * 255.0);
421 unsigned char min = 255, max = 0;
424 unsigned char range = max - min;
427 unsigned char lut[256];
429 for (
unsigned int x = min; x <= max; x++) {
430 lut[x] = 255 * (x - min) / range;
464 vpRGBa min = 255, max = 0;
474 unsigned char minChannel, maxChannel;
475 pR.getMinMaxValue(minChannel, maxChannel);
479 pG.getMinMaxValue(minChannel, maxChannel);
483 pB.getMinMaxValue(minChannel, maxChannel);
487 pa.getMinMaxValue(minChannel, maxChannel);
493 unsigned char rangeR = max.
R - min.
R;
495 for (
unsigned int x = min.
R; x <= max.R; x++) {
496 lut[x].
R = 255 * (x - min.
R) / rangeR;
499 lut[min.
R].
R = min.
R;
502 unsigned char rangeG = max.G - min.
G;
504 for (
unsigned int x = min.
G; x <= max.G; x++) {
505 lut[x].
G = 255 * (x - min.
G) / rangeG;
508 lut[min.
G].
G = min.
G;
511 unsigned char rangeB = max.B - min.
B;
513 for (
unsigned int x = min.
B; x <= max.B; x++) {
514 lut[x].
B = 255 * (x - min.
B) / rangeB;
517 lut[min.
B].
B = min.
B;
520 unsigned char rangeA = max.A - min.
A;
522 for (
unsigned int x = min.
A; x <= max.A; x++) {
523 lut[x].
A = 255 * (x - min.
A) / rangeA;
526 lut[min.
A].
A = min.
A;
566 double minSaturation, maxSaturation, minValue, maxValue;
567 saturationImage.getMinMaxValue(minSaturation, maxSaturation);
568 valueImage.getMinMaxValue(minValue, maxValue);
570 double *ptrStart = saturationImage.bitmap;
571 double *ptrEnd = saturationImage.bitmap + size;
572 double *ptrCurrent = ptrStart;
575 if (maxSaturation - minSaturation > 0.0) {
576 while (ptrCurrent != ptrEnd) {
577 *ptrCurrent = (*ptrCurrent - minSaturation) / (maxSaturation - minSaturation);
583 if (maxValue - minValue > 0.0) {
584 ptrStart = valueImage.bitmap;
585 ptrEnd = valueImage.bitmap + size;
586 ptrCurrent = ptrStart;
588 while (ptrCurrent != ptrEnd) {
589 *ptrCurrent = (*ptrCurrent - minValue) / (maxValue - minValue);
626 if (weight < 1.0 && weight >= 0.0) {
632 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
633 double val = (I.
bitmap[cpt] - weight * I_blurred.
bitmap[cpt]) / (1 - weight);
634 I.
bitmap[cpt] = vpMath::saturate<unsigned char>(val);
668 if (weight < 1.0 && weight >= 0.0) {
679 for (
unsigned int cpt = 0; cpt < I.
getSize(); cpt++) {
680 double val_R = (I.
bitmap[cpt].
R - weight * I_blurred_R.
bitmap[cpt]) / (1 - weight);
681 double val_G = (I.
bitmap[cpt].
G - weight * I_blurred_G.
bitmap[cpt]) / (1 - weight);
682 double val_B = (I.
bitmap[cpt].
B - weight * I_blurred_B.
bitmap[cpt]) / (1 - weight);
684 I.
bitmap[cpt].
R = vpMath::saturate<unsigned char>(val_R);
685 I.
bitmap[cpt].
G = vpMath::saturate<unsigned char>(val_G);
686 I.
bitmap[cpt].
B = vpMath::saturate<unsigned char>(val_B);
VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, const unsigned int size=7, const double weight=0.6)
Used to indicate that a value is not in the allowed range.
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.
Type * bitmap
points toward the bitmap
VISP_EXPORT void adjust(vpImage< unsigned char > &I, const double alpha, const double beta)
error that can be emited by ViSP classes.
Class to compute a gray level image histogram.
VISP_EXPORT void gammaCorrection(vpImage< unsigned char > &I, const double gamma)
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.
static int round(const double x)
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
unsigned int getSize() const
void calculate(const vpImage< unsigned char > &I, const unsigned int nbins=256, const unsigned int nbThreads=1)
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)
static void RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, const unsigned int size)
unsigned char R
Red component.
static void HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, const unsigned int size)
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
unsigned int getHeight() const
void performLut(const Type(&lut)[256], const unsigned int nbThreads=1)