Example #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()
Example #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():
Example #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()  
Example #4
0
from script.imglib.math import Compute, Subtract, Multiply
from script.imglib.color import Red, Blue, RGBA
from script.imglib.algorithm import Gauss, Dither
from script.imglib import ImgLib
from ij import IJ

# Obtain a color image from the ImageJ samples
clown = ImgLib.wrap(IJ.openImage("https://imagej.nih.gov/ij/images/clown.jpg"))

# Example 1: compose a new image manipulating the color channels of the clown image:
img = RGBA(Gauss(Red(clown), 10), 40, Multiply(255,
                                               Dither(Blue(clown)))).asImage()
print type(img)
ImgLib.wrap(img).show()
# Correct gamma
from script.imglib.math import Min, Max, Exp, Multiply, Divide, Log
from script.imglib.color import RGBA, Red, Green, Blue
from ij import IJ
from script.imglib import ImgLib 

gamma = 0.5
# img = ImgLib.wrap(IJ.getImage())
img = ImgLib.wrap(IJ.openImage("https://imagej.nih.gov/ij/images/clown.jpg"))  
ImgLib.wrap(img).show()

def g(channel, gamma):
    """ Return a function that, when evaluated, computes the gamma 
        of the given color channel. 
        If 'i' was the pixel value, then this function would do: 
        double v = Math.exp(Math.log(i/255.0) * gamma) * 255.0); 
        if (v < 0) v = 0; 
        if (v >255) v = 255; 
    """  
    return Min(255, Max(0, Multiply(Exp(Multiply(gamma, Log(Divide(channel, 255)))), 255)))  

corrected = RGBA(g(Red(img), gamma), g(Green(img), gamma), g(Blue(img), gamma)).asImage() 

ImgLib.wrap(corrected).show()