Histogram and automatic thresholding
5 views (last 30 days)
Show older comments
Hello everyone, sorry for requesting another. Really new to imaging.
I have perform the normalized gradient magnitude. Also found the histogram of it. But I wish to apply an authomatic thresholding technique based on the histogram of the normalized gradient magnitude. All edge map pixel with values greater than the threshold retains their original values, while those edge map pixels with values less than the threshold had their values set to zero.
please find my code;
im=dicomread('Image');
%applying sobel filtering
P1=fspecial('sobel');
P2=P1;
Data1=imfilter(im,P1,'replicate');
Data2=imfilter(im,P2,'replicate');
% gradient magnitude
grad=sqrt((Data1.^2)+(Data2.^2));
figure,imshow(grad,[]);
%%Normalize the Image:
myImg=grad;
myRange = getrangefromclass(myImg(1));
newMax = myRange(2);
newMin = myRange(1);
myImgNorm = (myImg - min(myImg(:)))*(newMax - newMin)/(max(myImg(:)) -
min(myImg(:))) + newMin;
figure,imshow(myImgNorm,[]);
%%calculating the histogram of normalized gradient
bin=255;
imhist(double(myImgNorm(:)),bin);
%figure,plot(h);
The next step I need your help is:
To perform the automatic threshold based on the histogram of the normalized gradient magnitude.
input image=Normalized gradient magnitude.
Thank you for your help in advance.
Regards,
3 Comments
Image Analyst
on 8 Nov 2013
You didn't do it correctly. Just format the code, not your comments. And get rid of empty lines between code. Then just highlight the code (only, no regular text from you) and click the {}Code button.
Accepted Answer
Image Analyst
on 8 Nov 2013
I don't know what algorithm you're going to use to find the threshold from the histogram. There are many, many methods. The most famous is Otsu's but I find that is only good for high contrast bi-modal histograms. An edge image may have a skewed histogram that looks kind of log-normal in shape (like a skewed Gaussian). For those kinds of histograms, I find the triangle method works fairly well, where it will find the "corner" in the skewed slope of the histogram mode.
Anyway, whatever method you select, once you have the threshold, to binarize your image, you simply do
binaryImage = yourEdgeImage > thresholdValue; % can use < or <= or >= if you want.
2 Comments
Image Analyst
on 8 Nov 2013
I can't help more than that now - I'm packing to go away for the weekend in a few minutes.
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!