Ask Your Question
1

differences in histogram equalization between equalizeHist and wikipedia example

asked 2013-01-13 14:33:20 -0600

nkint gravatar image

updated 2013-01-14 04:28:53 -0600

hi, i'm reading about histogram equalization.

In wikipedia article on that there is an example with this matrix:

img = (Mat_<uchar>(8,8) << 
    52, 55, 61, 66, 70, 61, 64, 73,
    63, 59, 55, 90, 109, 85, 69, 72,
    62, 59, 68, 113, 144, 104, 66, 73,
    63, 58, 71, 122, 154, 106, 70, 69,
    67, 61, 68, 104, 126, 88, 68, 70,
    79, 65, 60, 70, 77, 68, 58, 75,
    85, 71, 64, 59, 55, 61, 65, 83,
    87, 79, 69, 68, 65, 76, 78, 94 );

if i use equalizeHist from opencv imageproc module i obtain a result a little bit different from the one in the wikipedia.

The think that let me think is that the values (my result and the wikipedia example) are not so different, but the lowest value in the input (52) is mapped to 4 with cv::equalizeHist and not to 0 as in wikipedia result (as i expected to be as the lowest value).

Why?

this is my result:

[4, 16, 56, 96, 147, 56, 76, 167;
68, 36, 16, 215, 235, 203, 131, 159;
60, 36, 120, 239, 251, 227, 96, 167;
68, 24, 155, 243, 255, 231, 147, 131;
100, 56, 120, 227, 247, 211, 120, 147;
191, 88, 40, 147, 179, 120, 24, 171;
203, 155, 76, 36, 16, 56, 88, 195;
207, 191, 131, 120, 88, 175, 183, 219]

And this is my code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>

using namespace cv;
using namespace std;

int main(int /*argc*/, char** /*argv*/) {

    // wikipedia example
    Mat img = (Mat_<uchar>(8,8) << 
        52, 55, 61, 66, 70, 61, 64, 73,
        63, 59, 55, 90, 109, 85, 69, 72,
        62, 59, 68, 113, 144, 104, 66, 73,
        63, 58, 71, 122, 154, 106, 70, 69,
        67, 61, 68, 104, 126, 88, 68, 70,
        79, 65, 60, 70, 77, 68, 58, 75,
        85, 71, 64, 59, 55, 61, 65, 83,
        87, 79, 69, 68, 65, 76, 78, 94 );
    cout << "test Mat 8x8" << endl << img << endl;
    double m, M;
    minMaxLoc(img, &m, &M, 0, 0);
    cout << "min value: " << m << endl;
    cout << "max value: " << M << endl;

    Mat imgEqualized;
    equalizeHist(img, imgEqualized);
    cout << imgEqualized << endl;

    return 0;
}
edit retag flag offensive close merge delete

Comments

Can you post your result?

bsdnoobz gravatar imagebsdnoobz ( 2013-01-13 23:26:09 -0600 )edit

ok edited!

nkint gravatar imagenkint ( 2013-01-14 04:43:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-01-14 03:06:55 -0600

Daniil Osokin gravatar image

updated 2013-01-14 03:53:52 -0600

Hi! I have exactly the same output with OpenCV.

edit flag offensive delete link more

Comments

1

can you post me you code please? i have a little bit different result. in particular 52 is not mapped to 0 but to 4.

nkint gravatar imagenkint ( 2013-01-14 04:22:00 -0600 )edit

I've executed your code and have correct output. Which version of OpenCV do you use?

Daniil Osokin gravatar imageDaniil Osokin ( 2013-01-14 05:48:53 -0600 )edit

Version 2.4.3.. you mean that if you execute my code you have the same reuslt of wikipedia? the result matrix first element mat.at<uchar>(0,0) === 0 and not 4?

nkint gravatar imagenkint ( 2013-01-14 06:12:16 -0600 )edit

Yes, cout << (int)imgEqualized.at<uchar>(0,0) << endl gives me a 0. Don't you printing img (ascii code 52 is for 4)? minMaxLoc gives me 0 and 255 on equalized image.

Daniil Osokin gravatar imageDaniil Osokin ( 2013-01-14 06:19:52 -0600 )edit

no minMacLoc give me 4 and 255 and i use cout &lt;&lt; imgEqualized &lt;&lt; endl;. I'm on ubuntu 10.10, gcc version 4.4.5, opencv 2.4.3, i compile with g++pkg-config --libs --cflags opencvtest.cpp . What could it be? what version of opencv do you use?

nkint gravatar imagenkint ( 2013-01-14 06:29:49 -0600 )edit

I'm on top of 2.4 branch. Could you try it?

Daniil Osokin gravatar imageDaniil Osokin ( 2013-01-14 12:21:12 -0600 )edit

Question Tools

Stats

Asked: 2013-01-13 14:33:20 -0600

Seen: 721 times

Last updated: Jan 14 '13