Effacer les filtres
Effacer les filtres

How to Threshold image ?

64 vues (au cours des 30 derniers jours)
RuiQi
RuiQi le 6 Fév 2016
Commenté : Image Analyst le 6 Fév 2016
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);

Réponses (1)

Walter Roberson
Walter Roberson le 6 Fév 2016
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 commentaire
Image Analyst
Image Analyst le 6 Fév 2016
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.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by