Exemplo n.º 1
0
    def mj_watershed(imp,
                     normalize=True,
                     dynamic=1,
                     connectivity=6):

        # run watershed on stack
        weights = ChamferWeights3D.BORGEFORS.getFloatWeights()
        # calc distance map and invert
        dist = BinaryImages.distanceMap(imp.getStack(), weights, normalize)
        Images3D.invert(dist)
        basins = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp.getStack(), dynamic, connectivity, False)
        imp = ImagePlus("basins", basins)
        ip = imp.getProcessor()
        ip.setThreshold(1, 255, ImageProcessor.NO_LUT_UPDATE)

        return imp
Exemplo n.º 2
0
    def edm_watershed(imp):

        stack = imp.getStack()  # get the stack within the ImagePlus
        nslices = stack.getSize()  # get the number of slices
        for index in range(1, nslices + 1):
            # get the image processor
            ip = stack.getProcessor(index)

            if not ip.isBinary():
                ip = BinaryImages.binarize(ip)
            print('Apply Watershed to Binary image ...')
            print(type(ip))
            print('isBinary : ', ip.isBinary())
            edm = EDM()
            edm.setup("watershed", None)
            edm.run(ip)

        return imp
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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