Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to estimate the (weber) contrast of an image?

Hi, can someone help me to calculate the contrast of an luminance-image? I've already implement a method to calculate the contrast of color and a approach for the luminance- contrast. I think the weber-contrast is a good solution. Isn't it?

The formula i found on Wikipedia: weber contrast there I representing the luminance of the features and I_b the background luminance.

For my implementation i use JavaCV. The code is:

public double analyse(CvMat input) {
    double contrast = 0;

    // convert to lab to extract luminance channel

    cvCvtColor(input, input, CV_BGR2Lab);

    CvMat background = cvCreateMat(input.rows(), input.cols(), CV_8UC1);
    cvSplit(input, background, null, null, null);

    //calc local background
    cvSmooth(background, background, CV_BLUR, 5);
    JavaCVUtil.showImage(background.asIplImage(), "");
    int width = input.cols();
    int height = input.rows();



    for (int y = 0; y < height; y++) {

        for (int x = 0; x < width; x++) {
            contrast += (input.get(y, x, 0) - background.get(y, x))
                    / background.get(y, x);

        }
    }
     //normalize
    contrast /= (height * width);
    return contrast

}

Maybe someone can say me what's wrong with this code. For example, for the following image i get a NaN Error: image description

greetings