from edfgui import ExtendedDepthOfFieldHeadless from edfgui import Parameters imp = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip"); imp.show() # remove for headless IJ.log("EDF: start...") parameters = Parameters() parameters.setQualitySettings(1) parameters.setTopologySettings(0) parameters.show3dView = False parameters.showTopology = False edfh = ExtendedDepthOfFieldHeadless(imp, parameters) impedf = edfh.processHeadless() IJ.log("EDF: done.") impedf.show() # remove for headless
def process(dirIn, dirOut, expName, ps, pe, ts, te): jobid = commands.getoutput("echo $PBS_JOBID").split('.')[0] jobid = jobid.replace("[","_").replace("]","") # because the jobids look like 2356385[1] which causes problems print "job id: "+jobid jobdir = os.path.join("/tmp",str(jobid)+"_fiji") print "job dir: "+jobdir for p in range(ps,pe+1): pID = str(p); for t in range(ts,te+1): print "TIMEPOINT STARTING ***************" tID = "t"+str(t); print "time-point: "+tID; if os.path.isdir(jobdir): print "removing "+jobdir shutil.rmtree(jobdir) print "creating "+jobdir os.mkdir(jobdir) if stitching: fileOut = "rescaled_flipped_"; for z in range(zs,ze+1): zID = "z"+str(z); print "z-plane: "+zID; if bandpass: IJ.log("bandpass....") # load all images from same time point and same z-position fileID = expName+pID+"_b0"+tID+zID+"m.*"; IJ.log("opening images: "+os.path.join(dirIn,fileID)) IJ.run("Image Sequence...", "open=["+dirIn+"] starting=1 increment=1 scale=100 file=[] or=["+fileID+"] sort"); #selectWindow("im-2012-0007_Position35.tif_Files"); imp = IJ.getImage(); #imp.show(); imp.setTitle("Stack"); # illumination correction IJ.log("computing FFT..."); # run("Flip Horizontally", "stack"); impFFT = Duplicator().run(imp); for i in range(1, impFFT.getNSlices()+1): print "FFT of slice "+str(i) impFFT.setSlice(i) IJ.run(impFFT, "Bandpass Filter...", "filter_large=10000 filter_small=200 suppress=None tolerance=5 "); #impFFT.show() #stats = imp.getStatistics(Measurements.MEAN) #IJ.log("stats.mean = "+str(stats.mean)); # this is only the mean of one slice...is this a problem? print "dividing image stack by FFT stack..."; ic = ImageCalculator() impCorr = ic.run("Divide create 32-bit stack", imp, impFFT); #impCorr.show() def computeMean(pixels): return sum(pixels) / float(len(pixels)) print "multiplying each image by 128/mean for going back to 8 bit space..." stack = impCorr.getStack() for i in range(1, impCorr.getNSlices()+1): ip = stack.getProcessor(i).convertToFloat() mean = computeMean(ip.getPixels()) print "multiplying slice "+str(i)+" by "+str(float(128/mean)) ip.multiply(float(128/mean)) IJ.log("converting from 32-bit to 8-bit...") IJ.setMinAndMax(impCorr, 0, 255); IJ.run(impCorr,"8-bit",""); #IJ.saveAs(impCorr, "Tiff", "/Users/tischi/Documents/processed.tif"); #ff #impCorr.show() # save images IJ.log("saving bandpass corrected image sequence: "+os.path.join(jobdir,fileOut)) IJ.run(impCorr, "Image Sequence... ", "format=TIFF name=["+fileOut+"] start=1 digits=4 save=["+jobdir+"]"); if check: IJ.run(impCorr, "Image Sequence... ", "format=TIFF name=["+fileOut+"] start=1 digits=4 save=["+dirOut+"]"); #impCorr.close(); imp.close(); impFFT.hide(); # stitching IJ.log("STITCHING START **********") layoutFile = copyStitchingLayoutFile(dirIn,expName,jobdir,ps) ###layoutFile = makeStitchingLayoutFile(jobdir) createPreview = 0 computeOverlap = 0 fusion_method="Linear Blending" handleRGB = "Red, Green and Blue" showImage = 0 #fusion=1 regression=0.30 max/avg=2.50 absolute=3.50" st = Stitch_Image_Collection() st.alpha = 1 IJ.log("layout file: "+str(layoutFile)) impStitched = st.work(layoutFile, createPreview, computeOverlap, fusion_method, handleRGB, showImage) stitchedFile = os.path.join(jobdir,tID+zID+"_stitched.tif"); #impStitched.show() IJ.saveAs(impStitched,"Tiff", stitchedFile); if check: print os.path.join(dirOut,tID+zID+"_stitched.tif") stitchedFile = os.path.join(dirOut,tID+zID+"_stitched.tif"); IJ.saveAs(impStitched,"Tiff", stitchedFile); IJ.log("STITCHING END **********") if combine_z: IJ.log("combine z.....") ######### IJ.log("load stitched images into a stack...") for z in range(zs,ze+1): zID = "z"+str(z); stitchedFile = os.path.join(jobdir,tID+zID+"_stitched.tif"); IJ.log("opening "+stitchedFile) imp = IJ.openImage(stitchedFile) if z==zs: stack = ImageStack(imp.width,imp.height) stack.addSlice(imp.getProcessor()) imp = ImagePlus("stack", stack) #imp.show() ######## ######## IJ.log("cropping...") imp.setRoi(xs, ys, xe, ye); IJ.run(imp, "Crop", ""); #imp.show() ######## # the following normalisation should not be necessary, because they are already all 128/mean normalised #IJ.log("-- normalise intensity of all slices...") #stats = imp.getStatistics(Measurements.MEAN) #IJ.log("stats.mean = "+str(stats.mean)); # this is only the mean of one slice...is this a problem? #stack = imp.getStack() #for i in range(1, impFFT.getNSlices()+1): # ip = stack.getProcessor(i).convertToFloat() # ip.multiply(128/stats.mean) # #stack.setSlice(stack.getSliceLabel(i), ip) #run("Set Slice...", "slice="+1); #run("Set Measurements...", " mean redirect=None decimal=9"); #run("Select None"); #setBatchMode(true); #setMinAndMax(0, 255); run("32-bit"); #for(l=0; l<nSlices+1; l++) { ## run("Select All"); # run("Clear Results"); # run("Measure"); # picsum=getResult("Mean",0); # //if(l==0){picsum1=picsum;} # //int_ratio=picsum1/picsum; # int_ratio=128/picsum; # run("Select None"); # IJ.log("ratio ="+int_ratio); # run("Multiply...", "slice value="+int_ratio); # run("Next Slice [>]"); #} #setBatchMode(false); # stop here and try by hand #... #dfgfd #//stack-reg #//IJ.log("register xy...") #//run("StackReg", "transformation=Translation"); #// project into 1 plane .... #// run("Extended Depth of Field (Easy mode)..."); #//run("Z Project...", "start=["+1+"] stop=["+ze+"] projection=[Standard Deviation]"); doEDF = True if doEDF: IJ.log("EDF: start...") parameters = Parameters() parameters.setQualitySettings(1) parameters.setTopologySettings(0) parameters.show3dView = False parameters.showTopology = False edfh = ExtendedDepthOfFieldHeadless(imp, parameters) imp = edfh.processHeadless() IJ.log("EDF: done.") #imp.show() IJ.log("EDF: converting from 32-bit to 8-bit...") IJ.setMinAndMax(imp, 0, 255); IJ.run(imp,"8-bit",""); edfFile = os.path.join(dirOut,expName+pID+"-"+tID+"_EDOF_noTimeNorm.tif"); IJ.log("EDF save: "+edfFile) IJ.saveAs(imp,"Tiff", edfFile); IJ.log("EDF save: done.") #close(); // projection #close(); // stack print "TIMEPOINT FINISHED ***************" if os.path.isdir(jobdir): print "removing "+jobdir shutil.rmtree(jobdir)