Help me please with color image processing

1 view (last 30 days)
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.

Answers (1)

Image Analyst
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
Andrew Tim
Andrew Tim on 8 Apr 2015
Thank you very much. But to write my function I described earlier (function that recieves coordinates of rectangle area (box) in the image, and after this returns an image called in your terms "matching colors (Delta E<=30)") I need to analize whole code of this big Delta E app. And it's too difficult for me now :( (I started to learn Matlab only 2 weeks ago:)). Could you please help me? I dont need any GUIs and any other extra functional. Or if its difficult to rewrite it for me then could you point me when the main body of Delta E function begins in your file that can help me to write my function (skipping all other tasks like GUI etc)? And thank you very much for your time again.
Image Analyst
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.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!