Histogram and automatic thresholding

2 次查看(过去 30 天)
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 个评论
Josh
Josh 2013-11-8
Sorry Matt , I will try to format the code as you suggested.
Image Analyst
Image Analyst 2013-11-8
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.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-11-8
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 个评论
Josh
Josh 2013-11-8
Thanks Sir for your response. I have used Otsu's method as you mentioned, I had some difficulties. But I am not familiar with the triangle method, I wish to try it as well ,please Sir can you help. I don't know if my code was right the manner I find the threshold value from the histogram using.
imhist(double(myImgNorm(:)),bin); % histogram of the normalized gradient
thresholdValue=graythresh(imhist(double(myImgNorm(:)),bin); % threshold value from histogram
Image Analyst
Image Analyst 2013-11-8
I can't help more than that now - I'm packing to go away for the weekend in a few minutes.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by