Sorry if it’s a simple question, but I am new to scripting with Python in FiJi and still at the start of the learning curve.
I have a stack of images in nd2 format (Nikon) with 256 positions x 15 time points x 3 fluorescence channels (CFP, YFP and DsRed). I want to apply the plugin BaSiC from ICB on them.
Thanks to previous answers from this community, I now have a running script which loads the input file “test_1.nd2” and applied the Basic plugin to a sub-stack of 15 images corresponding to the first position and CFP channel, which computes and removes the background image from this images.
This script displays the initial stack “CFP stack”, and three result stacks: “Corrected:CFP stack” (the corrected images), “Flat-Field:CFP stack” and “Dark-Field: CFP stack”, the two components of the background calculation.
Now, I would ideally like to not display all these stacks and simply save the resulting three stacks to files. So my questions are the following:
- is there a way to run the plugin on these images without displaying them? I tried removing “imp2.show()” from the script, but then the BaSiC plugin complained about no image being open.
- how do I save the resulting three stack correct, flat-field and dark-field to tiff files for further processing?
Thank you for your help, the full script is below:
from loci.plugins import BF from loci.plugins.in import ImporterOptions from loci.formats import MetadataTools from loci.formats import ImageReader from ij import ImagePlus, ImageStack, IJ file = "Z:/case_imagesc/test_1.nd2" # load position by position options = ImporterOptions() options.setId(file) # Choose first position for now s =0 options.setSeriesOn(s, True) imp = BF.openImagePlus(options) stack = imp.getImageStack() print 'Number of frames in stack = ', stack.size() # three new stacks for each fluorescence channel CFP_stack = ImageStack(stack.width, stack.height) YFP_stack = ImageStack(stack.width, stack.height) DsRed_stack = ImageStack(stack.width, stack.height) # Iterate each frame in the stack and sort for i in range(stack.size()): if i%3==0: cp = stack.getProcessor(i+1) fp = cp.convertToFloat() CFP_stack.addSlice(None,fp) if i%3==1: cp = stack.getProcessor(i+1) fp = cp.convertToFloat() YFP_stack.addSlice(None,fp) if i%3==2: cp = stack.getProcessor(i+1) fp = cp.convertToFloat() DsRed_stack.addSlice(None,fp) options.setSeriesOn(s, False) # first channel selected to run BaSiC imp2 = ImagePlus("CFP stack", CFP_stack) imp2.show() # run BaSiC plugin IJ.run("BaSiC ", "processing_stack=[CFP stack] flat-field=None dark-field=None shading_estimation=[Estimate shading profiles] shading_model=[Estimate both flat-field and dark-field] setting_regularisationparametes=Automatic temporal_drift=Ignore correction_options=[Compute shading and correct images] lambda_flat=0.50 lambda_dark=0.50")