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
示例#2
0
def run(imagefile):

    # Opening the image
    log.info('Opening Image: ' + imagefile)

    # open image file and get a specific series
    #imps, MetaInfo = ImportTools.openfile(imagefile)
    imp, MetaInfo = ImportTools.openfile(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 ...')

    # extend borders
    log.info('Border Extension ...')
    # create BorderManager and add Zeros in all dimensions
    bmType = BorderManager3D.Type.fromLabel("BLACK")
    bm = bmType.createBorderManager(imp.getStack())
    BorderExt = ExtendBordersPlugin()
    # extend border by always exb
    imp = BorderExt.process(imp.getStack(), EXB, EXB, EXB, EXB, EXB, EXB, bm)
    # convert back to ImgPlus
    pastack = ImagePlus('Particles', imp)

    # check for pixel in 3d by size
    log.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.info('Labels Filtered : ' + str(len(labels)))

    # run 3D particle analysis
    log.info('3D Particle Analysis ...')
    PA3d = ParticleAnalysis3DPlugin()
    results = PA3d.process(pastack)

    # colorize the labels
    if LABEL_COLORIZE:
        log.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)

        #log.info('Type lut : ' + str(type(lut)))
        #  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
stackopt=True
method='Otsu'
background_threshold = 'dark'
#imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/3d_nuclei_image_holes_T.ome.tiff"
#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()



示例#4
0
setflatres = True
# select the desired pyramid level - level=0 for full resolution
readpylevel = 0
setconcat = True
openallseries = True
showomexml = False
attach = False
autoscale = True
verbose = 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))


# do the processing
log.info('Start Processing ...')

if extract_channel:
    imp = MiscTools.splitchannel(imp, channelindex)
示例#5
0
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
示例#6
0
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
示例#7
0
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
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
示例#9
0
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
示例#10
0
log.log(LogLevel.INFO, 'Filename              : ' + imagefile)
log.log(LogLevel.INFO, '-----------------------------------------')
log.log(LogLevel.INFO, 'Stitch Tiles          : ' + str(STITCHTILES))
log.log(LogLevel.INFO, 'Pyramid Level [0-...] : ' + str(READPYLEVEL))
log.log(LogLevel.INFO, 'Concatenate Series    : ' + str(SETCONCAT))
log.log(LogLevel.INFO, 'Open all Series       : ' + str(OPENALLSERIES))
log.log(LogLevel.INFO, 'Show OME-XML          : ' + str(SHOWOMEXML))
log.log(LogLevel.INFO, 'Open Attachment       : ' + str(ATTACH))
log.log(LogLevel.INFO, 'Autosale Image        : ' + str(AUTOSCALE))

# read the CZI image
imp, metainfo = ImportTools.openfile(imagefile,
                                     stitchtiles=STITCHTILES,
                                     setflatres=setflatres,
                                     readpylevel=READPYLEVEL,
                                     setconcat=SETCONCAT,
                                     openallseries=OPENALLSERIES,
                                     showomexml=SHOWOMEXML,
                                     attach=ATTACH,
                                     autoscale=AUTOSCALE)

# show the CZI image
imp.show()

# show the metadata
log.log(LogLevel.INFO, '------   CZI METADATA INFORMATION   -----')

# order the metadata dictionary
metainfo_ordered = MetaData.order_metadict(metainfo)

for k, v in metainfo_ordered.items():
示例#11
0
def run(imagefile):

    # Opening the image
    log.info('Opening Image: ' + imagefile)

    # open image file and get a specific series
    imp, MetaInfo = ImportTools.openfile(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']))
    if 'SizeC' in MetaInfo:
        log.info('Channel Count    : ' + str(MetaInfo['SizeC']))

    # do the processing
    log.info('Start Processing ...')

    # get the correct channel
    if MetaInfo['SizeC'] > 1:
        log.info('Extract Channel  : ' + str(MetaInfo['ChannelCount']))
        imps = ChannelSplitter.split(imp)
        imp = imps[CHINDEX - 1]

    # convert to 8bit grayscale
    ic = ImageConverter(imp)
    ic.convertToGray8()

    if FILL_HOLES:
        # 3D fill holes
        log.info('3D Fill Holes ...')
        imp = Reconstruction3D.fillHoles(imp.getImageStack())

    if not FILL_HOLES:
        imp = imp.getImageStack()

    # run watershed on stack
    weights = ChamferWeights3D.BORGEFORS.getFloatWeights()
    normalize = True
    dynamic = 2
    connectivity = LABEL_CONNECT
    log.info('Applying 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.info('Applying 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.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.info('Labels Filtered : ' + str(len(labels)))

    # run 3D particle analysis
    log.info('3D Particle Analysis ...')
    PA3d = ParticleAnalysis3DPlugin()
    results = PA3d.process(pastack)

    # colorize the labels
    if LABEL_COLORIZE:

        log.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