function thres(file, n) image = imread(file); [rows, cols] = size(image); for i = 1:rows for j = 1:cols if image(i, j) < n image(i, j) = 0; end end end imwrite(image, 'thresOut.pgm', 'pgm'); end