Modification of image using custom histogram

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

Antworten (2)

Sean de Wolski
Sean de Wolski am 30 Dez. 2014

0 Stimmen

3 Kommentare

jay
jay am 30 Dez. 2014
Hi Sean. I've seen this but I'm not sure how this does what I'm asking for. I went through the code but couldn't find specifically where I was able to redistribute the bins without changing the levels and use the histogram to modify the image contrast. Maybe you could give a bit more explanation..? Would be very much appreciated!!
Cheers!
Image Analyst
Image Analyst am 30 Dez. 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 am 30 Dez. 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

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 30 Dez. 2014

0 Stimmen

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 Kommentare

Sean de Wolski
Sean de Wolski am 30 Dez. 2014
or in R2014b, histcounts which is a sexier histc
Image Analyst
Image Analyst am 30 Dez. 2014
Jay, what you said in the comment about moving the bins around will change the gray levels and put the bins, with the same heights, but at different locations. This is called histogram equalization and is done by the function histeq(). It generally gives harsh, unnatural-looking images and is not needed for any image analysis. If you just want to improve the visual contrast there are better ways, such as imadjust() which does a linear stretch which looks more natural. If you want a flat histogram (all bins the same height) then you can't use histogram equalization and would have to use something like my File Exchange submission.
jay
jay am 30 Dez. 2014
Hi Image Analyist OK, this is where you're knowledge might set me straight in some areas. I've looked at histeq() already and I thought it was what I was after but I had the impression that it changed the bin levels when it did the equalisation. Am I wrong there?
Also, do you know if theres a way to modify an image's contrast levels with a specific histogram? Cheers again Image Analyst
Image Analyst
Image Analyst am 31 Dez. 2014
Yes, you're wrong there. Histogram equalization just moves the bins to different x (gray level) locations but it keeps the bin heights (pixel counts) the same. This is because it essentially uses intlut() to remap gray levels to new gray levels.
There is no way to change contrast without changing the gray levels. You can change just the displayed gray levels if you want with colormap() and leave the underlying gray levels the same. Or you can change the actual gray levels of the image (not just how it's displayed).
jay
jay am 31 Dez. 2014
Hi again Image Analyst Thanks for the info on histeq. I was certain that it was changing the bin levels, but I'll take a more in depth look at that. Thanks again. Yes, I want to change the actual gray levels of the image. Can you tell me the best way to achieve this?
Cheers!
Image Analyst
Image Analyst am 31 Dez. 2014
It depends on how you want to change them. You could use imadjust if you want to change them in a linear way. Or if you have some crazy algorithm to map them according to some arbitrary curve, then you can use intlut(). Lots and lots of other operations will alter the image and thus alter the histogram, some globally, and some locally adaptive, like adapthisteq().
jay
jay am 31 Dez. 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 am 31 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Gefragt:

jay
am 30 Dez. 2014

Kommentiert:

am 31 Dez. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by