Search code examples
csvmacrosgrayscaleimagej

ImageJ Macro: saving csv file


I'm trying write a macro to save the profiles from a sequence of images. Sadly, it's not working: the images open and close correctly (and the correct profile is drawn) but the .csv is nowhere to be found.

This is the code:

function action(input, output, filename) {
    open(input+filename);
    makeLine(568, 14, 576, 1006);
    run("Plot Profile");
            saveAs("Measurements", output + filename + ".csv");
    close();
    close();
}


input = "C:\\Users\\...etc...\\20170124\\";
output = "C:\\Users\\...etc....\\20170124\\";

list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);

Solution

  • Solved :D

    function action(input, output, filename) {
        open(input+filename);
        makeLine(568, 14, 576, 1006);
        run("Clear Results");
        name = filename +".csv";
        profile = getProfile();
        for (i=0; i<profile.length; i++)
        setResult("Value", i, profile[i]);
        updateResults();
        saveAs("Results", output + name);  
    }