Modification of image using custom histogram

14 views (last 30 days)
jay
jay on 30 Dec 2014
Commented: Image Analyst on 31 Dec 2014
Hi Matlabers
I'm looking for some tips on custom histogram modification. Here's what I need to do: I am reducing the number of bins in an image to 48 or below, I need to modify the positions of image histogram bins _ without _ changing the levels of those bins.
Initially the effect would be to evenly space the histogram bins across the range (in this case 0 - 255, always having the first bin at 0 and the first at 255), while keeping the levels and order of those bins the same.I would also like to modify the histogram to resemble different distribution, such as normal or beta.
I then need to change the contrast levels of an image to match this new histogram.
I've been struggling with this for a while, so any help would be very much appreciated!
Thanks in advance!
Jay

Answers (2)

Sean de Wolski
Sean de Wolski on 30 Dec 2014
  3 Comments
Image Analyst
Image Analyst on 30 Dec 2014
What does "without changing the levels" mean? If you move the bins, you've changed the levels over which that bin is looking at. If you have some arbitrary histogram shape and you want it to be some other shape just by changing what gray levels the bins collect, then it may not be possible. You'll actually have to change some of the gray levels of the image also, such that now some gray levels will fall into multiple bins instead of all into the same bin. For example if you have a bin at gray level 125 with a count of 1000 pixels in it, you might have to take 300 of them and put them into a bin at 110 gray levels, 400 of them and put them into a bin as 111 gray levels, and 300 of them and put them into a bin at 112 gray levels. But you have to be careful how you select the gray levels to reassign to other gray levels. You need to do it randomly or else you'll notice weird artifacts in your image. That's what I do in the app Sean referred to. If you post an image and post some curve that you want to make it into, then I might be able to code it up for you. A less sophisticated, less accurate version is in the function imhistmatch() of the Image Processing Toolbox.
jay
jay on 30 Dec 2014
OK, I'll write an example. Could you let me know if it's feasible. I'm actually trying to replicate some results I've seen in a scientific paper.
I take a grayscale image, use imhist() with a bin number of 16, for example... something pretty small. So it looks like this:
I want to move the positions of the bins so that they are more even, need a bin at 0 and 255. I want to keep the vertical heights (levels) of the bins the same and keep them in the same order also.
I then want to take this modified histogram and change the contrast levels of the image using it.
Apparently this process has been used in the paper I'm looking at...Is this possible? Cheers for your help
Jay

Sign in to comment.


Image Analyst
Image Analyst on 30 Dec 2014
You can precisely specify where each bin starts and stops if you use histc() instead of imhist(). histc() sounds like it will do what you want.
  8 Comments
jay
jay on 31 Dec 2014
Hi again Image Analyst. What I would like to do use a histogram to alter the image. So, the basic idea is to take the equalised histogram I was talking about earlier and replace an image's existing histogram with my new one. Do you know of a way I can do this?
Cheers
Image Analyst
Image Analyst on 31 Dec 2014
I don't think you need to equalize the image as an intermediate step. Just use imhistmatch() for an approximate transform. There are more accurate ways, but this quick and dirty method will probably do the trick for you.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!