Let's put in the code to run our analysis over a folder full of images.
Break down the requirements:
Note: We might also like to include some code to save the segmented binary images, so that users can check the outputs of our script. For that we need to ask the user for an output folder and get image to save the segmented binary images into that folder.
def run():
# Get the user to choose a directory of images to analyse
dc = DirectoryChooser("Pick a folder of images to analyse...")
img_dir = dc.getDirectory()
if img_dir is None:
print "No directory selected."
return
# Get the users to specify an output directory
od = DirectoryChooser("Pick an output folder...")
output_dir = od.getDirectory()
# Get a list of files from the input directory
file_list = os.listdir(img_dir)
file_list = filter(accept, file_list)
results = ResultsTable()
# Iterate through the list of files
for fp in file_list:
image = IJ.openImage(os.path.join(img_dir, fp))
# ... code that analyses image from v4 of the script
# ...
# ...
results.show("Results")
run()