필터 지우기
필터 지우기

Histogram and automatic thresholding

조회 수: 3 (최근 30일)
Josh
Josh 2013년 11월 8일
댓글: Image Analyst 2013년 11월 8일
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