On Mar 14, 2012, at 3:45 PM, Jan Eglinger wrote:
> Dear all,
>
> is there a quick way to convert an open results table into an image
> (where each pixel has the value of a results cell)?
> I did this in the past by saving the results, then deleting the header
> row and File>Import>Text Image, but I'd like to use a quicker way for
> some scripting.
There is an easy way to do this in the ImageJ 1.46i daily build, which adds a getTableAsImage() method to the ResultsTable class. Here is a JavaScript example that opens the "blobs" sample image, runs the particle analyzer on it, converts the results table to an ImageProcessor and then uses the ImageProcessor.getStatistics() method to calculate and displays some column statistics.
-wayne
imp = IJ.openImage("
http://imagej.nih.gov/ij/images/blobs.gif");
IJ.setAutoThreshold(imp, "Default");
IJ.run(imp, "Analyze Particles...", "display clear");
rt = ResultsTable.getResultsTable();
fp = rt.getTableAsImage();
if (fp!=null) {
new ImagePlus("fp", fp).show();
headers = Tools.split(rt.getColumnHeadings());
for (x=0; x<fp.getWidth(); x++) {
fp.setRoi(x,0,1,fp.getHeight());
stats = fp.getStatistics();
print(headers[x]+": "+stats);
}
}
>
> I tried this javascript:
> **
> var rt = ResultsTable.getResultsTable();
> var arr = new Array();
> var lastCol = rt.getLastColumn();
> var numResults = rt.getCounter();
>
> for (i = 0; i < numResults; i++) {
> arr[i] = rt.getValueAsDouble(lastCol, i);
> }
> **
> but then, I don't know how to convert the array to an image. In my case
> it should be a float array, but when trying
>
> fp = new FloatProcessor(arr);
>
> ImageJ complains that it doesn't know which function to use,
> FloatProcessor(int[][] array) or FloatProcessor(float[][] array)
>
> Could you give me a hint how to proceed?
>
> Thanks,
> Jan