I am trying to write a function that thresholds a grey-level image F
and a threshold value t
(0 ≤ t ≤ 255
) such that r = 0
for r < t
and r = 255
otherwise.
I have tried to implement this, but imshow(r)
does not produce an output.
function f = imgThreshold(img, t)
f = img;
if (f < t)
f = 0;
else
f = 1;
end
img = imread('https://i.stack.imgur.com/kP0u2.png');
t = 20;
r = imgThreshold(img, t);
imshow(r);
This should threshold this image. However, it does not do so. What am I doing wrong?