How to Threshold image ?
94 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
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
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!