views:

45

answers:

1

Or is there a built-in function that can do exactly this job?

+4  A: 

No, there is no built-in function that I know of. There might conceivably be something, but why would they bother to write something so basic? Why do I say it is basic? Suppose you did a direct comparison between the two images?

IM1 == IM2

A color image is an MxNx3 array, typically composed of uint8 values. So that test will result in a MxNx3 boolean array. If all three channels of the two were identical for any specific pixel, then that pixel is the same. Thus is we apply all to the third dimension of the result above...

all(im1 == im2,3)

This will be an MxN array. Now, how many of the pixels were identical? Since all returns a boolean result, the overall sum of that result will count the pixels that were identical. A simple way to form the overall sum of a 2-d array is to form the sum of the sum.

sum(sum(all(im1 == im2,3)))

Now, you can compare that number to 30% of the total number of pixels in the image. I'll let you figure out how to do that part.

Get used to building a solution in MATLAB using basic, vectorized building blocks.

woodchips