How do I change specific locations in an image to black?
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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
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?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!