Multi-point pixel selections for an entire folder of images

macro
Tags: #<Tag:0x00007fb87d5c1df8>

#1

I have a folder full of images. Each image has maybe ten features in it. I would like to have a macro which does the following.

  1. Requests image directory

  2. Loops through each image in directory, and
    a) opens the image
    b) pauses while I make click multiple points of interest in the image
    c) extracts the pixel coordinates x,y at each click
    d) appends [image_name, x,y] to an output list
    e) closes the image when I am done

  3. returns the output list as a csv file after all images have been iterated through

The form of the output should be:

fname1, x11, y11,
fname1, x12, y12,
fname1,x1n,y1n,

fname2, x21,y21,

fname2,xm2,ym2,

fnameN,xk1,xk2

Any guidance is appreciated; I’m an imageJ layman. I searched around and was not able to find a simple solution


#2

@kevinkayaks

To get you started… check out this older post for another user… You can also check out the following links - which have a nice outline of code you could use & modify to do as you wish:


#3

Thanks @etarena
Patching together some various things / actively making things up leads me to this. Do you have any guidance for me off of these lines? Thanks!

files = getFileList(input);
for (i = 0; i < files.length; i++){
	filename = files[i];
	open(filename);
	key = File.nameWithoutExtension;
	for (j=0; j< nResults; j++){
	    x = getResult("X", j);
	    y = getResult("Y", j);
            List.set(key, (x,y));     
	close();
  	
	}
}
saveAs("List", output+"Results.csv");

Currently the code opens images and waits for my input as expected, but the input is not being properly recorded or saved.


#4

solution:
define input path as input and output path as output

nr = 0 
run("Clear Results");
files = getFileList(input);
for (i = 0; i < files.length; i++){
    filename = files[i];	
    open(input + filename);
    waitForUser("find features on image" + filename);
    run("Measure");
    for (j=nr; j< nResults;j++){
        setResult("image filename", j, filename);}
    updateResults();
    nr = nResults;
    close();
    }

saveAs("Results", output);