/*! \ingroup group_imgproc_contrast Stretch the contrast of a grayscale image. \param I : The grayscale image to stretch the contrast. */ void vp::stretchContrast(vpImage<unsigned char> &I) { //Find min and max intensity values unsigned char min = 255, max = 0; I.getMinMaxValue(min, max); unsigned char range = max - min; //Construct the look-up table unsigned char lut[256]; if(range > 0) { for(unsigned int x = min; x <= max; x++) { lut[x] = 255 * (x - min) / range; } } else { lut[min] = min; } I.performLut(lut); }