I want to create an image like this:
From an image like this:
It depends on what type your input matrix is.
If it is a logical matrix you can simply use
invImg = ~img;
If you have scalar values in the range of 0 to n use
invImg = n - img;
Edit:
If you want a black and white image try the following (perhaps you need to play with the level paramter):
invImg = ~im2bw(img, 0.5);