doPresmooth=dopresmooth, correctCorners=correct_corners) # filter image if filtertype != 'NONE': log.info('Apply Filter : ' + filtertype) imp = FilterTools.apply_filter(imp, radius=filter_radius, filtertype=filtertype) # apply threshold log.info('Apply Threshold ...') imp = ThresholdTools.apply_threshold(imp, method=threshold_method, background_threshold=threshold_background, stackopt=threshold_stackoption, corrf=threshold_corr) if watershed: imp = WaterShedTools.run_watershed(imp, mj_normalize=True, mj_dynamic=1, mj_connectivity=watershed_connectivity) pastack, results = AnalyzeTools.analyzeParticles(imp, minsize, maxsize, mincirc, maxcirc, filename=imagefile,
def run(imagefile): # Opening the image log.log(LogLevel.INFO, 'Opening Image: ' + imagefile) # open image file and get a specific series imp, MetaInfo = ImportTools.openfile(imagefile) 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 ...') if EXTRACT_CHANNEL: # get the correct channel if MetaInfo['SizeC'] > 1: log.log(LogLevel.INFO, 'Extract Channel : ' + str(CHINDEX)) imps = ChannelSplitter.split(imp) imp = imps[CHINDEX - 1] # correct background using rolling ball if CORRECT_BACKGROUND: log.log(LogLevel.INFO, 'Rolling Ball Background subtraction...') imp = FilterTools.apply_rollingball(imp, radius=RB_RADIUS, createBackground=CREATEBACKGROUND, lightBackground=LIGHTBACKGROUND, useParaboloid=USEPARABOLOID, doPresmooth=DOPRESMOOTH, correctCorners=CORRECTCORNERS) if FILTERDIM == '2D': if RANKFILTER != 'NONE': # apply filter log.log(LogLevel.INFO, 'Apply 2D Filter : ' + RANKFILTER) imp = FilterTools.apply_filter(imp, radius=RADIUS, filtertype=RANKFILTER) if FILTERDIM == '3D': if FILTER3D != 'NONE': # apply filter log.log(LogLevel.INFO, 'Apply 3D Filter : ' + FILTER3D) imp = FilterTools.apply_filter3d(imp, radiusx=RADIUSX, radiusy=RADIUSY, radiusz=RADIUSZ, filtertype=FILTER3D) if THRESHOLD != 'NONE': # apply threshold log.log(LogLevel.INFO, 'Apply Threshold : ' + THRESHOLD) log.log(LogLevel.INFO, 'Correction Factor : ' + str(CORRFACTOR)) imp = ThresholdTools.apply_threshold(imp, method=THRESHOLD, background_threshold='dark', stackopt=TH_STACKOPT, corrf=CORRFACTOR) # imp_t = imp.duplicate() # imp_t.show("Threshold") if FILL_HOLES: # 3D fill holes log.log(LogLevel.INFO, '3D Fill Holes ...') imp = Reconstruction3D.fillHoles(imp.getImageStack()) if not FILL_HOLES: imp = imp.getImageStack() if WATERSHED: # run watershed on stack weights = ChamferWeights3D.BORGEFORS.getFloatWeights() normalize = True dynamic = 2 connectivity = LABEL_CONNECT log.log(LogLevel.INFO, 'Run Watershed to separate particles ...') #dist = BinaryImages.distanceMap(imp.getImageStack(), weights, normalize) dist = BinaryImages.distanceMap(imp, weights, normalize) Images3D.invert(dist) #imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp.getImageStack(), dynamic, connectivity, 32, False ) imp = ExtendedMinimaWatershed.extendedMinimaWatershed( dist, imp, dynamic, connectivity, 32, False) # extend borders log.log(LogLevel.INFO, 'Border Extension ...') # create BorderManager and add Zeros in all dimensions bmType = BorderManager3D.Type.fromLabel("BLACK") bm = bmType.createBorderManager(imp) #bm = bmType.createBorderManager(imp.getStack()) BorderExt = ExtendBordersPlugin() # extend border by always exb #imp = BorderExt.process(imp.getStack(), EXB, EXB, EXB, EXB, EXB, EXB, bm) imp = BorderExt.process(imp, EXB, EXB, EXB, EXB, EXB, EXB, bm) # convert back to ImgPlus pastack = ImagePlus('Particles', imp) # check for pixel in 3d by size log.log(LogLevel.INFO, 'Filtering VoxelSize - Minimum : ' + str(MINVOXSIZE)) pastack = BinaryImages.volumeOpening(pastack.getStack(), MINVOXSIZE) imp = ImagePlus('Particles Filtered', pastack) pastack = BinaryImages.componentsLabeling(imp, LABEL_CONNECT, LABEL_BITDEPTH) # get the labels labels = LabelImages.findAllLabels(pastack) log.log(LogLevel.INFO, 'Labels Filtered : ' + str(len(labels))) # run 3D particle analysis log.log(LogLevel.INFO, '3D Particle Analysis ...') PA3d = ParticleAnalysis3DPlugin() results = PA3d.process(pastack) # colorize the labels if LABEL_COLORIZE: log.log(LogLevel.INFO, 'Colorize Lables ...') #maxLabel = 255 maxLabel = len(labels) bgColor = Color.BLACK shuffleLut = True lutName = CommonLabelMaps.GOLDEN_ANGLE.getLabel() # Create a new LUT from info in dialog lut = CommonLabelMaps.fromLabel(lutName).computeLut( maxLabel, shuffleLut) # Create a new RGB image from index image and LUT options pastack_rgb = LabelImages.labelToRgb(pastack, lut, bgColor) # convert to rgb color IJ.run(pastack_rgb, "RGB Color", "slices") if LABEL_COLORIZE: return pastack_rgb, results, labels elif not LABEL_COLORIZE: return pastack, results, labels
#imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/3d_nuclei_image_holes.ome.tiff" imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/Osteosarcoma_01.ome.tiff" imagefile = r'"C:\Temp\input\Osteosarcoma_01.ome.tiff" corrf = 1.0 if stackopt: thcmd = method + ' ' + background_threshold + ' stack' if not stackopt: thcmd = method + ' ' + background_threshold # open image stack imp, MetaInfo = ImportTools.openfile(imagefile) imp = MiscTools.splitchannel(imp, 3) imp = ThresholdTools.apply_threshold(imp, method=method, background_threshold='dark', stackopt=stackopt, corrf=corrf) imp.show()
def run(imagefile, outputpath_orig, convert_orig2copy=False, sft='ome.tiff', fillholes=True, watershed=True, watershed_connectivity=6, verbose=True): print fillholes, watershed, watershed_connectivity # Opening the image log.info('Opening Image: ' + imagefile) # stitch togehter tiles stitchtiles = True # when set to True the number of pyramid levels can be read setflatres = True # select the desired pyramid level - level=0 for full resolution readpylevel = 0 setconcat = True openallseries = True showomexml = False attach = False autoscale = True # read the image imp, MetaInfo = ImportTools.openfile(imagefile, stitchtiles=stitchtiles, setflatres=setflatres, readpylevel=readpylevel, setconcat=setconcat, openallseries=openallseries, showomexml=showomexml, attach=attach, autoscale=autoscale) if verbose: for k, v in MetaInfo.items(): log.info(str(k) + ' : ' + str(v)) if EXTRACT_CHANNEL: imp = MiscTools.splitchannel(imp, CHINDEX) # optional filtering if FILTERTYPE != 'NONE': log.info('Apply Filter : ' + FILTERTYPE) imp = FilterTools.apply_filter(imp, radius=FILTER_RADIUS, filtertype=FILTERTYPE) # apply threshold log.info('Apply Threshold ...') imp = ThresholdTools.apply_threshold(imp, method=THRESHOLD_METHOD, background_threshold=THRESHOLD_BGRD, stackopt=THRESHOLD_STACKOPTION) print "3D: ", MetaInfo['is3d'] # fill holes if fillholes: imp = BinaryTools.fill_holes(imp, is3d=MetaInfo['is3d']) if watershed: imp = WaterShedTools.run_watershed( imp, mj_normalize=True, mj_dynamic=1, mj_connectivity=watershed_connectivity, is3d=MetaInfo['is3d']) return imp
def run(imagefile): # open image file and get a specific series #imps, MetaInfo = ImportTools.openfile(imagefile) imp, MetaInfo = ImportTools.openfile(imagefile, stitchtiles=True, setflatres=False, readpylevel=PYLEVEL, setconcat=True, openallseries=True, showomexml=False, attach=False, autoscale=True) # Opening the image log.info('Opening Image: ' + imagefile) log.info('File Extension : ' + MetaInfo['Extension']) if 'ResolutionCount' in MetaInfo: log.info('Resolution Count : ' + str(MetaInfo['ResolutionCount'])) if 'SeriesCount' in MetaInfo: log.info('SeriesCount : ' + str(MetaInfo['SeriesCount'])) # get sprecifies image series #log.info('Getting Image Series : ' + str(IMAGESERIES)) #imp = ImageTools.getseries(imps, series=IMAGESERIES) # do the processing log.info('Start Processing ...') if BINFACTOR == 1: imp_p = imp elif BINFACTOR >= 2: # apply binning to reduce the image size log.info('Apply Binning: ' + str(BINFACTOR) + ' Method : ' + BINMETHOD) imp_p = MiscTools.apply_binning(imp, binning=BINFACTOR, method=BINMETHOD) # apply filter log.info('Apply Filter: ' + RANKFILTER) imp_p = FilterTools.apply_filter(imp_p, radius=RADIUS) # convert to 8-bit for the thresholding log.info('Convert to 8-bit ...') IJ.run(imp_p, "8-bit", "") # apply threshold log.info('Apply Threshold: ' + THRESHOLD) imp_p = ThresholdTools.apply_threshold(imp_p, method=THRESHOLD, background_threshold=THRESHOLD_BGRD, corrf=CORRFACTOR) pastack, results = AnalyzeTools.analyzeParticles(imp_p, MINSIZE, MAXSIZE, MINCIRC, MAXCIRC, filename=imagefile, addROIManager=ROIS) # apply suitable LUT to visualize detected particles pastack = ImagePlus('Particles', pastack) IJ.run(pastack, 'glasbey_inverted', '') IJ.run(pastack, 'Enhance Contrast', 'saturated=0.35') return pastack, results
clij.op().automaticThreshold(input, output, threshold_method) # show result clij.pull(output).show() IJ.setMinAndMax(0, 1) end = time.clock() log.info('Duration of Processing CLIJ: ' + str(end - start)) threshold_stackoption = True threshold_background = 'dark' threshold_corr = 1.0 start2 = time.clock() log.info('Apply Threshold ...') th_image = ThresholdTools.apply_threshold(imp, method=threshold_method, background_threshold="dark", stackopt=threshold_stackoption, corrf=threshold_corr) end2 = time.clock() log.info('Duration of Processing Fiji: ' + str(end2 - start2)) # finish log.info('Done.') th_image.show()
IJ.setAutoThreshold(imp, "Otsu dark stack") ip = imp.getProcessor() hist = ip.getHistogram() lowth = ip.getMinThreshold() lowth_corr = int(round(lowth * corrf, 0)) print('Low Threshold : ' + str(lowth)) print('Low Threshold Corr : ' + str(lowth_corr)) # process stack with corrected threshold value if corrf <> 1.0: print('Using corrected threshold value.') imp = threshold_stack(imp, lowth_corr) if mt == 'slice': # get the stacks stack, nslices = ImageTools.getImageStack(imp) print('Threshold slice-by-slice') for index in range(1, nslices + 1): ip = stack.getProcessor(index) # get the histogramm hist = ip.getHistogram() # get the threshold value lowth_corr = ThresholdTools.apply_autothreshold(hist, corrf=corrf, method=method) ip.threshold(lowth_corr) imp.show()
def run(imagefile, outputpath_orig, convert_orig2copy=False, sft='ome.tiff', verbose=False): # Opening the image log.info('Opening Image: ' + imagefile) # stitch togehter tiles stitchtiles = True # when set to True the number of pyramid levels can be read setflatres = True # select the desired pyramid level - level=0 for full resolution readpylevel = 0 setconcat = True openallseries = True showomexml = False attach = False autoscale = True # read the image imp, MetaInfo = ImportTools.openfile(imagefile, stitchtiles=stitchtiles, setflatres=setflatres, readpylevel=readpylevel, setconcat=setconcat, openallseries=openallseries, showomexml=showomexml, attach=attach, autoscale=autoscale) if convert_orig2copy: log.info('Detected Extension : ' + MetaInfo['Extension']) # check if it was already an OME-TIFF based on the file extension ft = ['.ome.tif', '.ome.tiff'] if MetaInfo['Extension'] in ft: """ # just copy the original file new_path = '/output/' + os.path.basename(imagefile) command = 'cp ' + imagefile + ' ' + new_path log.info('Copy Original file without conversion to output folder') os.popen(command) """ # just copy the original file new_path = '/output/' + os.path.basename(IMAGEPATH) copy_ok = copyorig(IMAGEPATH, new_path, force_overwrite=True) log.info(copy_ok) if MetaInfo['Extension'] not in ft: log.info('Converting original to OME-TIFF and save to output folder.') savepath_orig = ExportTools.savedata(imp, outputpath_orig, extension=sft, replace=True) log.info('Saving converted original image : ' + savepath_orig) if verbose: for k, v in MetaInfo.items(): log.info(str(k) + ' : ' + str(v)) # do the processing log.info('Start Processing ...') if EXTRACT_CHANNEL: imp = MiscTools.splitchannel(imp, CHINDEX) # correct background if CORRECT_BACKGROUND: log.info('Removing Background using Rolling Ball ...') imp = FilterTools.apply_rollingball(imp, radius=RB_RADIUS, createBackground=CREATEBACKGROUND, lightBackground=LIGHTBACKGROUND, useParaboloid=USEPARABOLOID, doPresmooth=DOPRESMOOTH, correctCorners=CORRECTCORNERS) # optional filtering if FILTERTYPE != 'NONE': log.info('Apply Filter : ' + FILTERTYPE) imp = FilterTools.apply_filter(imp, radius=FILTER_RADIUS, filtertype=FILTERTYPE) # apply threshold log.info('Apply Threshold ...') imp = ThresholdTools.apply_threshold(imp, method=THRESHOLD_METHOD, background_threshold=THRESHOLD_BGRD, stackopt=THRESHOLD_STACKOPTION) #ip = imp.getProcessor() #ip = ip.convertToByte(False) #imp.setProcessor(ip) #ImageConverter.setDoScaling(False) #ImageConverter(imp).convertToGray8() #imp.show() #ImageConverter.setDoScaling(True); #IJ.run(imp, "8-bit", ""); #IJ.run(imp, "Enhance Contrast", "saturated=0.35"); """ # run watershed on stack weights = ChamferWeights3D.BORGEFORS.getFloatWeights() normalize = True dynamic = 2 connectivity = 26 ImageConverter(imp).convertToGray8() try: dist = BinaryImages.distanceMap(imp, weights, normalize) except: dist = BinaryImages.distanceMap(imp.getImageStack(), weights, normalize) Images3D.invert(dist) #imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp.getImageStack(), dynamic, connectivity, 32, False ) try: imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp, dynamic, connectivity, 32, False) except: imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp.getImageStack(), dynamic, connectivity, 32, False) """ """ pastack, results = AnalyzeTools.analyzeParticles(imp, MINSIZE, MAXSIZE, MINCIRC, MAXCIRC, filename=imagefile, addROIManager=ROIS) # apply suitable LUT to visualize particles pastack = ImagePlus('Particles', pastack) IJ.run(pastack, 'glasbey_inverted', '') IJ.run(pastack, 'Enhance Contrast', 'saturated=0.35') return imp, pastack, results """ return imp