Re: Compare images in Cocoa
Re: Compare images in Cocoa
- Subject: Re: Compare images in Cocoa
- From: Nicko van Someren <email@hidden>
- Date: Fri, 31 Oct 2008 15:35:40 +0000
On 31 Oct 2008, at 03:21, Pierce Freeman wrote:
Hi everyone. I am wondering if there is some way to compare two
images in
Cocoa, and then somehow spit out a percent of how similar they are.
The only
way I could think of is comparing every pixel, but this seems like
it would
take a long time, and even so I have no idea how to go about doing
that.
This very much depends on the type of differences you are expecting.
The first thing to note is that you can't do this without accessing
every pixel in both images, but there are library functions for
applying functions to 2-d arrays of pixels in CoreImage and deeper
down in the veclib and vImage frameworks. If you are just expecting
the images to be largely the same but some pixels to be different then
simply using CoreImage to produce a bitmap based on the pixel
differences is pretty easy and very fast.
If you expect images to be the same scale but differ in (a) some
pixels' values, (b) brightness and/or contrast or (c) parts of the
image are translated, then in general the first thing to do apply a
convolution function with the two images as inputs. The mathematics
are sticky but OS X includes library functions to do it for you. Try
looking on Google for terms like image convolution, motion detection,
motion compensation, etc. Basically you'll get an output from the
convolution where the strength of the spike in the middle of the
output represents how similar the parts of the image that have not
moved are to each other. Where parts of the image have been
translated from one image to the other you will get an output spike
offset from the centre by the movement vector, the size of spike
representing the size of the area that moved.
If you expect that between your two images some parts will be scaled
as well as translated then the whole problem gets much more complex,
so you might want to avoid these cases :-)
Cheers,
Nicko
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden