MATLAB Answers


Histogram to image

Asked by M W
on 23 Dec 2011

Hi, I'm a Matlab newbie and I desperately need your help. I need to enhance image by performing operations on its histogram. But how can I apply that changes to the image? It's easy to extract histogram form the image but how to transform histogram back into image after performing e.g. histogram smoothing?



No products are associated with this question.

2 Answers

Answer by Image Analyst
on 24 Dec 2011

I suppose you could maybe use the intlut() function. But why don't you tell us what you want to do and we can tell you the best way to achieve it? You can upload your image to


Answer by M W
on 24 Dec 2011

Thanks for the answer.

I need to implement a Generalized Histogram Equalization algorithm. The method is described in the following article (click to open/download a PDF file)

I'm stuck at the point where I have to remove the noise from histogram. I can do it e.g. with the medfilt1() method. It works fine for the histogram but what about the image? I need to change the image too. Is there any way to recreate the image based on the new histogram?


on 25 Dec 2011

Thanks again, you are really helping me!
Your histogram shaping program seems to be an amazing piece of code. I figured out that the TransformImage() function is the key for equalization. I'm now able to equalize histogram for any image. It really is flat and the image's contrast is improved.
However I have a hard time modifying it so that it works only for specified piece of histogram (e.g bins form 90 to 150) and the rest of the bins should be left as they are.
Another approach could be to pass a matrix with specified points and desired heights of the bins between that points) to the function and perform the equalization based on this matrix.
Can I ask for a little help?

Image Analyst
on 25 Dec 2011

It may take you a while, as it would for me, but I think is something that you could handle.

on 25 Dec 2011

Yea, I think I can do it. You provided a really good commentary.
I've spent some time looking through this code and I see that the desiredPixelsInEachBin vector may be the key.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!