Template Matching and Slice Alignment--- ImageJ Plugins

You can download this plugin here.
And the java source code: cvMatch_Template.java and Align slices.java
You will also need OpenCV shared library( 32-bit windows, 64-bit windows or 64-bit Mac ) , javacv and JNA library. 
Please see Installation for more details. 
Sample images are here

Description

This ImageJ plugin contains two functions. The first one is the cvMatch_Template. It implements the template matching function from the OpenCV library. The java interface of OpenCV was done through the javacv and JNA(java nativce access). It is quite similar as the existing template matching plugin but runs much faster and users could choose among six matching methods:

1.Squared difference

2.Normalized squared difference

3.Cross correlation

4.Normalized cross correlation

5.Correlation coefficient

6.Normalized correlation coefficient

The detailed algorithms could be found here.

The cvMatch_Template will search an specific object (image pattern) over an image of interest by the user specified method.


   
 
 template  best match
 multi-match


The second function Align_slices in stack utilized the previous matching function to do slice registration(alignment) based on a selected landmark. This function will try to find the landmark or the most similar image pattern in every slice and translate each slice so that the landmark pattern will be the same position through out the whole stack. It could be used to fix the drift of a time-lapse image stacks, as shown in the following example:

#New feature: subpixel registration, updated 2011/5/13. Please see here for details.

 
 
 
 before alignment
 after alignment
alignment with subpixel registration
Microtubule growth under TIRF microscope. Image courtesy of Didier PORTRAN.
(Physics of the Cytoskeleton and Morphogenesis, iRTSV/CEA, France)

System Requirement

ImageJ 1.44 or later, running on Java 1.6

I have only tested on the following systems. 
  • 64-bit ImageJ on Mac OS 10.5 and 10.6
            or
  • 32-bit ImageJ on windows XP
For other system architectures, you need to install the OpenCV to get the shared libraries corresponding to your system.

Installation

This plugin requires the OpenCV, javacv, and JNA (java native access) library. Javacv and JNA are provided as jar archives. We just need to put them along with the Template_Matching.jar into ImageJ plugins folder. For the OpenCV, you have two choices. Either you do a full installation of opencv on your machine (please see instructions here), or you can just download the pre-compiled library files.

Detailed steps:

(If you choose to full install OpenCV, only step one is required)

    0. Close ImageJ
    1. Download Template_Matching.jar , javacv.jar and jna.jar and put them into your ImageJ plugins folder (ex: C:\Program Files\ImageJ\plugins).
    2. Download the opencv library files according to your system. Library for 32-bit ImageJ on windowsLibrary for 64-bit windows / Library for 64-bit ImageJ on Mac
    3. Extract the library files. 

For Windows
    4a. Put the library files (libcxcore200.dll, libcv200.dll, Download as zip archive or cv100.dll cxcore100.dll for the 64-bit window system.Download as zip archive) into your ImageJ folder (ex: C:\Program Files\ImageJ)
(Note: Putting them in ImageJ\plugins and use "set path" doesn't work . Modified 2011/2/18)


For Mac
    4b. Put the library files (libcxcore.2.1.0.dylib, libcxcore.2.1.dylib, libcxcore.dylib, libcv.2.1.0.dylib, libcv.2.1.dylib, libcv.dylib, Download as zip archive) into /usr/lib
        ( Finder>Go>Go to folder...; or cmd+shift+G. In the dialog, type /usr/lib. Click "go". Then copy the library files into it. You will need administrator privilege to put files into /usr/lib)


    
   
    5. Restart ImageJ. 
    

After installing the Template Matching plugin, you can find "cvMatch_Template..." and "Align slices in stack" functions appeared in the Template Matching subfolder within the ImageJ plugin folder.

Tutorials

Tutorial for cvMatch_Template

Tutorial for Align slices in stack

Updates

# 2012/2/29: Added the pre-compiled opencv library file for the 64-bit window system.  (Thanks Yevhen Katrukha for providing the library files)

# 2011/5/30: Fixed the memory leak issue caused by the OpenCV interface.

# 2011/5/13: Boundary area for searching landmark.

# 2011/5/13: Subpixel registration.

Troubleshooting

#Q: I got a error message right after launching the plugin saying "java.lang.UnsupportedClassVersionError: Bad version number in .class file.............".
  A:
It occurs when the Java version used for ImageJ (Java 1.5.xxx for ImageJ-32bit in MacOS X, Java 1.6.xxx for ImageJ-64bit in MacOS X and all the window-versions)  is not compatible with the Java version used for compiling this plugin (Java 1.6.xxxx). To avoid this use the 64-bit ImageJ in Mac.

#Q: The plugin launched correctly, but after entering the parameters in the dialog window or after selecting the ROI, I got a error message saying "Plugin or class not found:"Align_slices"
(java.lang.NoClassDefFoundError: name/audet/samuel/javacv/jna/cxcore$
". 
  A:
It happens because ImageJ failed to find the javacv and jna interface. You probably forgot to put the  javacv.jar and jna.jar along with the Template_Matching.jar  into ImageJ's plugins folder. Please follow the steps written in the Installation part.

#Q: The plugin launched correctly, but after entering the parameters in the dialog window or after selecting the ROI, I got a error message saying "java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': ...................
  A:
It happens because the system failed to load the opencv library. You probably forgot to download and put the library files (32-bit on windows or 64-bit on Mac) into correct place (ex: C:\Program Files\ImageJ or /usr/lib). Please follow the steps written in the Installation part.

Publications

1. Tseng, Q. et al. A new micropatterning method of soft substrates reveals that different tumorigenic signals can promote or reduce cell contraction levels. Lab on a Chip 11, 2231 (2011).

2. Tseng, Q. et al. Spatial Organization of the Extracellular Matrix Regulates Cell–cell Junction Positioning. PNAS (2012).doi:10.1073/pnas.1106377109

3. Tseng, Qingzong. 2011. “Study of multicellular architecture with controlled microenvironment”. Ph.D. dissertation, Université de Grenoble. http://tel.archives-ouvertes.fr/tel-00622264.

Contact

Any question or comment, please contact Qingzong TSENG (qztseng at gmail.com).