def find_peaks(imp1, imp2, sigmaSmaller, sigmaLarger, minPeakValue): # FIND PEAKS # sigmaSmaller ==> Size of the smaller dots (in pixels) # sigmaLarger ==> Size of the bigger dots (in pixels) # minPeakValue ==> Intensity above which to look for dots # Preparation Neuron channel ip1_1 = IL.wrapReal(imp1) ip1E = Views.extendMirrorSingle(ip1_1) imp1.show() #Preparation Glioma channel ip2_1 = IL.wrapReal(imp2) ip2E = Views.extendMirrorSingle(ip2_1) imp2.show() calibration = [1.0 for i in range(ip1_1.numDimensions())] extremaType = DogDetection.ExtremaType.MINIMA normalizedMinPeakValue = False dog_1 = DogDetection(ip1E, ip1_1, calibration, sigmaSmaller, sigmaLarger, extremaType, minPeakValue, normalizedMinPeakValue) dog_2 = DogDetection(ip2E, ip2_1, calibration, sigmaSmaller, sigmaLarger, extremaType, minPeakValue, normalizedMinPeakValue) peaks_1 = dog_1.getPeaks() peaks_2 = dog_2.getPeaks() return ip1_1, ip2_1, peaks_1, peaks_2
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)
# Parameters for a Difference of Gaussian to detect embryo positions calibration = [1.0 for i in range(img.numDimensions())] # no calibration: identity sigmaSmaller = 15 # in pixels: a quarter of the radius of an embryo sigmaLarger = 30 # pixels: half the radius of an embryo extremaType = DogDetection.ExtremaType.MAXIMA minPeakValue = 10 normalizedMinPeakValue = False # In the differece of gaussian peak detection, the img acts as the interval # within which to look for peaks. The processing is done on the infinite imgE. dog = DogDetection(imgE, img, calibration, sigmaSmaller, sigmaLarger, extremaType, minPeakValue, normalizedMinPeakValue) peaks = dog.getPeaks() # Create a PointRoi from the DoG peaks, for visualization roi = PointRoi(0, 0) # A temporary array of integers, one per dimension the image has p = zeros(img.numDimensions(), 'i') # Load every peak as a point in the PointRoi for peak in peaks: # Read peak coordinates into an array of integers peak.localize(p) roi.addPoint(imp, p[0], p[1]) imp.setRoi(roi) # Now, iterate each peak, defining a small interval centered at each peak, # and measure the sum of total pixel intensity,