def run(imagefile, verbose=False): # open image file and get a specific series log.log(LogLevel.INFO, 'Opening Image: ' + imagefile) imp, MetaInfo = ImportTools.openfile(imagefile) # output of image metadata in log window if verbose: for k, v in MetaInfo.items(): log.log(LogLevel.INFO, str(k) + ' : ' + str(v)) log.log(LogLevel.INFO, 'File Extension : ' + MetaInfo['Extension']) if 'ResolutionCount' in MetaInfo: log.log(LogLevel.INFO, 'Resolution Count : ' + str(MetaInfo['ResolutionCount'])) if 'SeriesCount' in MetaInfo: log.log(LogLevel.INFO, 'SeriesCount : ' + str(MetaInfo['SeriesCount'])) if 'SizeC' in MetaInfo: log.log(LogLevel.INFO, 'Channel Count : ' + str(MetaInfo['SizeC'])) # do the processing log.log(LogLevel.INFO, 'Start Processing ...') # create empty image list imglist = [] numch = imp.getNChannels() # do the processing for ch in range(numch): # get a channel imp_c = MiscTools.splitchannel(imp, ch) name = os.path.basename(imagefile) + '_CH=' + str(ch) sp, fv, fv_max, fv_max_index = calc_focus(imp_c, name) log.log(LogLevel.INFO, 'Processing Channel : ' + str(ch)) log.log(LogLevel.INFO, 'Max. Value : ' + str(fv_max)) log.log(LogLevel.INFO, 'Max. Value Slice : ' + str(fv_max_index)) # set correct image properties sp = MiscTools.setproperties(sp, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=1, sizeZ=1, sizeT=1) imglist.append(sp) # in case of more than one channel use an jarray if numch > 1: # create an array imgarray = jarray.array(imglist, ImagePlus) # create an ImageStack from the array imgstack = ImageStack.create(imgarray) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp = ImagePlus(new_name + '_SHARPEST', imgstack) # ic case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp = imglist[0] # set correct image properties for the final image imp_sp = MiscTools.setproperties(imp_sp, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=numch, sizeZ=1, sizeT=1) return imp_sp
def run(imagefile, verbose=False): # open image file and get a specific series log.log(LogLevel.INFO, 'Opening Image: ' + imagefile) imp, MetaInfo = ImportTools.openfile(imagefile) # output of image metadata in log window if verbose: for k, v in MetaInfo.items(): log.log(LogLevel.INFO, str(k) + ' : ' + str(v)) log.log(LogLevel.INFO, 'File Extension : ' + MetaInfo['Extension']) if 'ResolutionCount' in MetaInfo: log.log(LogLevel.INFO, 'Resolution Count : ' + str(MetaInfo['ResolutionCount'])) if 'SeriesCount' in MetaInfo: log.log(LogLevel.INFO, 'SeriesCount : ' + str(MetaInfo['SeriesCount'])) if 'SizeC' in MetaInfo: log.log(LogLevel.INFO, 'Channel Count : ' + str(MetaInfo['SizeC'])) # do the processing log.log(LogLevel.INFO, 'Start Processing ...') # create empty image list imglist_t_c = [] imglist_t = [] numch = imp.getNChannels() # do the processing for t in range(MetaInfo['SizeT']): # get the timepoint imp_t = getstackfrom5d(imp, MetaInfo, firstC=1, lastC=MetaInfo['SizeC'], firstZ=1, lastZ=MetaInfo['SizeZ'], firstT=t + 1, lastT=t + 1) # calc the focus values for the different channels for ch in range(numch): # get a stack for a channel imp_t_c = getstackfrom5d(imp_t, MetaInfo, firstC=ch + 1, lastC=ch + 1, firstZ=1, lastZ=MetaInfo['SizeZ'], firstT=1, lastT=1) # create a name for the plane #name = os.path.basename(imagefile) + 'T=' + str(t+1) + '_CH=' + str(ch+1) name = 'T=' + str(t + 1) + '_CH=' + str(ch + 1) # get the plane with the bst focus to the current timepoint and current channel sp_c, fv, fv_max, fv_max_index = calc_focus(imp_t_c, name) log.log(LogLevel.INFO, 'Processing TimePoint : ' + str(t + 1)) log.log(LogLevel.INFO, 'Processing Channel : ' + str(ch + 1)) log.log(LogLevel.INFO, 'Max. Value : ' + str(fv_max)) log.log(LogLevel.INFO, 'Max. Value Slice : ' + str(fv_max_index)) # set correct image properties sp_c = MiscTools.setproperties(sp_c, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=1, sizeZ=1, sizeT=1) imglist_t_c.append(sp_c) print 'List CH Stacks :', len(imglist_t_c) for i in range(len(imglist_t_c)): print str(i) + ' : ', type(imglist_t_c[i]) # in case of more than one channel use an jarray if numch > 1: # create an array imgarray_c = jarray.array(imglist_t_c, ImagePlus) # create an ImageStack from the array print 'Type imgarray_c : ', type(imgarray_c) for i in range(numch): print type(imgarray_c[i]) imgstack_c = ImageStack.create(imgarray_c) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp_c = ImagePlus(new_name + '_SHARPEST_C', imgstack_c) # in case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp_c = imglist_t_c[0] # set correct image properties for the final image imp_sp_c = MiscTools.setproperties(imp_sp_c, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=numch, sizeZ=1, sizeT=1) # concatenate the timepoints imglist_t.append(imp_sp_c) if numch > 1: # create an array imgarray = jarray.array(imglist_t, ImagePlus) # create an ImageStack from the array imgstack = ImageStack.create(imgarray) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp_t = ImagePlus(new_name + '_SHARPEST_CT', imgstack) # in case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp_t = imglist_t[0] return imp_sp_t
namepattern = os.path.splitext(os.path.basename(imagefile))[0] stack = MiscTools.import_sequence(targetdir, number=MetaInfo['SizeZ'], start=1, increment=1, filepattern=namepattern, sort=True, use_virtualstack=False) # set properties for new stack stack = MiscTools.setproperties(stack, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit="micron", sizeC=MetaInfo['SizeC'], sizeZ=MetaInfo['SizeZ'], sizeT=MetaInfo['SizeT']) # save the registered stack savepath_stack = ExportTools.savedata(stack, outputimagepath, extension=saveformat, replace=True) stack.close() log.info('SavePath Registered Stack : ' + savepath_stack) # read the registered stack