viplav4u1ly has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am kumar viplav, currently trying to do some automation using perl. I have a problem like i have two images in .bmp format. one sample image and another one is reference image. reference image has been cut from the sample image only and i need to find how many times this reference image is present in the sample image. i know i can use compare() function of magickimage module. Please suggesst me the solution.

Replies are listed 'Best First'.
Re: Image processing in perl
by marto (Cardinal) on Feb 01, 2011 at 20:07 UTC

    Let me see if I understand you correctly. You have a source image e.g.

    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    along with a sample image:

    * * * *

    And your goal is to discover how many occurrences of the sample image can be found in the source image? If so I don't think that's what ImageMagicks compare is for. If this isn't what you are trying to do please clarify.

      You might be wrong about ImageMagick. See the last example with -subimage-search at http://www.imagemagick.org/script/compare.php. The similarity image seems to be what he wants, even though the gif file isn't exactly the data structure a perl programmer wants

        You may be right, I'm no ImageMagick expert. OP seems to want a count of the occurances of subimage in the source image. The output from compare with it's -subimage-search method is the best match ofset and another image, which presents OP with another problem as this only seems to work for the first match. Also, I don't think it's output is limited to gif files, that could just be an example. I think the solutions offered by others, Image::Match with it's match method and possibly Imager::Search are more along the lines of what OP requires.

      Hi marto, You got my point, what i want from perlmagick module.If i can't do it by compare function then please suggest me how can i do it?
Re: Image processing in perl
by davido (Cardinal) on Feb 02, 2011 at 02:21 UTC

    Image::Match seems to do what you are asking for, though you would probably need to first convert your bmp's to gif format.


    Dave

      As an alternative, Imager::Search, which uses Imager. I've not tried either module, so I don't know which is better...

      Hi , i am not able to install Image::Match in my system due to some dependencies. like only makefile.pl is present no intaller is present for active perl. Please help me out in installetion process."
      Hi, thanks for the suggestion. I installed the Image::Match package. As i told, i have two images, sample image and reference image. there are total 30 occurance of reference image in sample image, but theprogram is giving only one occurence. like "found at 3:424" coordinate.it should give the output for all 30 (x,y) coordinate. the program is given bellow:
      use Image::Match; $sample = Prima::Image-> load('im1.gif') or die "Can't load: $@"; $reference = Prima::Image-> load('im2.gif') or die "Can't load: $@"; # find again $OPTIONS{multiple} = 1 ; my ( $x, $y) = $sample-> match( $reference); $OPTIONS{overlap} = all ; print defined($x) ? "found at $x:$y\n" : "not found\n"; print "$x $y";
      I am not able to find theway to do the same. Please anyone suggest me how to get the desired output.

        You should use strict;. Had you done so you would realize that %OPTIONS doesn't exist, which is a clue that your expectation that $OPTIONS{multiple} = 1; is doing something is wrong.

        The POD for that module is simply awful. However, I think if you alter your match() call as follows, you'll have better luck:

        my( @matches ) = $sample->match($reference, {multiple => 1});

        You should find @matches to now be populated with an array of arrays representing the XY coordinates of each match.

        Whoever wrote that POD should be shot though (with a water pistol, of course). I would have to read the module's actual code to be sure that my suggestion even fits.


        Dave