How do I change specific locations in an image to black?

1 view (last 30 days)
My code is supposed to find the differences between two images and create a new image that indicates all these differences in black. Currently I have
%image1 and image2 are the two images to compare
%creates a mask of the differences imgMatrix1 and imgMatrix2 are the n by m by 3 rgb matrices
equalityTest=imgMatrix1==imgMatrix2;
%starts with a black image
newImageMap=uint8(zeros(a,b,c));
%turns all the identical spaces white
newImageMap(equalityTest)=255;
imwrite(newImageMap,newFileName);
end
Why is this code returning an image that has color in the correct spots but the color is cyan and not black?

Answers (1)

Image Analyst
Image Analyst on 15 Nov 2013
You did it wrong. You should start with the original image and set all differences to black:
% Starts with original image
newImageMap = imgMatrix1; % or imgMatrix2 - it doesn't matter.
% Turns all the different pixels black.
newImageMap(equalityTest) = 0;
% Pixels with non-black color match perfectly in all color channels.
% This will probably happen in computer graphics only, not camera images.
  2 Comments
Bob
Bob on 15 Nov 2013
Edited: Bob on 15 Nov 2013
The pattern is coming out cyan instead of black. I'm using newImageMap(~equalityMap)=0; because the map is true for pixels that are equal. How can I get Matlab to zero all the layers?
Edit: So the differences in the test case I'm running with only affects the red value in the pixels which are different. How do I get the green and blue to change along with the red?
Image Analyst
Image Analyst on 15 Nov 2013
Bob, see the full blown demo (test2.m) I wrote for you below in blue. If it does what you expect, then can you mark the answer as Accepted?

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!