def concatenate_files(f1, f2, path): # note that concatenate closes passed windows! ct = Concatenator() merged = ct.run(f1, f2) IJ.saveAs(merged, "Tiff", path)
#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()
filename = dataname + ".csv" #files = glob.glob(savepath+"/"+dataname+"*.csv") savename = savepath + "/" + filename ort.saveAs(savename) else: print "not saving" if filenum == 0: dup = Duplicator() stack1 = dup.run(imp1) print "first round" else: try: dup = Duplicator() stack2 = dup.run(imp1) stack1 = concat.run(stack1, stack2) stack1.setTitle(directory) print "making stack" except NameError: dup = Duplicator() stack1 = dup.run(imp1) print "first image was empty" imp1.changes = False imp1.close() if rm.getCount() != 0: rm.runCommand("Delete") output_file = savepath + "/nuclei_count.txt" with open(output_file, "w") as output: output.write(str(nuclei_count_sum) + "\n") stack1.show()
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 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