def getFilesAndAnalyze(folder): count = 0 timeseries = [] for root, directories, filenames in os.walk(folder): print directories for filename in sorted(filenames): #print filenames if not (("_1.tif" in filename) and ("2views_2" in filename)): continue else: #print root #print directories #print filename timeseries = appendFileToArray(timeseries, root, filename) count = count + 1 if count>10000: break calib = timeseries[0].getCalibration() jaimp = array(timeseries, ImagePlus) nc = 1 nz = timeseries[0].getImageStack().getSize() nt = len(timeseries) print nc,nz,nt allimp = Concatenator().concatenate(jaimp, False) allimp.setDimensions(nc, nz, nt) allimp.setCalibration(calib) allimp.setOpenAsHyperStack(True) allimp.show()
def concatenate_files(f1, f2, path): # note that concatenate closes passed windows! ct = Concatenator() merged = ct.run(f1, f2) IJ.saveAs(merged, "Tiff", path)
if match is not None: #print filename, match.group(3) GRlist.append(match.group(3)) print srcDir print 'files: ', len(GRlist) GRlist = sorted(GRlist) timeseries = [] for timepoint in GRlist: thisfile = basename + '_R' + repetition + '_GR' + timepoint + '_B' + block + '_L' + location + '.lsm' print thisfile imp = Opener.openUsingBioFormats(os.path.join(srcDir, thisfile)) imp.setOpenAsHyperStack(False) timeseries.append(imp) newname = basename + '_R' + repetition + '_B' + block + '_L' + location + '.lsm' calib = timeseries[0].getCalibration() dimA = timeseries[0].getDimensions() jaimp = array(timeseries, ImagePlus) ccc = Concatenator() #allimp = ccc.concatenateHyperstacks(jaimp, newname, False) allimp = ccc.concatenate(jaimp, False) allimp.setDimensions(dimA[2], dimA[3], len(GRlist)) allimp.setCalibration(calib) allimp.setOpenAsHyperStack(True) allimp.show()
#get right name for duplication of the desired frame if n < 10: numstr = "000" + str(n) elif n < 100: numstr = "00" + str(n) elif n > 99: numstr = "0" + str(n) if choice == 1: choose = RT.getValue(metaRT, "Frame selected", n - 1) #duplicate the right frame and give it the right title impDup = IJ.run( "Duplicate...", "title=Image_R" + str(numstr) + " duplicate frames=" + str(choose) + "") imp.close() # add 1 to the counter n = n + 1 #get list imageplus objects of all open images impl = [WM.getImage(id) for id in WM.getIDList()] end = len(impl) imp2 = impl[0] ti = 0 #concatenate all the frames to a time lapse for t in impl: if ti > 0: imp2 = Concatenator.run(imp2, t) print t ti = ti + 1 imp2.show()
def croppoints(self, outdir, roi_x=150, roi_y=150, ntracks=None, trackid="TRACK_ID", trackxlocation="POSITION_X", trackylocation="POSITION_Y", tracktlocation="FRAME"): """Function to follow and crop the individual spots within a trackmate "Spots statistics.csv" file. Args: imp (ImagePlus()): An ImagePlus() stack. spots (list of dictionaries): The output of a getresults() function call. outdir (path): The output directory path. roi_x (int, optional): ROI width (pixels). Defaults to 150. roi_y (int, optional): ROI height (pixels). Defaults to 150. ntracks (int, optional): The number of tracks to process. Defaults to None. trackid (str, optional): Column name of Track identifiers. Defaults to "TRACK_ID". trackxlocation (str, optional): Column name of spot x location. Defaults to "POSITION_X". trackylocation (str, optional): Column name of spot y location. Defaults to "POSITION_Y". tracktlocation (str, optional): Column name of spot time location. Defaults to "FRAME". """ imp = self.imp spots = self.spots if ntracks == None: ntracks = len(spots) elif ntracks > len(spots): ntracks = len(spots) def _cropSingleTrack(ispots): """Nested function to crop the spots of a single TRACK_ID. Args: ispots (list): List of getresults() dictionaries belonging to a single track. Returns: list: A list of ImagePlus stacks of the cropped timeframes. """ outstacks = [] for j in ispots: # Extract all needed row values. j_id = int(j[trackid]) j_x = int(j[trackxlocation] * xScaleMultiplier) j_y = int(j[trackylocation] * yScaleMultiplier) j_t = int(j[tracktlocation]) # Now set an ROI according to the track's xy position in the hyperstack. imp.setRoi( j_x, j_y, roi_x, roi_y ) # upper left x, upper left y, roi x dimension, roi y dimension # Optionally, set the correct time position in the stack. This provides cool feedback but is sloooow! # imp.setPosition(1, 1, j_t) # Crop the ROI on the corresponding timepoint and add to output stack. crop = Duplicator().run( imp, 1, dims[2], 1, dims[3], j_t, j_t) # firstC, lastC, firstZ, lastZ, firstT, lastT outstacks.append(crop) return outstacks # START OF MAIN FUNCTION. # Store the stack dimensions. dims = imp.getDimensions( ) # width, height, nChannels, nSlices, nFrames # IJ.log("Dimensions width: {0}, height: {1}, nChannels: {2}, nSlices: {3}, nFrames: {4}.".format( # dims[0], dims[1], dims[2], dims[3], dims[4])) # Get stack calibration and set the scale multipliers to correct for output in physical units vs. pixels. cal = imp.getCalibration() if cal.scaled(): xScaleMultiplier = cal.pixelWidth yScaleMultiplier = cal.pixelHeight IJ.log( "Physical units to pixel scale: x = {}, y = {} pixels/unit\n". format(xScaleMultiplier, yScaleMultiplier)) else: xScaleMultiplier = 1 yScaleMultiplier = 1 IJ.log( "Image is not spatially calibrated. Make sure the input .csv isn't either!" ) IJ.log( "Physical units to pixel scale: x = {}, y = {} pixels/unit\n". format(xScaleMultiplier, yScaleMultiplier)) # Add a black frame around the stack to ensure the cropped roi's are never out of view. expand_x = dims[0] + roi_x expand_y = dims[1] + roi_y # This line could be replaced by ij.plugin.CanvasResizer(). # However, since that function takes ImageStacks, not ImagePlus, that just makes it more difficult for now. IJ.run( imp, "Canvas Size...", "width={} height={} position=Center zero".format( expand_x, expand_y)) # Retrieve all unique track ids. This is what we loop through. track_ids = set([track[trackid] for track in spots]) track_ids = list(track_ids) stacks = [] # This loop loops through the unique set of TRACK_IDs from the results table. for i in track_ids[0:ntracks]: # Extract all spots (rows) with TRACK_ID == i. trackspots = [spot for spot in spots if spot[trackid] == i] # IJ.log ("TRACK_ID: {}/{}".format(int(i+1), len(track_ids))) # Monitor progress # Crop the spot locations of the current TRACK_ID. out = _cropSingleTrack(trackspots) # Concatenate the frames into one ImagePlus and save. impout = Concatenator().run(out) stacks.append(impout) # outfile = os.path.join(outdir, "TRACK_ID_{}.tif".format(int(i))) # IJ.saveAs(out, "Tiff", outfile) self.croppedpoints = stacks IJ.log("\nExecution croppoints() finished.")
from ij.gui import PointRoi import math from java.awt import * from java.awt import Font import itertools from ij.plugin.filter import MaximumFinder from ij.measure import ResultsTable import time from ij.gui import WaitForUserDialog import os, errno import glob from ij.gui import Overlay from ij.plugin import Concatenator concat = Concatenator() # Indicate channel which should be used for Thresholding # Save the results automatically as CSV file ? automatic_save_results = True #path for CSV fave #savepath = "d:\Marte/EGF/" draw_rois = True threshold = [9000, 3577, 5000] testmode = False IJ.run("Set Measurements...", "median min mean stack redirect=None decimal=3") #datapath = "D:/Eva/Maja/Experiment1/GFP-Vps36_Gal3/"
maxC = max([i.getNChannels() for i in imL]) else: maxC = len(chl) ssL = [] # Same number of slices nff=True for im in imL: if chl is not None: ## Here we extract only the channels we need im = SubHyperstackMaker().makeSubhyperstack(im, [i+1 for i in chl], range(1, im.getNSlices()+1), range(1, im.getNFrames()+1)) nz = maxZ-im.getNSlices() # Number of z planes to add if nz==0 and im.getNChannels()==maxC: ssL.append(im) continue if im.getNFrames()==1: tmp = Duplicator().run(im, 1, im.getNChannels(), 1, 1, 1, 1) # create a duplicated slice tmp.getProcessor().multiply(0) # make it a dark frame ssL.append(Concatenator().concatenate([im]+[tmp]*nz, False)) # This deletes references/images in imL else: # if im.getNFrames()>1 (we need to concatenate time-point-per timepoint :s ) nff=False allFrames = [] stack = im.getImageStack() nZ = im.getNSlices() nC = im.getNChannels() dark = Duplicator().run(im, 1, 1, 1, 1, 1, 1) dark.getProcessor().multiply(0) res = ij.ImageStack(im.width, im.height) icnt = 0 for ia in range(1, im.getNFrames()+1): for ib in range(1, maxZ+1): for ic in range(1,maxC+1): icnt +=1 if (ib>im.getNSlices()) or (ic>im.getNChannels()):
def loadTif(self, allowOverwrite=1): if self.header['b_sequence'] == 'Linescan': bPrintLog('Skipping: bPrairie2tif does not support Linescan, email bob and have him implement this', 3) return 0 width = None height = None #ip_ch1 = [] # a list of images as a list of 'image processor' #ip_ch2 = [] #ip_ch3 = [] bPrintLog('Loading ' + str(self.header['b_numSlices']) + ' Files ...', 3) numFiles = 0 infoStr = '' # sort individual .tif files into ch1 and ch2 for filename in os.listdir(self.srcFolder): if filename.endswith(".tif") and not filename.startswith('.'): # bPrintLog('opening:' + filename, 3) try: imp = IJ.openImage(self.srcFolder + filename) if imp is None: bPrintLog("ERROR: prairie2stack() could not open image from file:" + self.srcFolder + filename) continue isch1 = '_Ch1_' in filename isch2 = '_Ch2_' in filename isch3 = '_Ch3_' in filename if numFiles == 0: # don;t do this, header is to big to keep with output .tif #infoStr = imp.getProperty("Info") #get all tags, this is usefless infoStr += '\n' + self.infoStr0 # when appending, '\n' (EOL) is important because header does NOT end in EOL width = imp.width height = imp.height #stack = imp.getImageStack() #cp = stack.getProcessor(1) # assume 1 channel if isch1: #ip_ch1.append(cp) if self.imp_ch1 is None: self.imp_ch1 = imp else: self.imp_ch1 = Concatenator.run(self.imp_ch1, imp) elif isch2: #ip_ch2.append(cp) if self.imp_ch2 is None: self.imp_ch2 = imp else: self.imp_ch2 = Concatenator.run(self.imp_ch2, imp) elif isch3: #ip_ch3.append(cp) if self.imp_ch3 is None: self.imp_ch3 = imp else: self.imp_ch3 = Concatenator.run(self.imp_ch3, imp) else: bPrintLog('ERROR: did not find channel name in file:' + filename) numFiles += 1 except: continue #bPrintLog("exception error: prairie2stack() could not open image from file:" + self.srcFolder + filename) bPrintLog('Loaded ' + str(numFiles) + ' files ...', 3) ''' bPrintLog('ch1 has ' + str(len(ip_ch1)) + ' slices', 4) bPrintLog('ch2 has ' + str(len(ip_ch2)) + ' slices', 4) bPrintLog('ch3 has ' + str(len(ip_ch3)) + ' slices', 4) ''' #20170314, need to rewrite this to loop through channels (lots of repeated code here if self.imp_ch1 is not None: self.imp_ch1.setProperty("Info", infoStr); if self.imp_ch2 is not None: self.imp_ch2.setProperty("Info", infoStr); if self.imp_ch3 is not None: self.imp_ch3.setProperty("Info", infoStr); #ch1 #if ip_ch1: if self.imp_ch1: # bPrintLog('ch1 has ' + str(self.imp_ch1.getNSlices()) + ' slices', 4) ''' stack_ch1 = ImageStack(width, height) for fp in ip_ch1: stack_ch1.addSlice(fp) self.imp_ch1 = ImagePlus('xxx', stack_ch1) self.imp_ch1.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter']>0: bPrintLog('ch1: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str(globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch1, "Median...", medianArgs); infoStr += 'bMedianFilter=' + str(globalOptions['medianFilter']) + '\n' self.imp_ch1.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog('converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2^13 divideBy = bitDepth / 2^8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch1, "Divide...", divideArgs); # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch1, "8-bit", ''); # print stats including intensity for the stack we just made # Returns the dimensions of this image (width, height, nChannels, nSlices, nFrames) as a 5 element int array. d = self.imp_ch1.getDimensions() # width, height, nChannels, nSlices, nFrames stats = self.imp_ch1.getStatistics() # stats.min, stats.max bPrintLog('ch1 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog('ch1 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) # set the voxel size so opening in Fiji will report correct bit depth # run("Properties...", "channels=1 slices=300 frames=1 unit=um pixel_width=.2 pixel_height=.3 voxel_depth=.4"); #ch2 #if ip_ch2: if self.imp_ch2: # bPrintLog('ch2 has ' + str(self.imp_ch2.getNSlices()) + ' slices', 4) ''' stack_ch2 = ImageStack(width, height) for fp in ip_ch2: stack_ch2.addSlice(fp) self.imp_ch2 = ImagePlus('xxx', stack_ch2) self.imp_ch2.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter']>0: bPrintLog('ch2: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str(globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch2, "Median...", medianArgs); infoStr += 'bMedianFilter=' + str(globalOptions['medianFilter']) + '\n' self.imp_ch2.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog('converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2^13 divideBy = bitDepth / 2^8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch2, "Divide...", divideArgs); # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch2, "8-bit", ''); # print stats including intensity for the stack we just made d = self.imp_ch2.getDimensions() # width, height, nChannels, nSlices, nFrames stats = self.imp_ch2.getStatistics() # stats.min, stats.max bPrintLog('ch2 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog('ch2 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) #ch2 #if ip_ch3: if self.imp_ch3: # bPrintLog('ch1 has ' + str(self.imp_ch3.getNSlices()) + ' slices', 4) ''' stack_ch3 = ImageStack(width, height) for fp in ip_ch3: stack_ch3.addSlice(fp) self.imp_ch3 = ImagePlus('xxx', stack_ch3) self.imp_ch3.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter']>0: bPrintLog('ch3: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str(globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch3, "Median...", medianArgs); infoStr += 'bMedianFilter=' + str(globalOptions['medianFilter']) + '\n' self.imp_ch3.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog('converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2^13 divideBy = bitDepth / 2^8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch3, "Divide...", divideArgs); # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch3, "8-bit", ''); # print stats including intensity for the stack we just made d = self.imp_ch3.getDimensions() # width, height, nChannels, nSlices, nFrames stats = self.imp_ch3.getStatistics() # stats.min, stats.max bPrintLog('ch3 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog('ch3 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) return 1
""" testConcatenator.py Modifications Date Who Ver What ---------- --- ------ ------------------------------------------------- 2018-03-12 JRM 0.1.00 Concatenate images into a stack. Based on an example from Wayne Rasband postecd to the IJ mailing list. """ from ij import IJ from ij.plugin import Concatenator IJ.run("Close All") IJ.run("Boats (356K)") i1 = IJ.getImage() IJ.run("Bridge (174K)") i2 = IJ.getImage() i3 = Concatenator.run(i1, i2) i3.show()
def run(): myPrint("=== bConcatALign ===") #get source folder if len(sys.argv) < 2: #from user sourceFolder = DirectoryChooser("Please Choose A Directory Of .tif Files").getDirectory() if not sourceFolder: myPrint(' Aborted by user') return else: #from command line sourceFolder = sys.argv[1] #assuming it ends in '/' destFolder = sourceFolder + "channels8/" #a list of file names fileList = [] sliceList = [] timeseries = [] #ccc = Concatenator() #i = 0 for filename in os.listdir(sourceFolder): startWithDot = filename.startswith(".") isMax = filename.endswith("max.tif") isTif = filename.endswith(".tif") if (not startWithDot) and (not isMax) and (isTif): myPrint(filename) fullPath = sourceFolder + filename shortName, fileExtension = os.path.splitext(filename) fileList.append(filename) #get x/y/z dims and append to list #imp = Opener.openUsingBioFormats(fullPath) #not working imp = IJ.openImage(sourceFolder + filename) imp.setOpenAsHyperStack(False) timeseries.append(imp) #if (i==0): # mergedImp = imp #else: # print i # ccc.concatenate(mergedImp, imp, True) # #i += 1 calib = timeseries[0].getCalibration() dimA = timeseries[0].getDimensions() #why doesn't this f*****g work !!!!!!!!!!!!!!!!!! #infoProp = timeseries[0].getInfoProperty() #print calib #print dimA #print infoProp jaimp = array(timeseries, ImagePlus) ccc = Concatenator() allimp = ccc.concatenate(jaimp, False) #allimp.setDimensions(dimA[2], dimA[3], len(GRlist)) allimp.setCalibration(calib) allimp.setOpenAsHyperStack(True) allimp.show()
p)) continue print("Loading data...") if len(imfilenames) > 2: fo = FolderOpener() imp = fo.open(p) imp.show() print("N_z = {}".format(imp.getNSlices())) print("N_c = {}".format(imp.getNChannels())) print("N_t = {}".format(imp.getNFrames())) else: ch1_imp = IJ.openImage(os.path.join(p, imfilenames[0])) ch2_imp = IJ.openImage(os.path.join(p, imfilenames[1])) imp = Concatenator().concatenate(ch1_imp, ch2_imp, False) imp2 = HyperStackConverter.toHyperStack(imp, 2, int(imp.getNSlices() / 2), 1, "xyzct", "Composite") imp2.show() imp.close() print("Saving data...") out_dir = os.path.dirname(os.path.dirname(p)) save_path = os.path.join(out_dir, fname + ".tif") FileSaver(imp2).saveAsTiffStack(save_path) print("Copying metadata...") shutil.copyfile(os.path.join(p, fname + ".txt"), os.path.join(out_dir, metadata_file)) imp2.close() except Exception as e:
def loadTif(self, allowOverwrite=1): if self.header['b_sequence'] == 'Linescan': bPrintLog( 'Skipping: bPrairie2tif does not support Linescan, email bob and have him implement this', 3) return 0 width = None height = None #ip_ch1 = [] # a list of images as a list of 'image processor' #ip_ch2 = [] #ip_ch3 = [] bPrintLog('Loading ' + str(self.header['b_numSlices']) + ' Files ...', 3) numFiles = 0 infoStr = '' # sort individual .tif files into ch1 and ch2 for filename in os.listdir(self.srcFolder): if filename.endswith(".tif") and not filename.startswith('.'): # bPrintLog('opening:' + filename, 3) try: imp = IJ.openImage(self.srcFolder + filename) if imp is None: bPrintLog( "ERROR: prairie2stack() could not open image from file:" + self.srcFolder + filename) continue isch1 = '_Ch1_' in filename isch2 = '_Ch2_' in filename isch3 = '_Ch3_' in filename if numFiles == 0: # don;t do this, header is to big to keep with output .tif #infoStr = imp.getProperty("Info") #get all tags, this is usefless infoStr += '\n' + self.infoStr0 # when appending, '\n' (EOL) is important because header does NOT end in EOL width = imp.width height = imp.height #stack = imp.getImageStack() #cp = stack.getProcessor(1) # assume 1 channel if isch1: #ip_ch1.append(cp) if self.imp_ch1 is None: self.imp_ch1 = imp else: self.imp_ch1 = Concatenator.run(self.imp_ch1, imp) elif isch2: #ip_ch2.append(cp) if self.imp_ch2 is None: self.imp_ch2 = imp else: self.imp_ch2 = Concatenator.run(self.imp_ch2, imp) elif isch3: #ip_ch3.append(cp) if self.imp_ch3 is None: self.imp_ch3 = imp else: self.imp_ch3 = Concatenator.run(self.imp_ch3, imp) else: bPrintLog('ERROR: did not find channel name in file:' + filename) numFiles += 1 except: continue #bPrintLog("exception error: prairie2stack() could not open image from file:" + self.srcFolder + filename) bPrintLog('Loaded ' + str(numFiles) + ' files ...', 3) ''' bPrintLog('ch1 has ' + str(len(ip_ch1)) + ' slices', 4) bPrintLog('ch2 has ' + str(len(ip_ch2)) + ' slices', 4) bPrintLog('ch3 has ' + str(len(ip_ch3)) + ' slices', 4) ''' #20170314, need to rewrite this to loop through channels (lots of repeated code here if self.imp_ch1 is not None: self.imp_ch1.setProperty("Info", infoStr) if self.imp_ch2 is not None: self.imp_ch2.setProperty("Info", infoStr) if self.imp_ch3 is not None: self.imp_ch3.setProperty("Info", infoStr) #ch1 #if ip_ch1: if self.imp_ch1: # bPrintLog('ch1 has ' + str(self.imp_ch1.getNSlices()) + ' slices', 4) ''' stack_ch1 = ImageStack(width, height) for fp in ip_ch1: stack_ch1.addSlice(fp) self.imp_ch1 = ImagePlus('xxx', stack_ch1) self.imp_ch1.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter'] > 0: bPrintLog( 'ch1: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str( globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch1, "Median...", medianArgs) infoStr += 'bMedianFilter=' + str( globalOptions['medianFilter']) + '\n' self.imp_ch1.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog( 'converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2 ^ 13 divideBy = bitDepth / 2 ^ 8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch1, "Divide...", divideArgs) # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch1, "8-bit", '') # print stats including intensity for the stack we just made # Returns the dimensions of this image (width, height, nChannels, nSlices, nFrames) as a 5 element int array. d = self.imp_ch1.getDimensions( ) # width, height, nChannels, nSlices, nFrames stats = self.imp_ch1.getStatistics() # stats.min, stats.max bPrintLog( 'ch1 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog( 'ch1 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) # set the voxel size so opening in Fiji will report correct bit depth # run("Properties...", "channels=1 slices=300 frames=1 unit=um pixel_width=.2 pixel_height=.3 voxel_depth=.4"); #ch2 #if ip_ch2: if self.imp_ch2: # bPrintLog('ch2 has ' + str(self.imp_ch2.getNSlices()) + ' slices', 4) ''' stack_ch2 = ImageStack(width, height) for fp in ip_ch2: stack_ch2.addSlice(fp) self.imp_ch2 = ImagePlus('xxx', stack_ch2) self.imp_ch2.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter'] > 0: bPrintLog( 'ch2: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str( globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch2, "Median...", medianArgs) infoStr += 'bMedianFilter=' + str( globalOptions['medianFilter']) + '\n' self.imp_ch2.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog( 'converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2 ^ 13 divideBy = bitDepth / 2 ^ 8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch2, "Divide...", divideArgs) # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch2, "8-bit", '') # print stats including intensity for the stack we just made d = self.imp_ch2.getDimensions( ) # width, height, nChannels, nSlices, nFrames stats = self.imp_ch2.getStatistics() # stats.min, stats.max bPrintLog( 'ch2 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog( 'ch2 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) #ch2 #if ip_ch3: if self.imp_ch3: # bPrintLog('ch1 has ' + str(self.imp_ch3.getNSlices()) + ' slices', 4) ''' stack_ch3 = ImageStack(width, height) for fp in ip_ch3: stack_ch3.addSlice(fp) self.imp_ch3 = ImagePlus('xxx', stack_ch3) self.imp_ch3.setProperty("Info", infoStr); ''' # median filter if globalOptions['medianFilter'] > 0: bPrintLog( 'ch3: Running median filter: ' + str(globalOptions['medianFilter']), 4) medianArgs = 'radius=' + str( globalOptions['medianFilter']) + ' stack' IJ.run(self.imp_ch3, "Median...", medianArgs) infoStr += 'bMedianFilter=' + str( globalOptions['medianFilter']) + '\n' self.imp_ch3.setProperty("Info", infoStr) if globalOptions['convertToEightBit']: bPrintLog( 'converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 4) bitDepth = 2 ^ 13 divideBy = bitDepth / 2 ^ 8 # divide the 13 bit image down to 8 bit #run("Divide...", "value=32 stack"); bPrintLog('divideBy:' + str(divideBy), 4) divideArgs = 'value=' + str(divideBy) + ' stack' IJ.run(self.imp_ch3, "Divide...", divideArgs) # convert to 8-bit will automatically scale, to turn this off use # eval("script", "ImageConverter.setDoScaling(false)"); ImageConverter.setDoScaling(False) # run("8-bit"); bPrintLog('converting to 8-bit with setDoScaling False', 4) IJ.run(self.imp_ch3, "8-bit", '') # print stats including intensity for the stack we just made d = self.imp_ch3.getDimensions( ) # width, height, nChannels, nSlices, nFrames stats = self.imp_ch3.getStatistics() # stats.min, stats.max bPrintLog( 'ch3 dimensions w:' + str(d[0]) + ' h:' + str(d[1]) + ' channels:' + str(d[2]) + ' slices:' + str(d[3]) + ' frames:' + str(d[4]), 4) bPrintLog( 'ch3 intensity min:' + str(stats.min) + ' max:' + str(stats.max), 4) return 1