First time here? Check out the FAQ!

Ask Your Question
0

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

asked Aug 29 '12

501 Not Implemented gravatar 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

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Aug 29 '12

unxnut gravatar image

Could it be that your background(x,y) luminance gets a value of zero for a certain pixel in the loop where you accumulate contrast. I do not see you checking for that. Thus, if there is a single pixel with a luminance of zero in the image, you will get the exception.

Preview: (hide)

Comments

oh yes, you're right. I correct it. thx

Question Tools

1 follower

Stats

Asked: Aug 29 '12

Seen: 3,913 times

Last updated: Aug 29 '12