I want to create an image like this: From an image like this:
UPDATE
Here's what's generated by 255-img
, but the result doesn't match exactly:
I want to create an image like this: From an image like this:
UPDATE
Here's what's generated by 255-img
, but the result doesn't match exactly:
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);
It looks like the 3rd plot is the reverse of the 2nd above.
One thing to consider is what you are using for draw image image()
imagesc()
or imshow()
imagesc()
does auto scaling and imshow()
will use a color map.
Another thing to consider is the input image itself. Does it range from 0 - 255, 0 - 1.0 or RGB? Depending on what it is, the reverse would be different.
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.
I had some trouble processing the second image you posted above. Since it's in JPEG format, the image compression seems to have made the lines and text fuzzy, and that complicates thresholding it in the way that you want.
I instead went back to the indexed-color GIF image you posted on the previous related question, converted it to grayscale (using the function IND2GRAY from the Image Processing Toolbox), then converted that to a reversed black and white image to match the format of the first image you posted above. Here's the code I used:
[X,map] = imread('original_chart.gif'); %# Load the indexed color image
img = ind2gray(X,map); %# Convert the image to grayscale
reversedImage = img < max(img(:)); %# Convert to reversed black and white
And here's what reversedImage
looks like: