MATLAB: How to make this code work? i am trying to threshold an image.

digital image processingimage analysisimage processing

im = imread('image.bmp');
x = []; %creating empty matrix for x
y = [];%creating empty matrix for y
for i = [1: size(im,1)]
for j = [1:size(im,2)]
if 120 < im(i,j) < 200 {
x = [x,i]; y = [y,j];
i = 1; j = 1;
end
}
end
end

Best Answer

if true
%Threshold
x = []; %creating empty matrix for x
y = [];%creating empty matrix for y
for i = 1: size(im,1)
for j = 1:size(im,2)
if im(i,j)<200 && im(i,j)>50
im(i,j) = 255;
else im(i,j) = 0; %%else set rest of pixel values outside the range to 0
end
end
end
end
Related Question