"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.

 채택된 답변

Image Analyst
Image Analyst 2013년 4월 18일

1 개 추천

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

abu
abu 2013년 4월 19일
But how do I recognise 2 similar picture in my browser and crop them out?
Image Analyst
Image Analyst 2013년 4월 19일
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 2013년 4월 21일
abu, what's the status? Did my suggestions work?
abu
abu 2013년 4월 21일
Read the answer below...thx....
abu
abu 2013년 4월 21일
I mean I write my problem as answer slow below and not commenting here...sorry
Image Analyst
Image Analyst 2013년 4월 21일
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 2013년 4월 22일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

abu
abu 2013년 4월 20일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

abu
2013년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by