# 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.getSubpixelPeaks()

# 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(), 'd')
# 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, int(p[0]), int(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,
Exemplo n.º 2
0
table.show("Embryo intensities at peaks")

# Now show an image with white circles for every embryo found
# We'll use a sparse image: an image that doesn't have a data point for each pixel
# but instead has a function for generating pixel data from the x,y coordinates of each embryo

from net.imglib2 import KDTree, RealPoint, RealRandomAccess, RealRandomAccessible
from net.imglib2.neighborsearch import NearestNeighborSearchOnKDTree
from net.imglib2.img.display.imagej import ImageJFunctions as IL
from net.imglib2.type.numeric.integer import UnsignedByteType
from java.util import AbstractList

inside = UnsignedByteType(255)
outside = UnsignedByteType(0)
radius = 30  # = sigmaLarger, where sigmaLarger is the radius of the embryo
centers = dog.getSubpixelPeaks()  # in floating-point coordinates


class ConstantValueList(AbstractList):
    def __init__(self, constantvalue, count):
        self.constantvalue = constantvalue
        self.count = count

    def get(self, index):
        return self.constantvalue

    def size(self):
        return self.count


kdtree = KDTree(ConstantValueList(inside, len(centers)), centers)
from net.imglib2.neighborsearch import NearestNeighborSearchOnKDTree
from net.imglib2.img.display.imagej import ImageJFunctions as IL
from net.imglib2.type.numeric.integer import UnsignedByteType
from java.util import AbstractList

# The difference of Gaussian calculation, same as above (compressed)
# (or, paste this script under the script above where 'dog' is defined)
imp = IJ.openImage("https://imagej.nih.gov/ij/images/embryos.jpg")
IJ.run(imp, "8-bit", "")
img = IL.wrapReal(imp)
imgE = Views.extendMirrorSingle(img)
dog = DogDetection(imgE, img, [1.0, 1.0], 15.0, 30.0,
                   DogDetection.ExtremaType.MAXIMA, 10, False)

# The spatial coordinates for the centers of all detected embryos
centers = dog.getSubpixelPeaks()  # in floating-point precision

# A value for the inside of an embryo: white, in 8-bit
inside = UnsignedByteType(255)

# A value for the outside (the background): black, in 8-bit
outside = UnsignedByteType(0)

# The radius of a simulated embryo, same as sigmaLarger was above
radius = 30  # or = sigmaLarger

# KDTree: a data structure for fast spatial look up
kdtree = KDTree([inside] * len(centers), centers)


# The definition of circles (or spheres, or hyperspheres) in space