![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176351/image.png)
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 个评论
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
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 个评论
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 Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!