December 14, 2012

Using ImageJ in Your Own Application



One of the coolest things I've gotten to do at my current job is image analysis and feature extraction.  The goal of one of our projects was to isolate single fly embryos from images taken from labs.  Doing it is pretty simple and requires very little advanced mathematics, but to do it well, it takes some advanced pixel manipulation.

The Requirements
The Solution
An Example

  1. Make the image grayscaled.
  1. Apply a threshold on it to only get the dark areas. This assumes the lines will always be near black.
  1. Apply a Particle Analyzer to find Ellipses on the image.
  1. Loop through the "Particles" to find ones that fit our criteria.
  1. Get the angle from our Particle.

The major requirement was that the application be available on Mac, Linux, or PC; thus, we chose Java as our language.  Likewise, all components of the application needed to be in Java. 

Before I had arrived to the group, someone had already rewritten some MATLAB code that was able to extract embryo images from laboratory photos; and so the first step was that the Java code be able to reproduce the results from the MATLAB code.  Originally, we had investigated the possibility of simply using the MATLAB code and distributing that, but not every one has MATLAB (especially with its price tag).  We then found out about a MATLAB to Java compiler that did little more than just wrap the MATLAB code in a class; in fact, you still needed to have the MATLAB environment running, and on top of that, you needed to recompile the Java code for all platforms you wanted to distribute the application on.  It was a horrible mess, so we quickly dismissed MATLAB as the means of distributing the code, and thus, it was agreed that all MATLAB code would need to be rewritten in Java.

With all this in mind, we decided to go with ImageJ.  ImageJ is a Java application that focuses on image analysis and processing.  Since it was already written in Java, we didn't need to write very much on our own.  All we needed to do was download the application, read the license, and use the ij.jar file in our application.  The documentation is pretty good online for the library as well.

http://stackoverflow.com/q/11461910/759316

The question was asked "How do I get the angle of these black bars?"
120 degrees image


In the link above, you can see the actual code and solution to this question that works the following way:


How the code works:
  1. Make the image grayscaled.
  2. Apply a threshold on it to only get the dark areas. This assumes the lines will always be near black.
  3. Apply a Particle Analyzer to find Ellipses on the image.
  4. Loop through the "Particles" to find ones that fit our criteria.
  5. Get the angle from our Particle.


0 comments:

Post a Comment