Image with uniform histogram

I have a grey scale image and I want to change the histogram of the image to uniform histogram. How should I do it?

 Accepted Answer

Walter Roberson
Walter Roberson on 30 May 2012

6 Comments

will histeq function also make the histogram uniform?
http://www.mathworks.com/help/toolbox/images/ref/histeq.html
histeq enhances the contrast of images by transforming the values in an intensity image, or the values in the colormap of an indexed image, so that the histogram of the output image approximately matches a specified histogram.
the specified histogram I want is the uniform histogram. Will using histeq(image) output the uniform histogram?
It will do what it can. Depending on the distribution of pixel values, it may not be possible to achieve equal distribution (at least not without randomly reassigning points.) For example there just isn't much that histogram equalization can do to equalize an image that is completely constant.
Oh wait, I should have said "NO". histeq() applied to an image will output the adjusted image, not the histogram of the adjusted image. You would still need something like imhist() applied to the histeq() adjusted image in order to get the new histogram.
Many thanks :)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 31 May 2012
Histogram equalization WILL NOT give you a flat histogram. If someone told you that, then they were wrong. It would only work for the case of infinite number of pixels and infinite number of gray levels, essentially a continuum in both space and intensity. If you want a flat histogram for finite-sized, intensity-quantized actual real world digital images, you'll need to use my histogram shaping program which WILL give you a flat histogram, or any other shape you can possibly think of. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 The screenshot shows the image going to the shape of a girl's silhouette but like the text says, it also can give you a flat histogram - it asks you which you want when it starts up. The histogram will be truly exactly flat, at least to the extent that it can be. The only situation when it won't is when your image doesn't have an integer multiple of 256 pixels because it can't be perfectly flat in that case (think about it). But it will be as flat as mathematically possible. It's an clever and interesting algorithm - it uses noise and sorting to enforce perfect flatness and avoid contours.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!