Beispiel #1
0
def analyze(imp, min_area):
    MAXSIZE = 1000000000000
    MINCIRCULARITY = 0.0
    MAXCIRCULARITY = 1.
    
    options = PA.SHOW_MASKS 
    
    temp_results = ResultsTable()
    
    p = PA(options, PA.AREA + PA.MEAN, temp_results, min_area, MAXSIZE, MINCIRCULARITY, MAXCIRCULARITY)
    p.setHideOutputImage(True)

    p.analyze(imp)

    if temp_results.getCounter() == 0:
        areas   = []
        signals = []
    else:
        areas   = list(temp_results.getColumn(0))
        signals = list(temp_results.getColumn(1))
    
    count  = len(areas)
    area   = sum(areas)

    total = 0
    if area > 0:
        total  = sum([a*s for a,s in zip(areas, signals)]) / area
      

    return p.getOutputImage(), count, area, total
Beispiel #2
0
def threshold(imPlus, edgeThreshold=2500):
    mask = Duplicator().run(imPlus)
    mask_stk = mask.getStack()

    # First, we threshold based on edges
    IJ.setThreshold(mask, edgeThreshold, 100000, "No Update")
    for i in range(mask.getImageStackSize()):
        mask_stk.getProcessor(i + 1).findEdges()
    IJ.run(mask, "Make Binary", "method=Default background=Default black")

    # Now, we need to clean up the binary images morphologically
    IJ.run(mask, "Dilate", "stack")
    IJ.run(mask, "Fill Holes", "stack")
    IJ.run(mask, "Erode", "stack")
    IJ.run(mask, "Erode", "stack")

    # Finally, remove the small particles
    stk = ImageStack(mask.getWidth(), mask.getHeight())
    p = PA(PA.SHOW_MASKS, 0, None, 200, 100000)
    p.setHideOutputImage(True)
    for i in range(mask_stk.getSize()):
        mask.setSliceWithoutUpdate(i + 1)
        p.analyze(mask)
        mmap = p.getOutputImage()
        stk.addSlice(mmap.getProcessor())

    mask.setStack(stk)
    mask.setSliceWithoutUpdate(1)
    mask.setTitle(mask_title(imPlus.getTitle()))
    mask.show()
    return mask
Beispiel #3
0
    def analyzeParticles(imp, minsize, maxsize, mincirc, maxcirc,
                         filename='Test.czi',
                         addROIManager=True,
                         headless=True,
                         exclude=True):

        if addROIManager is True:

            if exclude is False:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \

            if exclude is True:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        if addROIManager is False:

            if exclude is False:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \

            if exclude is True:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        measurements = PA.STACK_POSITION \
            + PA.LABELS \
            + PA.AREA \
            + PA.RECT \

        results = ResultsTable()
        p = PA(options, measurements, results, minsize, maxsize, mincirc, maxcirc)
        p.setHideOutputImage(True)
        particlestack = ImageStack(imp.getWidth(), imp.getHeight())

        for i in range(imp.getStackSize()):
            imp.setSliceWithoutUpdate(i + 1)
            ip = imp.getProcessor()
            #IJ.run(imp, "Convert to Mask", "")
            p.analyze(imp, ip)
            mmap = p.getOutputImage()
            particlestack.addSlice(mmap.getProcessor())

        return particlestack, results
Beispiel #4
0
def removeSmallCCs(image):

	MINSIZE = 1000
	MAXSIZE = 1000000

	options = PA.SHOW_ROI_MASKS 
			
	
	results = ResultsTable()
	
	p = PA(options, PA.STACK_POSITION + PA.LABELS + PA.AREA + PA.PERIMETER + PA.CIRCULARITY, results, MINSIZE, MAXSIZE)
	p.setHideOutputImage(True)
	p.analyze(image)
	mmap = p.getOutputImage()
	mip = mmap.getProcessor() 
	mip.threshold(0)
	img = ImagePlus("rods_processed", mip)
	IJ.run(img, "8-bit", "") 
	IJ.run(img, "Make Binary", "method=Default background=Dark black")
	

	return img
Beispiel #5
0
    def analyzeParticles(imp,
                         minsize,
                         maxsize,
                         mincirc,
                         maxcirc,
                         #filename='Test.czi',
                         addROIManager=False,
                         #headless=False,
                         exclude=True):

        if GraphicsEnvironment.isHeadless():
            print('Headless Mode detected. Do not use ROI Manager.')
            addROIManager = False

        if addROIManager:

            # get the ROI manager instance
            rm = RoiManager.getInstance()
            if rm is None:
                rm = RoiManager()
            rm.runCommand("Associate", "true")

            if not exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \

            if exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_MANAGER \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        if not addROIManager:

            if not exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \

            if exclude:
                options = PA.SHOW_ROI_MASKS \
                    + PA.SHOW_RESULTS \
                    + PA.DISPLAY_SUMMARY \
                    + PA.ADD_TO_OVERLAY \
                    + PA.EXCLUDE_EDGE_PARTICLES

        measurements = PA.STACK_POSITION \
            + PA.LABELS \
            + PA.AREA \
            + PA.RECT \
            + PA.PERIMETER \
            + PA.SLICE \
            + PA.SHAPE_DESCRIPTORS \
            + PA.CENTER_OF_MASS \
            + PA.CENTROID

        results = ResultsTable()
        p = PA(options, measurements, results, minsize, maxsize, mincirc, maxcirc)
        p.setHideOutputImage(True)
        particlestack = ImageStack(imp.getWidth(), imp.getHeight())

        for i in range(imp.getStackSize()):
            imp.setSliceWithoutUpdate(i + 1)
            ip = imp.getProcessor()
            # convert to a mask for the particle analyzer
            ip.invert()
            # do the particle analysis
            p.analyze(imp, ip)
            mmap = p.getOutputImage()
            # add the slide to the full stack
            particlestack.addSlice(mmap.getProcessor())

        return particlestack, results