Saving or Exporting Multiple results files

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

Saving or Exporting Multiple results files

javila0624
Hello all,
Can someone help with figuring out a more efficient way of exporting values from the results window? I've made a macro that gives me custom histogram counts for three respective channels. I am running batch-processing using this macro on 20 samples. Below is the final edit for it. As you can see, I placed a waitforUser command so I can paste data onto an excel sheet.


When I try to save with saveAs("Results", "Directory...), my data is overwritten by the most recent file data. I've tried variations of (...,Directory/getTitle().txt") with no luck.

Ideally, I'd like to have either one results window with all data points for all 20 samples (20*3=60 separate histogram distributions), one .txt file with all data, or 20 separate .txt files (or 60 of them).

The most perfect solution would be someway to export to excel with the macro, while preventing over-writing of data (which I've experienced with print(x, ...) commands). I think I'm missing a line or some code to skip columns in excel iteratively.



Can someone offer assistance?


title=getTitle()
c1Title = "C1-" + title;
c2Title = "C2-" + title;
c3Title = "C3-" + title;          
run("Split Channels");
row = 0;
selectWindow( "C3-" + title);
getHistogram(Values, counts, nBins, min,max);
                for (k=0; k<nBins; k++) {
                setResult("Channel", row,"C3-" + title);
                setResult("Count", row, counts[k]);
                row++;
        }
updateResults();
selectWindow( "C2-" + title);
getHistogram(Values, counts, nBins, min,max);
                for (k=0; k<nBins; k++) {
                setResult("Channel", row,"C3-" + title);
                setResult("Count", row, counts[k]);
                row++;
        }
         updateResults();
selectWindow ("C1-" + title);
getHistogram(Values, counts, nBins, min,max);
                for (k=0; k<nBins; k++) {
                setResult("Channel", row,"C3-" + title);
                setResult("Count", row, counts[k]);
                row++;
        }
         updateResults();

selectWindow ("Results");
String.copyResults
waitForUser

Reply | Threaded
Open this post in threaded view
|

Re: Saving or Exporting Multiple results files

Michael Entrup
Hi Javila,

I hope this will help you. I took your macro and extended it a bit. It
will open a sample image, get the histogram data and save it as a csv
file. To demonstrate, that it creates a new csv file for each image, you
have to rename the sample image and the macro will do the same task again.

Best regards
Michael


nBins = 256;
min = 0;
max = 255;
run("Fluorescent Cells (400K)");
run("16-bit");

hist();
run("Fluorescent Cells (400K)");
run("16-bit");
run("Rename...");
hist();

function hist() {
        setBatchMode(true);
        title=getTitle()
        c1Title = "C1-" + title;
        c2Title = "C2-" + title;
        c3Title = "C3-" + title;
        run("Split Channels");
        row = 0;
        run("Clear Results");
        run("Input/Output...", "jpeg=85 gif=-1 file=.csv use_file copy_row");
        selectWindow( "C1-" + title);
        getHistogram(Values, counts, nBins, min,max);
        for (k=0; k<nBins; k++) {
                setResult("Value", row, k);
                setResult("Count C1", row, counts[k]);
                row++;
                }
        row = 0;
        close();
        selectWindow( "C2-" + title);
        getHistogram(Values, counts, nBins, min,max);
        for (k=0; k<nBins; k++) {
                setResult("Count C2", row, counts[k]);
                row++;
        }
        row = 0;
        close();
        selectWindow ("C3-" + title);
        getHistogram(Values, counts, nBins, min,max);
        for (k=0; k<nBins; k++) {
                setResult("Count C3", row, counts[k]);
                row++;
        }
        close();
        updateResults();
        saveAs("Results", "C:\\Temp\\" + title + ".csv");
        selectWindow ("Results");
        run("Close");
        setBatchMode("exit and display");
}



Am 23.07.2014 um 01:04 schrieb javila0624:

> Hello all,
> Can someone help with figuring out a more efficient way of exporting values
> from the results window? I've made a macro that gives me custom histogram
> counts for three respective channels. I am running batch-processing using
> this macro on 20 samples. Below is the final edit for it. As you can see, I
> placed a waitforUser command so I can paste data onto an excel sheet.
>
>
> When I try to save with saveAs("Results", "Directory...), my data is
> overwritten by the most recent file data. I've tried variations of
> (...,Directory/getTitle().txt") with no luck.
>
> Ideally, I'd like to have either one results window with all data points for
> all 20 samples (20*3=60 separate histogram distributions), one .txt file
> with all data, or 20 separate .txt files (or 60 of them).
>
> The most perfect solution would be someway to export to excel with the
> macro, while preventing over-writing of data (which I've experienced with
> print(x, ...) commands). I think I'm missing a line or some code to skip
> columns in excel iteratively.
>
>
>
> Can someone offer assistance?
>
>
> title=getTitle()
> c1Title = "C1-" + title;
> c2Title = "C2-" + title;
> c3Title = "C3-" + title;
> run("Split Channels");
> row = 0;
> selectWindow( "C3-" + title);
> getHistogram(Values, counts, nBins, min,max);
> for (k=0; k<nBins; k++) {
>                  setResult("Channel", row,"C3-" + title);
>                  setResult("Count", row, counts[k]);
>                  row++;
>          }
> updateResults();
> selectWindow( "C2-" + title);
> getHistogram(Values, counts, nBins, min,max);
> for (k=0; k<nBins; k++) {
>                  setResult("Channel", row,"C3-" + title);
>                  setResult("Count", row, counts[k]);
>                  row++;
>          }
>           updateResults();
> selectWindow ("C1-" + title);
> getHistogram(Values, counts, nBins, min,max);
> for (k=0; k<nBins; k++) {
>                  setResult("Channel", row,"C3-" + title);
>                  setResult("Count", row, counts[k]);
>                  row++;
>          }
>           updateResults();
>
> selectWindow ("Results");
> String.copyResults
> waitForUser
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Saving-or-Exporting-Multiple-results-files-tp5008855.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Saving or Exporting Multiple results files

javila0624
Thanks Michael Entrup! This helped out a lot!