Help me please with color image processing
2 views (last 30 days)
Show older comments
Hello, I have two images. Img1 and Img2. All I want is to write function in MATLAB that brings each pixel from one image and compares it to each pixels of another, and then the pixels are equal then it write white color pixel on the second image. Could you please help me to write this function? Thank you.
0 Comments
Answers (1)
Image Analyst
on 3 Apr 2015
Try this:
r1 = Img1(:,:,1);
g1 = Img1(:,:,2);
b1 = Img1(:,:,3);
r2 = Img2(:,:,1);
g2 = Img2(:,:,2);
b2 = Img2(:,:,3);
% Find pixels where each color matches.
matchingPixels = (r1 == r2) & (g1 == g2) & (b1 == b2);
imshow(matchingPixels);
% Make those pixels white in the second image's color channels:
r2(matchingPixels) = 255;
g2(matchingPixels) = 255;
b2(matchingPixels) = 255;
% Concatenate to make a full color image again
Img2 = cat(3, r2, g2, b2);
imshow(Img2);
13 Comments
Image Analyst
on 8 Apr 2015
To get rid of GUI things, just comment out any line of code that calls title(), imshow(), plot(), bar(), xlabel(), ylabel(), xlim(), ylim(), and functions like that. Once those are gone, just step through the code and if any line of code displays anything, just delete that line.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!