Exporting grayscale value to excel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Exporting grayscale value to excel

Mahesh Thapaliya
Hi!

I am quite new to imageJ.  I would like to export all the grayscale value
from a picture (or from a stack of images) and wanted to process in Excel
and wanted to see the picture back in imageJ. Is it possible to do this?
If so, could someone please write, how can i do this?

Like this.
S.N.   X-Value    Y-Value     Grayscale Value
1.
2.
3.
4.
.
.

Regards,
Mahesh Thapaliya
Jyväskylä, Finland
Reply | Threaded
Open this post in threaded view
|

Re: Exporting grayscale value to excel

Janne Hyötylä
Hi Mahesh,

These macros here are maybe not the most efficient but they work.
You have to import the saved image in excel as tab-separated values.
And when saving the excel sheet, again save it as tab-separated text file  
(might be called *.csv).

To export the original image:

x = getWidth();
y = getHeight();
f = File.open("");
for (i= 0; i < x*y; i++) {
     ix = i%x;
     iy = floor(i/x);
     print(f, (ix) + "\t" + (iy) + "\t" + getPixel(ix, iy));
}



To import the modified image (it loops twice through the values to get the  
image dimensions first)

str = File.openAsString("");
rows = split(str, "\n");
x = newArray(lengthOf(rows));
y = newArray(lengthOf(rows));
val = newArray(lengthOf(rows));
for (i= 0; i < lengthOf(rows); i++) {
     cols = split(rows[i], "\t");
     x[i] = cols[0];
     y[i] = cols[1];
     val[i] = cols[2];
}
Array.getStatistics(x, xmin, xmax);
Array.getStatistics(y, ymin, ymax);
newImage("ImportFromExcel", "16-bit", xmax+1, ymax+1, 1);
for (i= 0; i < lengthOf(val); i++) {
     setPixel(x[i], y[i], val[i]);
}


You should modify it accordingly if you want more than 1 slice or other  
bit depths etc..

Hope it helps.

Janne



On Sat, 23 Oct 2010 13:08:09 +0200, Mahesh Thapaliya  
<[hidden email]> wrote:

> Hi!
>
> I am quite new to imageJ.  I would like to export all the grayscale value
> from a picture (or from a stack of images) and wanted to process in Excel
> and wanted to see the picture back in imageJ. Is it possible to do this?
> If so, could someone please write, how can i do this?
>
> Like this.
> S.N.   X-Value    Y-Value     Grayscale Value
> 1.
> 2.
> 3.
> 4.
> .
> .
>
> Regards,
> Mahesh Thapaliya
> Jyväskylä, Finland