Posted by
Cammer, Michael on
Mar 29, 2015; 6:27pm
URL: http://imagej.273.s1.nabble.com/saving-multiple-measurements-to-the-same-spreadsheet-or-text-file-tp5012045p5012241.html
Here is a macro we wrote quickly on Thursday to output the mean intensity of a bunch of ROIs in 3 channels. It's not fully realized-- for instance ratios aren't calculated, it doesn't read all files from a folder and match them with the ROI files, and it prints to the Log window instead of out to files, but I'm putting it here because of the trick we often use for generating columns of data. It's not my idea; I found it a few years ago in someone else's macro.
Simply define an output string and set it null. Then in each iteration of a loop append new text or numbers to the string followed by a tab. At the end of the loop, print it. Usually we use two print statements, one to send to the Log window and one to a text file with the same name as the image being analyzed or one big text file for all images with the same root name. It's a flexible method because columns can be added/subtracted without dealing with arrays and it is easy to read in text files generated this way and split them back into numbers. And maybe the d2s command isn't really needed.
Relevant code in boldface (may or may not survive the repost).
var tab = " \t ";
var bg = newArray(104, 175, 124); // bg of each channel
macro "measure all cells [F4]" {
run("Set Measurements...", "mean redirect=None decimal=4");
print(getTitle());
print("cell# \t YFP \t FRET \t CFP");
means = newArray(3);
for (i=0; i<roiManager("count"); i++){
roiManager("select", i);
outputstring = "" + d2s((i+1),0) + tab;
for (s=1; s<=3; s++) {
setSlice(s);
run("Measure");
means[s-1] = getResult("Mean", nResults-1) - bg[s-1];
outputstring = outputstring + d2s(means[s-1],0) + tab;
}
print(outputstring);
} // end for i
} // end macro
_________________________________________
Michael Cammer, Optical Microscopy Specialist
http://ocs.med.nyu.edu/microscopyLab: (212) 263-3208 Cell: (914) 309-3270
________________________________________
From: ImageJ Interest Group [
[hidden email]] on behalf of Patrick Coffey [
[hidden email]]
Sent: Sunday, March 29, 2015 12:25 PM
To:
[hidden email]
Subject: Re: saving multiple measurements to the same spreadsheet or text file
Dear Jim,
Thank you for your response. (I have spent countless hours on the
resources that you mentioned). Unfortunately there is not a single example
of saving data from columns of multiple measurements to a spreadsheet or txt
file (one can build up a multi-column table one row at a time). Just to
re-cap - I want to measure multiple profiles and save them to the "same"
file as columns. Saving the profiles to individual files is easy to do.
So the output would look something like this
Profile1 Profile2 Profile3
130 240 255
77 212 170
And so on ....
I believe the problem is that imagej does not support 2D arrays,
hence it is impossible to build up a 2D array in nested loops in the typical
fashion. My guess is that I will have to resort to a 1D array that has the
same number of positions as the 2D array. Then I will have to literally
build up the results table one line at a time where the intended columns are
separated by "\t". Once the results table is built, I will be able to save
that as a spreadsheet file.
Please let me know if you have a workaround and thanks for the help.
Patrick
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Jim
Passmore
Sent: Thursday, March 19, 2015 6:20 AM
To:
[hidden email]
Subject: Re: saving multiple measurements to the same spreadsheet or text
file
Patrick,
Based on your brief description, I think there may be what you need in the
standard Results Table. For example, if you measure a series of lines, you
can get a result table with the length and angle orientation (2 columns) of
each line, one line per row in the table. It can easily be saved to a text
file to import into a spreadsheet.
There are probably multiple ways to use it that will accomplish what you
need. First off, bookmark the "developer resources" page, as it will come
in handy.
http://imagej.net/developer/index.htmlSecond, from that page there is a list of macro language functions at
http://imagej.net/developer/macro/functions.htmlI would search through that page for commands that operate on the result
table. In particular, the setResult and updateResults commands might help.
Use ctrl-F in the browser window and search for "result" to find a few more
useful commands.
Another option would be to save your measurements in an array, then use the
Array.show command to display them in a result window, which again can be
saved to a file. Array commands are on the same web page.
Note that there are numerous examples linked to from the list of macro
functions, and there are other resources on the developer page, including a
couple of "manuals" on macro programming and many more examples. You may
find better ideas there. Happy programming!
On Wed, Mar 18, 2015 at 3:02 PM, Patrick Coffey <
[hidden email]>
wrote:
> Hi, I'm trying to determine if there is a straightforward way using a
> macro with imageJ to save multiple measurements to a spreadsheet file
> (or tab delimited txt file) in the form of a measurement for each column.
> Currently I can save a single measurement at a time where the relevant
> code is as follows
>
> ... looping through images (image1, image2, image3 ... and so on)
> Plot.create("Profile", "X", "Value", profile); // Plot profile
> Plot.show();
> waitForUser("","review Plot");
> saveAs("Measurements");
>
> I'd like the columns to be image1, image2, etc ...
>
> Any sample code is greatly appreciated. Many thanks, Patrick
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
*-- Jim Passmore*
Research Associate
Sealed Air Corporation
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html