Esempio n. 1
0
def analyze_cells(imp, size, i, zmin):

	test = []
	cdf = []

	#ip = imp.getProcessor()
	#print "grabbing image..."
	#test = ip.getHistogram()
	#test =  StackStatistics(imp).getHistogram()
	#print "calculating stack statistics..."
	#total = sum(test)
	#print "calculate threshold"
	#cdf = map(lambda x: x/float(total), acc(test))
	#thresh =  min(filter(lambda x: cdf[x] >= quantile, xrange(1,len(cdf)) ))

	max_int = StackStatistics(imp).max
	cal= imp.getCalibration()
	scale2D = cal.pixelWidth / cal.pixelDepth
	sigma = (size / cal.pixelWidth) * scale2D
	iso = Compute.inFloats(Scale2D(ImgLib.wrap(imp),scale2D))
	peaks = DoGPeaks(iso, sigma, sigma * 0.5, thresh, 1)
	print "FOund", len(peaks), "peaks"

	ps = []
	file = open(folder+str(i).zfill(4)+'_test_out.csv','w')
	exporter = csv.writer(file)

	for peak in peaks:
		if peak[2]>=zmin:
			print "raw",peak
			p = Point3f(peak)
			p.scale(cal.pixelWidth * 1/scale2D)
			print "sf", cal.pixelWidth * 1/scale2D
			print "scaled", p
			ps.append(p)
			t = ()
			exporter.writerow([p.x, p.y, p.z])

	file.close()

	if vis:
		iso = Compute.inFloats(Scale2D(Red(ImgLib.wrap(imp)),scale2D))
		univ = Image3DUniverse(512,512)
		univ.addIcospheres(ps,Color3f(1,0,0), 2, size/2, "Cells").setLocked(True)
		univ.addOrthoslice(imp).setLocked(True)
		univ.show()
Esempio n. 2
0
from net.imglib2.img.display.imagej import ImageJFunctions
from net.imglib2.view import Views
from itertools import imap
from java.lang import System
from net.imglib2.roi import EllipseRegionOfInterest
from net.imglib2 import Point, RealPoint

cell_diameter = 5  # in microns
minPeak = 40  # The minimum intensity for a peak to be considered so.
imp = IJ.getImage(
)  #IJ.openImage("http://pacific.mpi-cbg.de/samples/first-instar-brain.zip")

# Scale the X,Y axis down to isotropy with the Z axis
cal = imp.getCalibration()
scale2D = cal.pixelWidth / cal.pixelDepth
iso = Compute.inFloats(Scale2D(Red(ImgLib.wrap(imp)), scale2D))
#ImgLib.wrap(iso).show()

# Find peaks by difference of Gaussian
sigma = (cell_diameter / cal.pixelWidth) * scale2D
peaks = DoGPeaks(iso, sigma, sigma * 0.5, minPeak, 1)
print "Found", len(peaks), "peaks"

# Copy ImgLib1 iso image into ImgLib2 copy image
copy = ArrayImgFactory().create(
    [iso.getDimension(0),
     iso.getDimension(1),
     iso.getDimension(2)], FloatType())
c1 = iso.createCursor()
c2 = copy.cursor()
while c1.hasNext():
Esempio n. 3
0
from script.imglib.math import Compute, Subtract
from script.imglib.color import Red, Green, Blue, RGBA
from script.imglib import ImgLib
from ij import IJ 

# RGB image stack 열기
imp = IJ.openImage("https://imagej.nih.gov/ij/images/flybrain.zip")  

# Wrap it as an Imglib image
img = ImgLib.wrap(imp)

# Example 1: subtract red from green channel
sub = Compute.inFloats(Subtract(Green(img), Red(img)))
ImgLib.wrap(sub).show()

# Example 2: subtract red from green channel, and compose a new RGBA image  
rgb = RGBA(Red(img), Subtract(Green(img), Red(img)), Blue(img)).asImage()  
  
ImgLib.wrap(rgb).show()  
Esempio n. 4
0
# 1. Open an image
imp = IJ.openImage("https://imagej.nih.gov/ij/images/bridge.gif")
ti = imp.getShortTitle()
img = ImgLib.wrap(imp)

# 2. Simulate a brighfield from a Gauss with a large radius
# (First scale down by 4x, then gauss of radius=20, then scale up)
brightfield = Resample(Gauss(Scale2D(img, 0.25), 20), img.getDimensions())

# 3. Simulate a perfect darkfield
darkfield = 0

# 4. Compute the mean pixel intensity value of the image
mean = reduce(lambda s, t: s + t.get(), img, 0) / img.size()

# 5. Correct the illumination
corrected = Compute.inFloats(Multiply(Divide(Subtract(img, brightfield),
                                             Subtract(brightfield, darkfield)), mean))

# 6. ... and show it in ImageJ - it needs to be scaled. This is a 32 bit image
ImgLib.wrap(corrected).show()

# 7. JRM get the displayed image 
imp_new = WindowManager.getCurrentImage()
IJ.run(imp_new, "Enhance Contrast", "saturated=0.35")
# JRM: this will change with input image type...
IJ.run(imp_new, "8-bit", "")
imp_new.setTitle(ti + "_ff_cor")
imp_new.show()
print("done")
Esempio n. 5
0
def detect_objects_3D(imp, size, i, zmin, zmax):

	test = []
	cdf = []

	IJ.run("3D OC Options", "  nb_of_obj._voxels median_gray_value centroid dots_size=5 font_size=10 store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none");

	#ip = imp.getProcessor()
	#print "grabbing image..."
	#test = ip.getHistogram()
	#test =  StackStatistics(imp).getHistogram()
	#print "calculating stack statistics..."
	#total = sum(test)
	#print "calculate threshold"
	#cdf = map(lambda x: x/float(total), acc(test))
	#thresh =  min(filter(lambda x: cdf[x] >= quantile, xrange(1,len(cdf)) ))



	max_int = StackStatistics(imp).max

	cal= imp.getCalibration()
	scale2D = cal.pixelWidth / cal.pixelDepth
	sigma = (size / cal.pixelWidth) * scale2D


	iso = Compute.inFloats(Scale2D(ImgLib.wrap(imp),scale2D))
	#thresh = 0
	thresh = round(max_int/25.5)
	peaks = DoGPeaks(iso, sigma, sigma * 0.5, thresh, 1)
	ps = []
 #	print max_int
#	for p in peaks:
#		if p[2]>zmin and p[2]<zmax:
#			p2 = Point3f(p)
#			p2.scale(cal.pixelWidth * 1/scale2D)
#			ps.append(p2)


	#ob3d = Counter3D(imp, thresh)
	#peaks = ob3d.getCentroidList()
	print "FOund", len(peaks), "peaks"

	#ps = []
	file = open(folder+exp_name+'/'+'cells/'+str(i).zfill(4)+'_cells.csv','w')
	exporter = csv.writer(file)

#TODO: check consistency of coordinates !

	for peak in peaks:
		print peak[2]
		if peak[2]>=zmin and peak[2]<=zmax:
			#print "raw",peak
			p = Point3f(peak)
			p.scale(cal.pixelWidth * 1./scale2D)
			#print "sf", cal.pixelWidth * 1/scale2D
			#print "scaled", p
			ps.append(p)
			t = ()
			exporter.writerow([p.x, p.y, p.z])

	file.close()
Esempio n. 6
0
from script.imglib.math import Compute, Add, Subtract
from script.imglib.color import HSB, Hue, Saturation, Brightness
from script.imglib import ImgLib
from ij import IJ

# Obtain an image
img = ImgLib.wrap(IJ.openImage("https://imagej.nih.gov/ij/images/clown.jpg"))

# Obtain a new clown, whose hue has been shifted by half
# with the same saturation and brightness of the original
bluey = Compute.inRGBA(
    HSB(Add(Hue(img), 0.5), Saturation(img), Brightness(img)))

print type(Hue(img)), type(Saturation(img)), type(Brightness(img))

ImgLib.wrap(Compute.inFloats(Hue(img))).show()
ImgLib.wrap(Compute.inFloats(Saturation(img))).show()
ImgLib.wrap(Compute.inFloats(Brightness(img))).show()

ImgLib.wrap(bluey).show()
Esempio n. 7
0
imp = WindowManager.getCurrentImage()
#imp = IJ.openImage("http://pacific.mpi-cbg.de/samples/first-instar-brain.zip")

#imageStats = imp.getStatistics()
#imageMin = imageStats.min()
imageMin = imp.MIN_MAX
print 'min:', imageMin

# Scale the X,Y axis down to isotropy with the Z axis
cal = imp.getCalibration()
print '   x/y/z calibration is: ', cal.pixelWidth, cal.pixelHeight, cal.pixelDepth

scale2D = cal.pixelWidth / cal.pixelDepth
print '   calling scale2d'
#iso = Compute.inFloats(Scale2D(Red(ImgLib.wrap(imp)), scale2D))
iso = Compute.inFloats(Scale2D(ImgLib.wrap(imp), scale2D))

# Find peaks by difference of Gaussian
sigma = (cell_diameter  / cal.pixelWidth) * scale2D
print '   starting dogpeaks...'
peaks = DoGPeaks(iso, sigma, sigma * 0.5, minPeak, 1)
print "   Found", len(peaks), "peaks"

# Convert the peaks into points in calibrated image space
if len(peaks)>0:
  ps = []
  for peak in peaks:
    p = Point3f(peak)
    p.scale(cal.pixelWidth * 1/scale2D)
    ps.append(p)