Prompt user to select image within script

Hi,

I am writing a script where I would like the user to perform segmentation on one or multiple images. Usually I would use script parameters to have the user select the images to segment, however that would mean fixing the number of images to select. The way that makes the most sense to me would be to use a script parameter to set the amount of images to select, then within the script have a for loop that runs through that many iterations, each loop prompting the user to select the image to analyze.

I have looked through the Dialog and File functions with no luck, the closest function being the getDirectory function. Ideally, something like a getImageFile would work.

Does anybody know of a way I could get this to work? Thanks.

Good day,

what about simply using:

open("");

but perhaps I didn’t set the point…

Regards

Herbie

2 Likes

Herbie,

Thanks for your reply. This is exactly the functionality I was looking for, I didn’t realize not specifying the path would prompt the user to select one.

Thanks again!

For the sake of completeness, let me mention another option, available in Fiji (i.e. ImageJ2): you can specify a File[] script parameter and it will open a dialog allowing you to choose an arbitrary number of files, optionally with a filter for a set of file extensions. Depending on whether this parameter is the only parameter, or there are other script parameters present, a file chooser dialog or a file list widget is displayed. Consider the following two example snippets:

Only one parameter:

#@ File[] inputFiles

for (i = 0; i < inputFiles.length; i++) {
	print("File " + i + ": " + inputFiles[i]);
}

Other script parameters present:

#@ File[] inputFiles
#@ String someOtherParameter

for (i = 0; i < inputFiles.length; i++) {
	print("File " + i + ": " + inputFiles[i]);
}
1 Like