Re: pls: how export an image into Excel
Posted by
Albert Cardona on
URL: http://imagej.273.s1.nabble.com/pls-how-export-an-image-into-Excel-tp3699547p3699552.html
Francisco,
To create a text file with your image as a width x height matrix:
ImagePlus imp = IJ.getImage();
ImageProcessor ip = imp.getProcessor();
StringBuffer sb = new StringBuffer();
int width = ip.getWidth();
int height = ip.getHeight();
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
sb.append(ip.getf(x, y)).append(' '); // using faster version
of getPixel
}
sb.append('\n');
}
new ij.text.TextPanel(sb.toString()).saveAs(""); // will show a file dialog
Voila. Super easy.
The above works for all kinds of images. You may want to change 'getf'
for 'get' to retrieve pixels as integers, or even call the pixels object
with getPixels() and cast it (it's an array, of type dependent on the
ImageProcessor type). You can also use getColumn() and getRow() (check
the ImageProcessor API, all you need is there:
http://rsb.info.nih.gov/ij/developer/api/index.html ).
Even easier would be to simple Save As / Text... and then cut the pixels
column into rows of image width length.
Albert