Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 56 lines (48 sloc) 2.783 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
This example opens several image files (if selected) in ImageJ without to displaying them in the ImageJ-Canvas view.
The script transfers, clusters and summarizes the RGB pixel values of the images in R
Then it transfers the summarized results (pixel counts - areas) to the Bio7 Grid. The default images are scaled
and are painted in a grid cell, too!

The new Bio7 1.6 API method to transfer R, G, B values as a matrix is used for this workflow!

Note: This example demonstrates how to apply advanced RScripts to e.g. a folder of images and then
generate automatically a report of the results in the Bio7 spreadsheet (which can be saved and
restored as a file with the new Bio7 import/export format which saves images and formattings of
the sheet, too).
*/
import ij.IJ;
import ij.ImagePlus;
import ij.WindowManager;
import org.eclipse.nebula.widgets.grid.Grid;
import ij.process.ImageProcessor;
import java.awt.image.BufferedImage;

if (RServe.isAliveDialog()) {
Bio7Grid.createSheet(0, 0, "Measurements");//Create a new sheet in the Table view!
for (int i = 0; i < 6; i++) {
Bio7Grid.createColumn(1,70, "State: " + (i + 1));//Create new columns!

}
Bio7Grid.createColumn(1,70, "Name");//Create new column!
Bio7Grid.createColumn(1,160, "Image");//Create new column!

String[] files = Bio7Dialog.openMultipleFiles();//Open files from multiple selections(with Shift+Mouse-Click or Ctrl+Mouse-Click).
if(files!=null){
RConnection c = RServe.getConnection();
for (int i = 0; i < files.length; i++) {
System.out.println(Bio7Dialog.getCurrentPath() + "/" + files[i]);
ImagePlus imp = IJ.openImage(Bio7Dialog.getCurrentPath() + "/" + files[i]);//Open image data with the ImageJ API!
ImageProcessor ip = imp.getProcessor().resize(160, 120);//Resize the image data!
ImagePlus impResized=new ImagePlus("pic", ip);//Create a new image from the image data!
BufferedImage buff=impResized.getBufferedImage();//Create a BufferedImage from the resized image!

//Transfer the R, G, B image (ImagePlus required as argument!) to R in one shot with the new Bio7 1.6 API method!
ImageMethods.imageToR("currentImage", true, 3, imp);
c.eval("cl<-kmeans(currentImage,6)"); //Cluster the image data with the kmeans algorithm in R!
RServe.print("table(cl$cluster)");//Create a table in R from the results!
String[] values = (String[]) c.eval("as.character(table(cl$cluster))").asStrings();//Get the result values as a String array!
Bio7Grid.createRow(i,120);
/*Put the values and the scaled image in the sheet!*/
for (int u = 0; u < values.length; u++) {
Bio7Grid.setValue(i, u, values[u]);
Bio7Grid.setValue(i, 6, imp.getTitle());
Bio7Grid.setImage(i,7,Bio7Grid.toSWTImage(buff));
}

}
}
}
Something went wrong with that request. Please try again.