Your images are not black and white. There is also a gray color.
Given that you are editing that it seems to you that some pixel is off and any pixel is off (i.e., convert it to a direct binary black and white image), this should do what you want:
newImg = zeros(size(img)); newImg(img > 0) = 0; % <-- This line is not really needed newImg(img = 0) = 1;
Please note that the 2nd line is not strictly necessary, since the new image is initialized to 0 in any case, this is just to show what exactly is happening.
source share