in reply to Can i Compare two images in perl ?
As an example of what can be achieved without "image processing".
This simple script compares two images and produces a single xx.xxx% similarity figure:
#! perl -slw use strict; use GD; GD::Image->trueColor( 1 ); my $im1 = GD::Image->new( $ARGV[ 0 ] ); my $im2 = GD::Image->new( $ARGV[ 1 ] ); my $raw1 = $im1->gd; my $raw2 = $im2->gd; my $xored = $raw1 ^ $raw2; my( $all, $diff ) = (0)x2; $all += 255, $diff += ord substr $xored, $_, 1 for 0 .. length( $xored + ) - 1; print $all, ' ', $diff; printf "The simlarity is %.3f%%\n", ( $all - $diff ) / $all * 100;
And here are the results of applying that to my previous 'problem' examples.
C:\test\xx>..\907337 ballons1.jpg ballons2.jpg 672410265 62443267 The simlarity is 90.714%
C:\test\xx>..\907337 ballons1.jpg ballons1a.jpg 672410265 92011553 The simlarity is 86.316%
C:\test\xx>..\907337 1.png 2.png 244802805 241803 The simlarity is 99.901%
C:\test\xx>..\907337 microarray1.jpg microarray2.jpg 340764405 41409302 The simlarity is 87.848%
In this example, the second microarray is just a mirror image of the first for test purposes as I couldn't find two similarly size examples. The reflection means that the registration is probably not as good as you'd expect from a true comparison, but it serves its purpose to highlight the possibilities and downsides of the technique.
The technique could be much improved with good examples and a clearer statement of requirements.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can i Compare two images in perl ?
by deep3101 (Acolyte) on Jun 01, 2011 at 02:27 UTC | |
by BrowserUk (Patriarch) on Jun 02, 2011 at 04:04 UTC | |
by deep3101 (Acolyte) on Jun 02, 2011 at 04:19 UTC | |
by BrowserUk (Patriarch) on Jun 03, 2011 at 05:41 UTC |