def dog_detection(overlay,img, imp, cal): # Create a variable of the correct type (UnsignedByteType) for the value-extended view zero = img.randomAccess().get().createVariable() # Run the difference of Gaussian cell = 8.0 # microns in diameter min_peak = 2.0 # min intensity for a peak to be considered dog = DogDetection(Views.extendValue(img, zero), img, [cal.pixelWidth, cal.pixelHeight,cal.pixelDepth], cell / 2, cell, DogDetection.ExtremaType.MINIMA, min_peak, False, DoubleType()) peaks = dog.getPeaks() roi = OvalRoi(0, 0, cell/cal.pixelWidth, cell/cal.pixelHeight) print ('Number of cells = ', len(peaks)) p = zeros(img.numDimensions(), 'i') boundRect = imp.getRoi() for peak in peaks: # Read peak coordinates into an array of integers XYZ location of spots peak.localize(p) print(p) if(boundRect is not None and boundRect.contains(p[0], p[1])): oval = OvalRoi(p[0], p[1],cell/cal.pixelWidth, cell/cal.pixelHeight) oval.setColor(Color.RED) overlay.add(oval)
def circle_roi(cs, r, color): # type: (CellStack, int, Color) -> None """ Draw a circle roi with center and radius of the cell """ d = r * 2 x, y = cs.center[0] - r, cs.center[1] - r roi = OvalRoi(x, y, d, d) roi.setColor(color) cs.setRoi(roi)
zero = img.randomAccess().get().createVariable() # Run the difference of Gaussian cell = 30.0 # microns in diameter min_peak = 10.0 # min intensity for a peak to be considered dog = DogDetection( Views.extendValue(img, zero), img, [cal.pixelWidth, cal.pixelHeight], cell / 2, cell, DogDetection.ExtremaType.MAXIMA, #MAXIMA min_peak, False, DoubleType()) peaks = dog.getPeaks() roi = OvalRoi(0, 0, cell / cal.pixelWidth, cell / cal.pixelHeight) print('Number of cells = ', len(peaks)) p = zeros(img.numDimensions(), 'i') overlay = Overlay() imp.setOverlay(overlay) for peak in peaks: # Read peak coordinates into an array of integers peak.localize(p) if (boundRect.contains(p[0], p[1])): oval = OvalRoi(p[0], p[1], cell / cal.pixelWidth, cell / cal.pixelHeight) oval.setColor(Color.RED) overlay.add(oval)