How to Threshold image ?

조회 수: 99 (최근 30일)
RuiQi
RuiQi 2016년 2월 6일
댓글: Image Analyst 2016년 2월 6일
Hi i am trying to write out the code for edge detection on my own. I dont know how to threshold to get the edges. There is no function that lets me threshold it like output = threshold(image,200) where 200 is the value to threshold. My code is below. help thanks
Image = imread('42049.jpg');
Result = conv2(double(Image),Gx,'valid');
Result = abs(Result);
minV = min(Result(:));
maxV = max(Result(:));
FinalResult = (Result-minV)*255/(maxV-minV);
BW = im2bw(FinalResult, 0.8);
imshow(BW);

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 6일
BW = FinalResult >= 200;
The error you have, by the way, is that you are leaving your final result as double precision when you scale it by 255. The thresholding of double precision images is done under the assumption that they are in the range 0 to 1. If you had not multiplied by 255, or if you had used uint8() on FinalResult then your thresholding would have worked.
  댓글 수: 1
Image Analyst
Image Analyst 2016년 2월 6일
Plus, FinalResult is not needed, at least in the code we see so far. Doing a linear scaling on an image does not change what the final thresholded image will look like. It will just threshold at a different place, that's all. But the binary image will be the same.
If you are doing edge detection,like, say, with a Laplacian, you will have two values on either side of an edge - a positive one and a negative one. I don't think it's necessary to use abs - that will just make the edge thicker, and possibly with a zero between them so you'd have a double edge line.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by