Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

differences in histogram equalization between equalizeHist and wikipedia example

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.

Why?

differences in histogram equalization between equalizeHist and wikipedia example

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.

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]

differences in histogram equalization between equalizeHist and wikipedia example

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.

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;
}

differences in histogram equalization between equalizeHist and wikipedia example

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;
}