EDIT: @iarganda fixed this in a patch!
FIJI version: (Fiji Is Just) ImageJ 2.0.0-rc-69/1.52n; Java 1.8.0_172 [64-bit];
I am running attempting to create a Jython macro that will register 2 images of fluorescent beads.
When I run Register Virtual Stack Slices (RVSS) for the first time on FIJI (no advanced mode, save transforms) it works successfully. However, when attempting to register any subsequent sets of images (either using my macro or manually using the plug-in) it gives an error:
“Could not open target image at [path]” and opens a Bio-Formats Import Options window. Clicking OK or Cancel on the Bio-Formats window does not resolve the issue.
The interesting thing is that the RVSS will still output transformed files for the ones with the error, but it will not save the transforms (only the first run will save the transforms.) I need the transform files to apply the transforms to other files.
I believe my FIJI is up to date and only has files from the update sites. I have tried running my macro on my Mac as well with a fresh install of FIJI, but I still get the same error.
The following is my macro that is adapted from the Process Folder example (may have to change the file separator if using a Windows):
@ File (label = "Input directory", style = "directory") srcFile @ String (label = "File extension", value=".tif") ext containString1 = "after" containString2 = "mCherry" # See also Process_Folder.ijm for a version of this code # in the ImageJ 1.x macro language. from register_virtual_stack import Register_Virtual_Stack_MT import os from ij import IJ, ImagePlus import sys def run(): srcDir = srcFile.getAbsolutePath() for root, directories, filenames in os.walk(srcDir): filenames.sort(); for filename in filenames: # Check for file extension if not filename.endswith(ext): continue # Check for "after" pattern in file name if containString1 not in filename: continue # Check for "mCherry" pattern in file name if containString2 not in filename: continue # Check if already registered if 'Registered' in root: #print("Already registered: "+root) continue # Check for only 2 files in folder if len(filenames) != 2: #print("Wrong number of files: "+ root) continue process(root, filename) #create a new registered folder and perform image registration #NOTE: DIRECTORIES NEED FILE SEPARATOR AFTERWARDS. WILL GIVE ERROR IF FILE SEPARATOR BEFORE REFERENCE FILE NAME def process(currentDir, fileName): # source directory source_dir = os.path.join(currentDir,"") #print("Source: "+source_dir) # output directory (folder named Registered in folder one level above current directory) target_dir = os.path.join(os.path.dirname(currentDir),"Registered","") #print("target: "+target_dir) #create output directory if it does not exist if not os.path.exists(target_dir): try: os.mkdir(target_dir) except OSError: print ("Creation of the directory %s failed" % target_dir) else: print ("Successfully created the directory %s " % target_dir) # transforms directory (same as the source directory) transf_dir = os.path.join(currentDir,"") # reference image (need to add separator before file name) reference_name = fileName #print("Reference: "+reference_name) featuresModelIndex = 1 #RIGID registrationModelIndex = 1 #RIGID advanced = False non_shrink = False Register_Virtual_Stack_MT.exec(source_dir, target_dir, transf_dir, reference_name, featuresModelIndex, registrationModelIndex, advanced, non_shrink) imp = IJ.getImage() #stores current image in imp imp.close() #for each image in the registered folder, open mCherry images, create a stack, and save it for root, directories, filenames in os.walk(target_dir): for filename in filenames: imp = IJ.openImage(os.path.join(target_dir, filename)) imp.show() IJ.run("Images to Stack", "method=[Copy (top-left)] name=Stack title= use"); #creates stack from the top left imp = IJ.getImage() #stores current image in imp IJ.saveAs(imp, "Tiff", os.path.join(target_dir, "Registered_mCherry")); imp.close() run()
Attached is an example folder to run the code on. If clarification on anything is needed, please let me know. Thank you in advance!