Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Histogram Equilization

I want to do histogram equilization(for 16 bit image) manually without using opencv API , i am using the function :

   Mat image = Mat(h, w, CV_16UC1, image_data);

   Mat new_image = Mat::zeros(image.size(), image.type());

   for (int x = 0; x < image.rows; ++x) 
    {
        for (int y = 0; y < image.cols; ++y) 
        {
            new_image.at<ushort>(x, y) = saturate_cast<ushort>(((pow(2, bpp) - 1) / (max - min))*(image.at<ushort>(x, y) - min));
        }
    }

Here ,

image : 16 bit image.

min : 0

max :65535

bpp :16

But i am not getting equalized image. I got half image black and half image is same as input image.

why it is happening is there need to modified the code ? Please give me any suggestion.

Histogram Equilization

I want to do histogram equilization(for 16 bit image) manually without using opencv API , i am using the function :

   Mat image = Mat(h, w, CV_16UC1, image_data);

   Mat new_image = Mat::zeros(image.size(), image.type());

   for (int x = 0; x < image.rows; ++x) 
    {
        for (int y = 0; y < image.cols; ++y) 
        {
            new_image.at<ushort>(x, y) = saturate_cast<ushort>(((pow(2, bpp) - 1) / (max - min))*(image.at<ushort>(x, y) - min));
        }
    }

Here ,

image : 16 bit image.

min : 0

max :65535

bpp :16

But i am not getting equalized image. I got half image black and half image is same as input image.

image and half image black. If i give min =0 and max = 255 then i got half image white and half image black. why it is happening is there need to modified the code ? Please give me any suggestion. suggestion.

click to hide/show revision 3
None

updated 2019-01-16 07:47:06 -0600

berak gravatar image

Histogram Equilization

I want to do histogram equilization(for 16 bit image) manually without using opencv API , i am using the function :

   Mat image = Mat(h, w, CV_16UC1, image_data);

   Mat new_image = Mat::zeros(image.size(), image.type());

   for (int x = 0; x < image.rows; ++x) 
    {
        for (int y = 0; y < image.cols; ++y) 
        {
            new_image.at<ushort>(x, y) = saturate_cast<ushort>(((pow(2, bpp) - 1) / (max - min))*(image.at<ushort>(x, y) - min));
        }
    }

Here ,

image : 16 bit image.

min : 0

max :65535

bpp :16

But i am not getting equalized image. I got half image is same as input image and half image black. If i give min =0 and max = 255 then i got half image white and half image black. why it is happening is there need to modified the code ? Please give me any suggestion.