How to find a sub-image within another image and then diff?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

I recompiled with HDRI and ran my normcrosscorr

time normcrosscorr -s image2s.png image1.png image12_corr.png image12_match.png

Match Coords: (39,91) And Score In Range 0 to 1: (0.0680293)


real 2m2.459s
user 1m39.843s
sys 0m6.228s


So about 2 min using FFT and 11 min using compare.
minglw
Posts: 31
Joined: 2010-02-16T14:32:06-07:00
Authentication code: 8675308

Re: How to find a sub-image within another image and then di

Post by minglw »

Hi Fred!

I configured Cygwin and recompiled IM with "--enabled-hdr=yes".
I also have FFTW setup.

What's the script that I can try? (or the cmd or series of cmds to try to see how fast can hdri improve?)

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

You have to install FFTW before compiling IM.

When I compile IM with HDRI, I just add --enable-hdri to my ./configure file. I don't know what you need to do with Windows or Cygwin.

But to see if you have everything in place, type

convert -version

Version: ImageMagick 6.6.0-0 2010-02-27 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: HDRI

See if it say HDRI.


Also type

convert -list configure


Look for these two lines:

CONFIGURE ./configure '--enable-delegate-build' '--enable-shared' '--disable-static' '--with-modules' '--with-quantum-depth=16' '--with-hdri' '--with-gslib' '--without-wmf' '--disable-silent-rules' '--disable-dependency-tracking' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts/' '--with-lqr'


DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr openexr png tiff x11 xml zlib


If all is fine, then you need to go to my web site (listed below) and get the script called normcrosscorr.

Be sure you reference the filename exactly as it is downloaded, such normcrosscorr.sh,

Or remove the suffix and just call it normcrosscorr.

Put it whereever you want. To run it (at least in unix):

bash /fullpathto/normcrosscorr [arguments] /fullpathto/smallimage /fullpathto/largeimage /fullpathto/outputimage1 /fullpathto/outputimage2

see the examples at http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr

However, run this from my home directory where all my images are stored so I don't need the full paths to the images. I also set my PATH to contain the path to where I store my scripts, so I don't need the fullpath to the script and don't need the "bash", but the latter should not hurt.

Also be sure you change permissions on the script file so that it is executable. And follow the hits on the page from Wolfgang Hugemann

Let me know how it goes.

Fred

P.S. If this does not work, I would recommend backing off from the HDRI, recompile non-hdri, and first test whether you can do your compare operation and the rest of my commands as I presented them with your Cygwin. If that works, then download one of my other simpler scripts, say, autolevel or aspect or anglegradient, and see if it runs OK. If that all works, then try recompiling under HDRI Cygwin and then try my normcrosscorr script.
minglw
Posts: 31
Joined: 2010-02-16T14:32:06-07:00
Authentication code: 8675308

Re: How to find a sub-image within another image and then di

Post by minglw »

I was able to compile ok before, not sure why it's not working now.

It was failing with the error message that it can't find "complex.h".

I did a make clean and then make uninstall to re-start from the beginning.
After running ./configure and then make, it fails on the same error again.

Here's the output:

minglw@minglw /tmp/ImageMagick-6.6.0-0
$ make
make all-am
make[1]: Entering directory `/tmp/ImageMagick-6.6.0-0'
CC magick/magick_libMagickCore_la-accelerate.lo
CC magick/magick_libMagickCore_la-animate.lo
CC magick/magick_libMagickCore_la-annotate.lo
CC magick/magick_libMagickCore_la-artifact.lo
CC magick/magick_libMagickCore_la-attribute.lo
CC magick/magick_libMagickCore_la-blob.lo
CC magick/magick_libMagickCore_la-cache.lo
CC magick/magick_libMagickCore_la-cache-view.lo
CC magick/magick_libMagickCore_la-cipher.lo
CC magick/magick_libMagickCore_la-client.lo
CC magick/magick_libMagickCore_la-coder.lo
CC magick/magick_libMagickCore_la-color.lo
CC magick/magick_libMagickCore_la-colormap.lo
CC magick/magick_libMagickCore_la-colorspace.lo
CC magick/magick_libMagickCore_la-compare.lo
CC magick/magick_libMagickCore_la-composite.lo
CC magick/magick_libMagickCore_la-compress.lo
CC magick/magick_libMagickCore_la-configure.lo
CC magick/magick_libMagickCore_la-constitute.lo
CC magick/magick_libMagickCore_la-decorate.lo
CC magick/magick_libMagickCore_la-delegate.lo
CC magick/magick_libMagickCore_la-deprecate.lo
CC magick/magick_libMagickCore_la-display.lo
CC magick/magick_libMagickCore_la-distort.lo
CC magick/magick_libMagickCore_la-draw.lo
CC magick/magick_libMagickCore_la-effect.lo
CC magick/magick_libMagickCore_la-enhance.lo
CC magick/magick_libMagickCore_la-exception.lo
CC magick/magick_libMagickCore_la-feature.lo
CC magick/magick_libMagickCore_la-fourier.lo
magick/fourier.c:57:21: complex.h: No such file or directory
magick/fourier.c: In function `ForwardFourierTransform':
magick/fourier.c:508: error: invalid operands to binary /
magick/fourier.c:517: error: incompatible type for argument 1 of `cabs'
magick/fourier.c:518: warning: implicit declaration of function `carg'
magick/fourier.c:518: error: incompatible type for argument 1 of `carg'
magick/fourier.c:525: warning: implicit declaration of function `creal'
magick/fourier.c:525: error: incompatible type for argument 1 of `creal'
magick/fourier.c:526: warning: implicit declaration of function `cimag'
magick/fourier.c:526: error: incompatible type for argument 1 of `cimag'
magick/fourier.c: In function `InverseFourier':
magick/fourier.c:980: error: `I' undeclared (first use in this function)
magick/fourier.c:980: error: (Each undeclared identifier is reported only once
magick/fourier.c:980: error: for each function it appears in.)
make[1]: *** [magick/magick_libMagickCore_la-fourier.lo] Error 1
make[1]: Leaving directory `/tmp/ImageMagick-6.6.0-0'
make: *** [all] Error 2

minglw@minglw /tmp/ImageMagick-6.6.0-0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

not sure I can help.

I usually do this when switching between HDRI and non-hdri and vice versa:

./configure ...
make clean
make
sudo make install

If you do a make uninstall, then I think you have to do ./configure again before doing make.

My ./configure looks like this for HDRI, but I have other things.

./configure --enable-delegate-build --enable-shared --disable-static \
--with-modules --with-quantum-depth=16 --enable-hdri --with-gslib --without-wmf \
--disable-silent-rules --disable-dependency-tracking \
--with-gs-font-dir=/usr/local/share/ghostscript/fonts/ --with-lqr


If your problem persists, you will have to check with Magick. Post to bugs forum, if he does not see this message.


Seems like you are missing the complex.h file. Perhaps it got deleted at some point. That is part of the FFT code in IM.

Try

make uninstall
./configure ...
make
sudo make install


P.S. Just wondering if you are using Cygwin, do you need the unix version of FFTW compiled into your Cygwin system?
minglw
Posts: 31
Joined: 2010-02-16T14:32:06-07:00
Authentication code: 8675308

Re: How to find a sub-image within another image and then di

Post by minglw »

Compiling under Cygwin just doesn't work as nice as I thought it is, looks like Unix but just ain't Unix.

I removed the entire Cygwin install and restartted from fresh and I am hitting other issues.
Can't even do a very simple hello world C program compile now.

Previously, I downloaded the source code for FFTW and did the compile and install and it seems to work fine.
And ImageMagick's configure script was able to find that FFTW is setup properly and complete.
It only fails on the error I mentioned in my earlier post regarding can't find complex.h.

I hope whoever is compiling and releasing the Windows version of ImageMagick can also provide a HDRI version.

When I find a machine to put Linux on, I will try it again.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to find a sub-image within another image and then di

Post by snibgo »

Not that I can help, but:

1. If you ./configure more than once, you should probably "make distclean" first.

2. I made the decision a month ago to setup dual-boot Windows7/Ubuntu on my laptop, rather than hacking with Cygwin. It was worth doing.
snibgo's IM pages: im.snibgo.com
minglw
Posts: 31
Joined: 2010-02-16T14:32:06-07:00
Authentication code: 8675308

Re: How to find a sub-image within another image and then di

Post by minglw »

I've tried "make clean" and "make distclean" before re-running ./configure already. it still ends up with the same fail.

I agree, I think it's better to install a *nix setup versus messing with Cygwin.

The machine I have is a company machine, I don't want to mess up with the dual boot. I will give it a try with my machine at home.

It seems convincing from the stats that Fred has shown that HDRI can help speed things up with FFT.

I guess the logically question to ask is: why isn't IM always compiled with HDRI enabled (as the default for the distribution) ?

Is it because it's new and not well tested ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to find a sub-image within another image and then di

Post by magick »

HDRI consumes twice as much memory as the standard Q16 release of ImageMagick and can give unexpected results to the general user (pixels values can go negative or exceed the quantum range). Therefore, we leave HDRI as an option for image professionals.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

As of IM 6.6.0-9, FFT in ImageMagick should work properly for Windows users. An change was made to correct for a missing complex.h library under Windows.

NOTE that one has to install the FFTW delegate first, then recompile IM from source so that it recognizes FFTW.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

Instructions for Windows Users: see viewtopic.php?f=4&t=14251#p56836
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to find a sub-image within another image and then di

Post by fmw42 »

user el_supremo has recently been able to get Windows compiled with FFTW, HDRI and Cygwin and confirms that my normcrosscor script functions successfully in Windows
Post Reply