Hi everyone, I'm trying to put a threshold on a grayscale image, and I'm doing it this way: that a "for" loop reads the image pixel by pixel, and if the value of the pixel is less than "0.5" sets its' value to "0", and if it is more than "3", sets it to "256". Here it is my code:
my_image =imread('picture.tif');for R=1:num of Rows for C=1:num of Columns pixel=my_image(R,C); if pixel<0.50000000 , pixel=0.000000000;, end if pixel>3.00000000 , pixel=256;, end thresh(R,C)=pixel; endendim_thresh=mat2gray(thresh);figure,imshow(im_thresh);title('thresholding');
But it doesn't work properly. Sometimes it misses some values that ought to be changed, and sometimes changes the ones that shouldn't be changed, to arbitrary values…for example changes the value "0.8182" to "0.0032". It also doesn't have enough accuracy, for example instead of changing the value "0.425" to "0", changes it to "0.0002". Could you please tell me what's causing this problem, and help me to fix the code?! Thanks in advance…
Best Answer