I want to create an image like this: From an image like this:
Your images aren't binary black & white. There's gray in there as well.
Given from your edit that you seem to what any on pixel to be off, and any off pixel to be on (ie, convert it to a straight 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;
Note that the 2nd line isn't strictly necessary since the new image is being initialized to 0 anyways, it's just in to show what exactly is going on.