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