Showing posts with label ImageJ. Show all posts
Showing posts with label ImageJ. Show all posts

Sunday 15 June 2014

Writing ImageJ Plugins

These instructions for getting started writing plugins for ImageJ2 were developed at the Fiji / ImageJ2 Hackathon in Dresden, Germany, December 2011, using the Eclipse IDE version 3.7 and Sun JDK 1.6 on Ubuntu 11.04. It assumes that you have a working installation of ImageJ2, from http://developer.imagej.net/downloads.

Configure your environment

  1. Install JDK 6, needed for the javac compiler, using your system install mechanism or by downloading from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  2. Install Eclipse IDE version 3.7 for Java developers from http://eclipse.org/downloads/, using the appropriate download for your system.
  3. Download imagej-2.0.0-SNAPSHOT-all.jar from http://developer.imagej.net/downloads and save it somewhere handy; I have mine in a directory called JavaLibs.
  4. Run Eclipse and tell it to use JDK 6 as the default JRE for new projects (Window > Preferences > Installed JREs > Add... > Standard VM > Navigate to your JDK install directory
  5. Right click in the Package Explorer > New... > Java Project
  6. Give your project a name, e.g. IJ2-plugins, hit Next
  7. Under the Libraries tab Add External Jars... and navigate to the imagej-2.0.0-SNAPSHOT-all.jar you downloaded in step 3. This gives you access to the IJ2 application programming interface (API). At the time of writing, to get context Javadoc for ImgLib classes you also have to specify the URL of its Javadoc. Click on the triangle to the left of imagej-2.0.0-SNAPSHOT-all.jar, select "Javadoc location:", hit Edit, add the URL:
    http://jenkins.imagej.net/job/ImgLib-daily/javadoc/
    Hit Validate and if everything is OK, hit OK.
  8. Configure Ant to do your build using the javac compiler
    1. Copy this code and paste it into your project in a file called build.xml
      <project name="Plugins for ImageJ2" default="" basedir=".">
      <description>
      ImageJ2 build file
      </description>
      <property name="src" location="src" />
      <property name="build" location="javacbin" />
      <property name="imagej2Plugins" location="/home/mdoube/imagejdev/plugins/" />
      <property name="user.name" value="Michael Doube" />
      <path id="plugin-classpath">
      <fileset dir="/home/mdoube/JavaLibs/">
      <include name="imagej-2.0-SNAPSHOT-all.jar" />
      </fileset>
      <pathelement path="${build.dir}" />
      </path>
      <target name="init">
      <!-- Create the time stamp -->
      <tstamp />
      <!-- Create the build directory structure used by compile -->
      <mkdir dir="${build}" />
      </target>
      <target name="compile" depends="" description="compile the source ">
      <!-- Compile the java code from ${src} into ${build} -->
      <javac includeantruntime="false" srcdir="${src}" destdir="${build}">
      <classpath refid="plugin-classpath"/>
      </javac>
      <echo>
      Building the .jar file.
      </echo>
      </target>
      <target name="compress" depends="" description="generate the distribution">
      <jar jarfile="IJ2Plugins.jar">
      <fileset dir="${build}" includes="**/*.*" />
      <manifest>
      <attribute name="Built-By" value="${user.name}" />
      </manifest>
      </jar>
      <copy file="IJ2Plugins.jar" toDir="${imagej2Plugins}" />
      </target>
      <target name="clean" description="clean up">
      <!-- Delete the ${build} and ${dist} directory trees -->
      <delete dir="${build}" />
      </target>
      </project>
    2. double-click on build.xml and edit it so that the fileset dir="" field contains the ij-app jar and the ImageJ2Plugins location is set to your local ImageJ plugins directory
    3. you can also edit the name of the jar that's generated
    4. now right-click on your project in the Package Explorer > Properties > Builders > New > select Ant Builder > Enter a name for your builder
    5. Main tab, under Buildfile: hit Browse Workspace and locate the build.xml you just made, hit OK
    6. Targets tab, After a “Clean”: Set targets, check init, compile, compress, clean
    7. Targets tab, Auto Build: Set targets, check init, compile, compress, clean

Hello World

Writing your first plugin: HelloWorld

  1. Right-click on the src directory of your new project and New > Class
  2. Give your class a name; e.g., HelloWorld (the convention for classes is to be capitalised like that)
  3. Eclipse initialises a new file and puts a little code into it for you.
    1. Edit the first line so it reads: public class HelloWorld implements RunnablePlugin {
    2. Note the squiggly red line under RunnablePlugin indicating a compile error, move your cursor to it and hit Ctrl+1
    3. Eclipse gives you a bunch of autocorrect options, select the top one, Import 'RunnablePlugin' (imagej.ext.plugin) and hit Enter. Eclipse adds a line of code for you at the top of the file: import imagej.ext.plugin.RunnablePlugin;
    4. Now HelloWorld gets a squiggly line, so Ctrl+1 again and select Add Unimplemented Methods. Eclipse adds a bunch of code, which is the run() method needed because we are implementing the RunnablePlugin interface.
    5. We want HelloWorld to show up in the ImageJ menus, so add an annotation above the public class line: @Plugin(menuPath = "Plugins>Hello World")
    6. Ctrl+1 again on the @Plugin squiggly line to autocorrect the missing import.
    7. You can Ctrl+Space and Eclipse will suggest options for autocompletion.
  4. Let's check ImageJ and see if our plugin is available in the menus.
    1. Run ImageJ
    2. You should now see in ImageJ's Plugins menu an item called Hello World
    3. But it doesn't do anything yet because we haven't added any useful code
  5. Add code to your HelloWorld until it matches HelloWorld.java below, using Ctrl+1 and Ctrl+Space to investigate possibilities in the API
    1. Each time you update your code, Ant rebuilds your jar and copies it to your plugins directory
    2. At the moment, you have to restart ImageJ to test your changes

HelloWorld.java

import imagej.ext.plugin.Parameter;
import imagej.ext.plugin.Plugin;
import imagej.ext.plugin.RunnablePlugin;
import imagej.ui.UIService;

@Plugin(menuPath = "Plugins>Hello World")
public class HelloWorld implements RunnablePlugin {
@Parameter
private UIService uiService;

@Override
public void run() {
uiService.showDialog("Hello world.");
}
}

Wednesday 21 May 2014

Version 1.49a 15 May 2014

Version 1.49a  (upgrade)

  • Thanks to Kenneth Sloan, added a "Paint on overlay" option to the built in brush tool's options dialog. Add the built in brush tool to the toolbar by selecting "Brush" from the toolbar's ">>" menu.
  • Thanks to Daniel Pensold, Analyze>Tools>Save XY Coordinatessaves the coordinates and values of pixels inside selections to a .csv file.
  • Thanks to Volker Wirth, added a "Title:" field to the dialog displayed by Edit>Selection>Straighten when the line width is one or when processing a stack.
  • Selections created by the selection brush tool are deleted after they are added to an overlay.
  • Thanks to Jon Harman, Plugins>Install recognizes .zip files.
  • Thanks to Jerome Mutterer, added the makeArrow() macro function (example).
  • Thanks to Federico Luzzati, added the Stack.toggleChannel() macro function (example).
  • Thanks to Norbert Vischer, the showProgress(progress) macro function displays subordinate progress bars as moving dots when 'progress' is negative (macro example, script example).
  • Thanks to Messaoudi Cedric, Edit>Options>Memory & Threadsno longer limits the number of threads to 32.
  • Thanks to Wilhelm Burger, added the IJ.setProperty(String,Object) and IJ.getProperty(String) methods, which are useful for passing data between plugins.
  • Thanks to Stephan Preibisch, added the MultiLineLabel#setText() method (example).
  • Fixed a bug that caused the recording mode to not be saved when quitting ImageJ with the Recorder open.
  • Thanks to Mats Nilsson, fixed a bug that caused the getInfo() macro function and ImagePlus#getStringProperty() method to not work with DICOM tags containing letters.
  • Thanks to Norbert Vischer, fixed a bug the caused the Array.findMaxima() macro function to throw an exception when the array length was one.
  • Fixed a bug that caused images with overlays containing black transparent images to not be correctly saved and restored.
  • Thanks to Jan Brocher, fixed a v1.48 regression that caused changes made in the Image>Overlay>Add to Overlay dialog (displayed when you press alt+b) to not be remembered.
  • Thanks to Kees Straatman, fixed a bug that caused the recorder to incorrectly record the Process>Binary>Convert to Mask command.
  • Thanks to Chris Weisiger, fixed a bug in Image>Stacks>Othogonal Viewsthat caused it to fail with extened StackWindows with custom controls.
  • Thanks to Philippe Carl, fixed a v1.48t regression that caused the Plot#drawNormalizedLine() method to not work with log plots.

 

Thursday 8 May 2014

ImageJ2


ImageJ2 is a new version of ImageJ seeking to strengthen both the software and its community. Internally, it is a total redesign of ImageJ, but it is backwards compatible with ImageJ 1.x via a "legacy layer" and features a user interface closely modeled after the original.

Under the hood, ImageJ2 completely isolates the image processing logic from the graphical user interface (UI), allowing ImageJ2 commands to be used in many contexts, including headless in the cloud or on a server such as OMERO, or from within another application such as KNIME, Icy or CellProfiler (a Python application).

ImageJ2 has an N-dimensional data model driven by the powerful ImgLib2 library, which supports image data expressed in an extensible set of numeric and non-numeric types, and accessed from an extensible set of data sources. ImageJ2 is driven by a state-of-the-art, collaborative development process, including version control, unit testing, automated builds via a continuous integration system, a bug tracker and more.

We are collaborating closely with related projects including Fiji, SCIFIO and OME, and are striving to deliver a coherent software stack reusable throughout the life sciences community and beyond. For more details, see the SciJava web site.

ImageJ2 is currently in the "beta" stage, meaning the code is not finished. It is being released for early community feedback and testing. Comments, questions and bug reports are much appreciated!

To maintain ImageJ's continuity of development, we have modeled the application after ImageJ v1.x as much as is reasonable. However, please be aware that ImageJ2 is essentially a total rewrite of ImageJ from the ground up. It provides backward compatibility with older versions of ImageJ by bundling the latest v1.x code and translating between "legacy" and "modern" image structures.

For more details on the project, see the ImageJ2 web site.

LICENSING

ImageJ2 is distributed under a Simplified BSD License; for the full text of the license, see LICENSE.txt.
For the list of developers and contributors, see pom.xml.

IMAGEJ AS A LIBRARY

This repository is the master ImageJ2 application, which brings together all of ImageJ under the artifact net.imagej:imagej. It is the easiest entry point if you are looking to use ImageJ as a library from your own software. E.g., in your Maven pom.xml:

<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>2.0</version>
</parent>
...
<dependency>
<groupId>net.imagej</groupId>
<artifactId>imagej</artifactId>
</dependency>
We recommend inheriting from the pom-scijava parent, although it is not required. (If you do not, you will need to include the <version> of ImageJ in your <dependency> declaration.)

DEPENDENCIES

This component depends on other, lower level components, each of which lives in its own repository:
It also includes uses various "plugin" components at runtime:
See the pom.xml for a complete list of dependencies.

BUGS

For a list of known issues, see the issue tracking system.
Please report any bugs by following the instructions online.

Wednesday 7 May 2014

Version 1.48v 19 April 2014 (upgrade)

  •  Plot and Histogram windows are no longer centered on the screen.
  • Added the Overlay.clear and setOption("Add to overlay",boolean) macro functions.
  • Thanks to David Knecht, commands listed in the Plugins>Shortcuts>List Shortcuts and Plugins>Shortcuts>Create Shortcutdialogs are sorted with case ignored.
  • Thanks to Denis Roussel, changed an incorrect Javadoc reference in PlugInFilter.java from SUPPORTS_STACKS to DOES_STACKS.
  • Thanks to Johannes Schindelin, added @link tags to the PlugInFilter.java Javadocs.
  • Fixed a bug that caused the progress bar to not terminate after dragging a jar file to the "ImageJ" window.
  • Fixed a bug that caused the roiManager("add") macro function to unexpectedly set the stack position of the source selection. 

Intro to ImageJ

ImageJ is free public domain image processing software developed at the National Institutes of Health. Its power and flexibility allow it to be used as a research tool by scientists in many disciplines, from medicine to astronomy. Installers are available for Windows, MacOS and OSX, and Linux.
You can use ImageJ to display, annotate, edit, calibrate, measure, analyze, process, print, and save raster (row and column) image data. It reads most common raster image formats as well as raw data files in text format, such as from spreadsheets. ImageJ also supports stacks - multiple images in a single window - for animation and analysis.

ImageJ is a public domain Java image processing program inspired by NIH Image for the Macintosh. It runs, either as an online applet or as a downloadable application, on any computer with a Java 1.4 or later virtual machine. Downloadable distributions are availablefor Windows, Mac OS, Mac OS X and Linux.

It can display, edit, analyze, process, save and print 8-bit, 16-bit and 32-bit images. It can read many image formats including TIFF, GIF, JPEG, BMP, DICOM, FITS and "raw". It supports "stacks", a series of images that share a single window. It is multithreaded, so time-consuming operations such as image file reading can be performed in parallel with other operations.

It can calculate area and pixel value statistics of user-defined selections. It can measure distances and angles. It can create density histograms and line profile plots. It supports standard image processing functions such as contrast manipulation, sharpening, smoothing, edge detection and median filtering.

It does geometric transformations such as scaling, rotation and flips. Image can be zoomed up to 32:1 and down to 1:32. All analysis and processing functions are available at any magnification factor. The program supports any number of windows (images) simultaneously, limited only by available memory.

Spatial calibration is available to provide real world dimensional measurements in units such as millimeters. Density or gray scale calibration is also available.

ImageJ was designed with an open architecture that provides extensibility via Java plugins. Custom acquisition, analysis and processing plugins can be developed using ImageJ's built in editor and Java compiler. User-written plugins make it possible to solve almost any image processing or analysis problem. 

Friday 21 March 2014

Image Sequence in ImageJ


Creates a new image window or stack. A dialog box allows you to specify the image title, type, dimensions and initial content.
Name is the title that will be used for the Window. Type is the image type: 8-bit grayscale, 16-bit grayscale (unsigned), 32-bit (float) grayscale or RGB color. Fill With (White, Black or Ramp) specifies how the image is initialized. Width and Height specify the image dimensions in pixels. Set Slices to a value greater than one to create a stack.



import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;

public class TestImp {

    public static void main(String[] args) {

        IJ.run("Image Sequence...", "open=C:\tempfiles");

        // "open=C:\tempfiles number=2 starting=1 increment=1 scale=100 file=[] or=[] sort");

        ImagePlus imagePlus = WindowManager.getCurrentImage();

        System.out.println(imagePlus.getStackSize());

    }
}

Thursday 13 March 2014

Regarding calibration in the dicom image using ImageJ

1. I assume you have these in DICOM format. In ImageJ it is simple to import a single DICOM image and the calibration is done for you (the DICOM header contains fields for slope and intercept (usually 1 and -1024)). Since you have a stack this is probably not much good. For importing tomographic studies I use the "Import Dicom sequence" plugin available here: http://www.iftm.de/telemedizin/dcmimex.htm

From what I remember it is not the most straight-forward plugin to install but will nicely import a sequence of DICOM images as a stack. It does not, however, seem to calibrate the gray levels into hounsfield units. To do this choose Analyse->Calibrate. Choose "Straight line" as the function, type -1024 in the left box and 0 in the right box. When you press OK you get a straight-line graph of the calibration and a label with straight line formula y = a + bx. a should be -1024 and b should be 1. If they are then we have a calibration to HU.

To demonstrate the HU calibration, move the cursor around the image and observe the "value" in the IJ status bar. The value is in HU and the gray level appears in brackets.

2. Images typically only contain 256 gray levels when displayed, even though the image may contain values of any number (eg CT from -1024 to ~32k). So gray levels have to be "binned" in an image, just like in a histogram. So the column labelled "level" is the gray level displayed in the image and the "bins" are demonstrated in the second column. The size of the bin is dictated by the min and max pixel levels.

I hope I pitched that at the right level. Enjoy ImageJ ;-)

Thursday 12 December 2013

Create image thumbnail in java using ImageJ API

For more information on how to implement Photos sharing website using Java, Spring, Tomcat, Imagej download Fotovault (opensource Photo sharing project) Fotovault - Photo Sharing Project
Below is the code example to create thumbnails in Java.

Download ImageJ jar from

http://rsbweb.nih.gov/ij/download.html

and include it in your classpath.

The below code example proportionately/evenly crops the image to make the image a perfect square and creates a thumbnail of 100 X 100 pixels.
cropAndResize method takes the fileAbsolutePath and Save as image suffix (thumbnail name suffix).


ImageJ New Plugins

In a joint project, we work towards using ImageJ in the context of neuroanatomy. The people involved are:
  • Baker, Dean
  • Jenett, Arnim
  • Grübel, Kornelia
  • Heisenberg, Martin
  • Larkworthy, Tom
  • Longair, Mark
  • Schindelin, Johannes
  • Schmid, Benjamin

AmiraMesh Reader / Writer

In the Würzburg group, we work a lot with Amira, and we work a lot with ImageJ.
To make the work easier, we wrote plugins to read and write 3d stacks in the Amira Mesh format in ImageJ.

Amira Surface Viewer

Amira can write 3d surface files. These can be loaded and visualized in ImageJ with the ShowAmiraSurface plugin.

ROI Brush

Tom Larkworthy wrote the ROI Brush, a tool which does not paint, but instead (un)selects circular regions.

Delaunay / Voronoi diagram

Gabriel Landini had this on his wishlist...

Two Point Correlation

This plugin plots a correlation / distance graph. It was requested by Paul Stutzman, but I have not heard back from him.

Scrollable StackWindow

With this plugin, you can select the current slice with your mouse wheel.

Align Image

Use this plugin to align an image to a template image, by selecting a line in both images.

Moving Least Squares

Warp an image using a technique presented by Schaefer et al. in Image Deformation Using Moving Least Squares.

IsoSurface Extractor

This plugin makes an isosurface from an image stack. It displays the result in a 3d window (you can zoom, pan and rotate the surface), and optionally saves the result as a VRML.

3D Viewer

This plugin offers 3D visualisation of image s

Friday 25 October 2013

3D viewer navigation


The following keystrokes control navigation in the 3D viewer. For more information about navigating in the 3D viewer, see Using the Navigation Controls.
Note - The focus must be in the 3D viewer in order for these controls to take effect. Simply click anywhere in the 3D viewer to change focus.

 
Command
Windows/Linux
Keystroke(s)
Mac
Keystroke(s)
Result
Move leftLeft arrowLeft arrowMoves the viewer in the direction of the arrow.
Move rightRight arrowRight arrowMoves the viewer in the direction of the arrow.
Move upUp arrowUp arrowMoves the viewer in the direction of the arrow.
Move downDown arrowDown arrowMoves the viewer in the direction of the arrow.
Rotate clockwiseShift + left arrowShift + left arrowRotates the view clockwise. The earth spins counter-clockwise.
Rotate counter-clockwiseShift + right arrowShift + right arrowRotates the view counter-clockwise.
Show/hide Overview windowCTRL + MCommand/Open Apple Key + MDisplays or closes overview window.
Tilt upShift + left mouse button + drag down, Shift + down arrowShift + down arrowTilts the viewer toward "horizon" view.
Tilt downShift + left mouse button + drag up, Shift + up arrowShift + up arrowTilts the viewer toward "top-down" view.
LookCTRL + left mouse button + dragCommand/Open Apple Key + mouse button + dragPerspective points in another direction, as if you are turning your head up, down, left or right.
Zoom inScroll wheel, + key, PgUp keyScroll wheel, + keyZooms the viewer in. Tip: to use the 'Page Up' key, make sure 'Num Lock' on your keyboard is off.
Zoom outScroll wheel, - key (both keyboard and numpad), PgDn keyScroll wheel, - key (both keyboard and numpad)Zooms the viewer out. Tip: to use the 'Page Down' key, make sure 'Num Lock' on your keyboard is off.
Zoom + automatic tiltRight mouse button + drag up or downCTRL + click + drag up or downZooms the viewer in and automatically tilts your view as you approach ground level.
Stop current motionSpacebarSpacebarWhen the viewer is in motion, stops movement
Reset view to "north - up"nnRotates view so that view is 'n'orth-up.
Reset tilt to "top-down" viewuuResets angle to view scene in "top-down" or "'u'p" mode.
Reset tilt and compass view to defaultrr'R'esets angle to view "top-down" and rotates to "north-up" view. Use this feature to orient the earth in the center of the viewer.

Tip - Use the ALT key in combination with most of these keystrokes to move more slowly in the indicated direction.

Tuesday 1 October 2013

ImageJ: Create ImageStack for dicom 2d slice

Hello friends following code for make ImagePlus by given path and also modify your code in your own way...enjoy..!!!!

Friday 27 September 2013

ImageJ Programming Tutorials

ImageJ: For Orthogonal Views for Stack of Dicom Images







ImageJ: Show Any Formate Image

WindowManager.setTempCurrentImage(new ImagePlus("D:\\testImaes\\skull\\IM-0001-0001.DCM"));
        imp = WindowManager.getTempCurrentImage();

        Istogramma istogramma = new Istogramma(imp);
        istogramma.showHistogram(imp, 1);
        //imp.show();
        IJ.run(imp, "Scale...", "x=0.5 y=0.5 width=344 height=345 interpolate create title=[Scaled version of " + imp.getTitle() + "]");