imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.2k stars 337 forks source link

Batch export of landmarks XY coordinates #226

Closed T4mmi closed 5 years ago

T4mmi commented 5 years ago

Hi everyone,

In order to semi-automatically segment images / place ROI, I placed landmarks in images using the Multi-point tool and saved results as TIFF images ... for thousands of images !

I now wanna extract the coordinates of such points in order to use them outside of ImageJ.

when I open the image and do a File > Save As > XY Coordinates... it provides a text file containing ONLY the coordinates of my points --> That's the behavior I wanna replicate

I tried to script a macro as following:

macro "Export coordinates" { 
    dir = getDirectory("Choose a Directory "); 
    list = getFileList(dir); 
    setBatchMode(true); 
    for (i=0; i<list.length; i++) { 
        path = dir+list[i]; 
        showProgress(i, list.length); 
        name = list[i]; 
    txtPath = dir+name+".txt"; 
    run("Save XY Coordinates...", "save=["+txtPath+"]");
        close(); 
    } 
} 

Yet I end up with text files containing text images ...

kind of stuck there

imagejan commented 5 years ago

That's a question, not an issue report. Questions like this are better asked on https://forum.image.sc.

run("Save XY Coordinates...", "save=["+txtPath+"]");

If you used the macro recorder to get this command, you seem to have recorded the wrong command. This corresponds to Analyze > Tools > Save XY Coordinates... (as you can find out using the serach bar), while the menu command you mention (File > Save As > XY Coordinates) is recorded as:

run("XY Coordinates...", ...

Maybe you were tricked by the new macro code completion implemented by @haesleinhuepf ?

T4mmi commented 5 years ago

Thanks a lot, indeed it was my mistake between "Save XY Coordinates..." and "XY Coordinates..." Though that was an issue of the script

Anyway I drop the gist of the macro here in case that can help someone in the futur.

macro "Export coordinates" { 
    /*
        Read images in a chossen directory and export measurements
        XY coordinates in a .txt file with the same name
    */
    dir = getDirectory("Choose a Directory ");  // window to select the input directory
    list = getFileList(dir); // list files in it
    setBatchMode(true); // activate batch process
    for (i=0; i<list.length; i++) { // loop over files
        showProgress(i, list.length); // update progressbar
        fileName = list[i];
        filePath = dir+fileName; 
        open(filePath);  // open the current image
        name = substring(fileName, 0, lastIndexOf(fileName, “.”));
        txtPath = dir+name+".txt"; 
        run("XY Coordinates...", "save=["+txtPath+"]");
        close(); 
    } 
} 

closes #226