Login  Register

Re: ROI to calculate mean grey value of 2 stacks

Posted by Swayne, Theresa C. on Mar 27, 2017; 2:31pm
URL: http://imagej.273.s1.nabble.com/ROI-to-calculate-mean-grey-value-of-2-stacks-tp5018354p5018379.html


Dear Nan,

You’re welcome!

It is possible to do what you want, although ImageJ is not designed to easily rearrange text.

To re-format the results, you need to 1) read in the data from the existing table, and then 2) re-write it to a new table in the order that you want.  I am not adept enough to write this for you quickly.

But as an example, below is part of a macro I wrote to take certain data from the particle analysis summary table and rewrite it in a different order. You may be able to adapt this snippet for your purpose.

For more help I recommend searching this list’s archives, and the ImageJ forum at forum.imagej.net, for posts related to the Results Table. That is what I did to put together my code.

Hope this helps.

======================================================
// read data from the Summary window
selectWindow("Summary");
lines = split(getInfo(), "\n");     // reads in all the contents of the table as an array
headings = split(lines[0], "\t");  // splits the 0th row (table headings) into an array
C1Values = split(lines[1], "\t");  // 1st row of data in the table
C1Name = C1Values[0]; // 0th column in the 1st row of data — the image name
C2Values = split(lines[2], "\t");  // 2nd row of data
C2Name = C2Values[0];           // 0th column in the 2nd row of data — the image name
OverlapValues = split(lines[3], "\t"); // 3rd row of data

// convert strings to integers
C1Count = parseInt(C1Values[1]); // 1st data row, 1st data column, converted from string to int so that I can calculate with it
C2Count = parseInt(C2Values[1]); // 2nd data row, 1st data column, converted from string to int
OverlapCount = parseInt(OverlapValues[1]); // 3rd data row, 1st data column, converted from string to int

// calculate the percent overlap
C1withC2 = OverlapCount/C1Count;
C2withC1 = OverlapCount/C2Count;

// create a new table with all colocalization data
// format: image name, n cells, n cells colocalized with other label, % colocalized with other label
run("New... ", "name=[Cell_Colocalization] type=Table");
print("[Cell_Colocalization]", "Filename\tChannel\tTotal Cells\tColocalized Cells\tFraction Colocalized\n”); // new table headings
print("[Cell_Colocalization]", C1Name+"\t1\t" + C1Count+ "\t"+ OverlapCount + "\t" + C1withC2); // 1st row of data in new table
print("[Cell_Colocalization]", C2Name+"\t2\t" + C2Count+ "\t"+ OverlapCount + "\t" + C2withC1); // 2nd row of data in new table

// save the table
selectWindow("Cell_Colocalization");
saveAs("Text", path+"coloc-"+basename+".xls”);
==========================================================



> On Mar 27, 2017, at 3:37 AM, Nan Hu <[hidden email]> wrote:
>
> Dear Theresa,
>
> Thank you so much for your detailed explaination. Now things worked pretty well except for showing the results in different colums. The results are shown as you said "in one append", and the macro I use is shown as following:
>
> -------------------------------Macro Begin---------------------------------
> run("Image Sequence...", "open=[E:\\AF\stack1.tif] sort");
> run("Select All");
> roiManager("Add");
> roiManager("Multi Measure");
> run("Image Sequence...", "open=[E:\\SHG\stack1.tif] sort");
> roiManager("multi-measure measure_all one append");
> -------------------------------Macro Finished--------------------------------
>
> Do you know how to change the macro to separate the results in different colums?
>
> Best regards,
> Nan
>
>

------------------------------------
Theresa Swayne, Ph.D.
Manager
Confocal and Specialized Microscopy Shared Resource

Herbert Irving Comprehensive Cancer Center
Columbia University Medical Center
1130 St. Nicholas Ave., Room 222A
New York, NY 10032
Phone: 212-851-4613
[hidden email]


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html