Login  Register

Re: Using a Macro to Format Exported Results File in Imagej

Posted by Jan Eglinger on Sep 16, 2013; 8:33am
URL: http://imagej.273.s1.nabble.com/Using-a-Macro-to-Format-Exported-Results-File-in-Imagej-tp5004789p5004793.html

Dear Hannah,

On 16.09.2013 12:50 AM, hschn444 wrote:
> I have created a macro that generates many different data points in the
> results window. For each image, a angle, lengths, etc. is generated. Is
> there a way I can format the column headers in the exported excel results
> file? For example, I have many different lengths generated in the macro, but
> they import into the excel file on individual rows with repeating image
> names. I would like each length in a different column corresponding to the
> same image name.

You can add a column to the current line in the Results window like this:

    setResult("NameOfNewColumn", nResults-1, value);

(see http://imagej.nih.gov/ij/developer/macro/functions.html#setResult )

However, I understand that you get a variable number of length
measurements and therefore your number of needed columns would be
variable for each line/image. This will be a little cumbersome to
implement, and I'd suggest actually keep the measurements one per line.
Provided you have unique image names (=Labels), you can group and
analyze them much easier using e.g. Excel's PivotTable functions or any
more powerful statistical software.
If you only need the total length, you can add all your measurements
within the macro and only add a "LengthTot" column.

Hope that helps,
Jan



>
> This is what I get:
>
>       Label               X   Y   Angle      Length
> 1   IMG_1227.JPG    285 882 -48.406 714.025
> 2   IMG_1227.JPG    0   0      0         1003.544
> 3   IMG_1227.JPG    0   0      0          532
> 4   IMG_1227.JPG    0   0      0          5623
> This is what I want:
>
>      Label               X     Y    Angle   Length1  LengthN    LengthTot
> LengthSeg
> 1   IMG_1227.JPG    285 882 -48.406 714.025 1003.544   532           5632
>
>
> It would be ideal to modify the macro I have to do this.
>
>     dir=getDirectory("image");
>    name = "Results";
>    index = lastIndexOf(name, "\\");
>    if (index!=-1) name = substring(name, 0, index);
>    name = name + ".xls"; ///can change xls to csv, txt, etc.
>    saveAs("Measurements", dir+name);
>
> close();
> }
> run("Clear Results");
>
>

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