Modification of image using custom histogram
Ältere Kommentare anzeigen
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
am 30 Dez. 2014
0 Stimmen
3 Kommentare
jay
am 30 Dez. 2014
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
am 30 Dez. 2014
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
am 30 Dez. 2014
or in R2014b, histcounts which is a sexier histc
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
am 30 Dez. 2014
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
am 31 Dez. 2014
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
am 31 Dez. 2014
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.
Kategorien
Mehr zu Contrast Adjustment finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
