Image Data from ImageJ to R and Vice Versa

[This article was first published on » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In recent years many R packages have been developed to enable image analysis in R. As an alternative the combination of R with a powerful image analysis software like ImageJ offers many advanced image analysis interfaces and algorithms not yet available in R. Bio7 integrates both applications in a Rich Client Plattform based on Eclipse interfaced and connected with the RServe application (which offers an API to connect Java and R). In addition Bio7 offers an easy to use interface for the bidirectional transfer of image data from ImageJ to R respectively R to ImageJ. The transfer of selected image data regions, selection point(s) coodinates (single and multiple) and transfer of particle measurements data to R is supported with special actions in Bio7, too. Here is a short overview:

Transfer of image data to and from R

It is quite simple to transfer images from ImageJ to R with the interface Bio7 offers. The image data itself can be transferred as (datatype) doubles, integers or bytes which are supported by default in R. The data is transferred as vector data in R (except double data which can also be transferred as a matrix). In addition the image size (as variables) is transferred, too (this variables for size are automatically selected if an image is transferred from R to ImageJ).
Vice versa the default data types can be used to create ImageJ supported image types which are:
Colour images (R,G,B), Float 32-bit images, Short 16-bit images, Greyscale 8-bit images.

The options to select different datatypes and image types enables an efficient and appropriate transfer of image data to the R workspace or to ImageJ from the R workspace.
R,G,B images, for example, can efficiently be transferred as byte data after a split of the image R,G,B data in its intensity (greyscale) components (in ImageJ the command can be found in the main menu: Image->Colour->Split Channels).

Note: If several opened images should be transferred in one shot to the R workspace the “Cluster Pic” or “PCA” action can be used with the option “Only Transfer” to transfer all selected image layers (see video below).

Video: (older!).

Transfer of selected image data (pixels)

With the Bio7 interface it is also possible to transfer values from selected pixels. Several selection types are available in ImageJ and will be transferred as vector data to R. With this action it is e.g. possible to do regional statistics of image data in R. If several images are opened in the tabbed interface the selected region for all opened layers can be transferred, too in one shot e.g. to analyze changes in time or space (see video below).


Transfer of selection coordinates

In addition the transfer of selection coordinates of ImageJ is supported in two different ways: single selections as vectors and multiple selections (recorded in the “ROI-Manager” of ImageJ – ROI=Region Of Interest) as 2d-vectors. This features can be used e.g. to analyze shape data, point-pattern data, etc.
Please be aware that in Java the coordinate display is different from the coordinate display in R (the 0,0 coordinates for x and y in Java are in the upper-left!).


Transfer of Particle Analysis data

In ImageJ measurements of Particles are supported in an easy way. Particles could be for example cells, animals, plants etc. which are recorded in an image. The particles can be analyzed automatically with the Analyze->Analyze Particles action in the ImageJ menu. Several geometrical measurements are supported e.g. Area, Diameter, Centroids, Bounding rectangle, Ferret’s diameter etc.
The results of such measurements can directly be transferred to the R workspace with a special action available in the Bio7 GUI interface (in the detached Image-Methods view). The measurements can be analyzed easily with different packages in R.
With the Spatstat package for example the centroid values of the particle analysis can be used to calculate nearest neighbour distances, point-pattern statistics etc. The geometrical measurements can be used for example to split the data in different classes (see video below).


Dynamic transfer of R data to ImageJ

Dynamic R data (or plot data) can be transferred (and recorded) to ImageJ with the available R API and the Java language (or BeanShell and Groovy) with Bio7. Created R data from called R scripts or created within Java e.g. can be tranferred directly into an ImageJ image (as a kind of display) or ImageJ stack (see video below). Even the recording of timed R plots in ImageJ can be realized (as a stack).


At all the combination of R and ImageJ offers powerful possibilities to combine image analysis and statistical analysis with an easy to use Graphical User Interface offered by Bio7. Bio7 is an OpenSource Software and is available for all popular platforms (Windows 32, 64-bit, Linux 32, 64-bit and MacOSX 64-bit) at:

To leave a comment for the author, please follow the link and comment on their blog: » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)