예제 #1
0
    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 createDoG(img, calibration, sigmaSmaller, sigmaLarger, minPeakValue):
    # Fixed parameters
    extremaType = DogDetection.ExtremaType.MAXIMA
    normalizedMinPeakValue = False
    # Infinite img
    imgE = Views.extendMirrorSingle(img)
    # 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.
    return DogDetection(imgE, img, calibration, sigmaLarger, sigmaSmaller,
                        extremaType, minPeakValue, normalizedMinPeakValue)
예제 #3
0
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
예제 #4
0
파일: cardona_fun.py 프로젝트: zvtrung/tips
# View as an infinite image, mirrored at the edges which is ideal for Gaussians
imgE = Views.extendMirrorSingle(img)

# 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)
예제 #5
0
cal = imp.getCalibration()  # in microns

img = IJF.wrap(imp)

print(img.dimensions)
# Create a variable of the correct type (UnsignedByteType) for the value-extended view
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])):
예제 #6
0
# View as an infinite image, mirrored at the edges which is ideal for Gaussians
imgE = Views.extendMirrorSingle(img)

# 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)
from ij import IJ
from net.imglib2.view import Views
from net.imglib2.algorithm.dog import DogDetection
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

# 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)
예제 #8
0
# A script to find cells by difference of Gaussian using imglib2.
# Uses as an example the "first-instar-brain.tif" RGB stack availalable
# from Fiji's "Open Samples" menu.

from net.imglib2.algorithm.dog import DogDetection
from net.imglib2.type.numeric.real import DoubleType

# Extract the red channel
interval = ops.run("create.img", [img.dimension(0), img.dimension(1), 1, img.dimension(3)], img.firstElement(), img.factory())
red = ops.run("transform.crop", img, interval)

# Create a variable of the correct type (UnsignedByteType) for the value-extended view
extended = ops.run("transform.extendZeroView", red)

# Run the difference of Gaussian
cell = 5.0 # microns in diameter
min_peak = 40.0 # min intensity for a peak to be considered

dog = DogDetection(extended, red,
                   [img.averageScale(0), img.averageScale(1), img.averageScale(3)],
                   cell / 2, cell,
                   DogDetection.ExtremaType.MINIMA,
                   min_peak, False,
                   DoubleType())

peaks = dog.getPeaks()


print len(peaks)
print peaks