"Spot the difference" game code

hi i need a code which 1. detect 2 similar image and crop them out(example from browser) 2. detect the differences between 2 images 3. show the differences, count and label them(example difference no.1,difference no.2)
basically the code is like a cheat to the "spot the differences" game and tell u how many and where are the differences. Appreciate if some1 could help me on the code. Thanks in advance.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 18 Apr. 2013

1 Stimme

Try to just subtract them:
differenceImage = single(image1) - single(image2);
imshow(differenceImage, []);
Then you can threshold and blacken the differences, or make them red, or outline them, or whatever you want to do.

8 Kommentare

abu
abu am 19 Apr. 2013
But how do I recognise 2 similar picture in my browser and crop them out?
Image Analyst
Image Analyst am 19 Apr. 2013
If they're similar, the difference image will show few pixels with large values, if any. If they're 100% similar, the max value of the difference image will be zero. I don't know what you want to crop out in that case. You're welcome to upload your pair of images somewhere if you want.
You "Answer" below should have been a comment here. Since you didn't upload the pair of images, I can't do much easily other than to direct you what to do. First of all, you need to extract the color planes:
% Extract the individual red, green, and blue color channels.
redChannel1 = rgbImage1(:, :, 1);
greenChannel1 = rgbImage1(:, :, 2);
blueChannel1 = rgbImage1(:, :, 3);
redChannel2 = rgbImage2(:, :, 1);
greenChannel2 = rgbImage2(:, :, 2);
blueChannel2 = rgbImage2(:, :, 3);
% Make difference images for each color channel
redDifferenceImage = single(redChannel1) - single(redChannel2);
greenDifferenceImage = single(greenChannel1) - single(greenChannel2);
blueDifferenceImage = single(blueChannel1) - single(blueChannel2);
Next you need to make a function called FindDifferences(differenceImage). In that function you need to pass the difference image for each color channel in turn. And inside you need to take the absolute value and threshold. Then if you want the "outline" a little larger than the difference region you need to call imdilate. Then pass it back
function detectedDifferences = FindDifferences(differenceImage)
binaryImage = abs(differenceImage) > 2; % or whatever.
detectedDifferences = imdilate(binaryImage, true(15));
Now you need to call that for each color channel:
detectedDifferencesR = FindDifferences(redDifferenceImage);
detectedDifferencesG = FindDifferences(greenDifferenceImage);
detectedDifferencesB = FindDifferences(blueDifferenceImage);
Now combine
detectedDifferences = detectedDifferencesR | detectedDifferencesG | detectedDifferencesB;
Now call bwboundaries
boundaries = bwboundaries(detectedDifferences)
Then plot them over the image:
hold on;
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 3);
end
That's just off the top of my head and untested so there may be some slight errors, but that's the basic process. It's pretty intuitive and obvious, and may be what you had already thought about. Hope that helps.
Image Analyst
Image Analyst am 21 Apr. 2013
abu, what's the status? Did my suggestions work?
abu
abu am 21 Apr. 2013
Read the answer below...thx....
abu
abu am 21 Apr. 2013
I mean I write my problem as answer slow below and not commenting here...sorry
Image Analyst
Image Analyst am 21 Apr. 2013
Yes, I saw that, but what I want to know is if my code snippets above helped you. Did you actually try them? Or not? It sounds like not. If not, then why not?
abu
abu am 22 Apr. 2013
Yes, that pretty much solved the comparing difference part. My problem noow would be how to crop the 2 image from browser in order to compare them

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

abu
abu am 20 Apr. 2013

0 Stimmen

http://imageshack.us/photo/my-images/14/examplesk.png/ this is the example i need to crop. i need the 2 similar picture. thx a lot.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by