Skip to content

Instantly share code, notes, and snippets.

@hirokai
Last active August 29, 2015 14:16
Show Gist options
  • Save hirokai/a97446b6d6d61848dc53 to your computer and use it in GitHub Desktop.
Save hirokai/a97446b6d6d61848dc53 to your computer and use it in GitHub Desktop.
Auto cell detection by RICM, for 20150206 FC1 fixed
# auto_detect.py
from ij import IJ
from ij.plugin import ImageCalculator
IJ.run("Close All")
IJ.run("Stack From List...", "open=/Users/hiroyuki/Desktop/images.txt")
IJ.run("Gaussian Blur...", "sigma=5 stack")
imp = IJ.getImage()
imp.setTitle("all")
def statistics():
# How many points are in our dataset?
num_points = 10
# For each of those points how many dimensions do they have?
dimensions = 2
# Bounds for the values of those points in each dimension
lower = 0
upper = 200
# The K in k-means. How many clusters do we assume exist?
num_clusters = 3
# When do we say the optimization has 'converged' and stop updating clusters
opt_cutoff = 0.5
# Generate some points
points = [kmeans.makeRandomPoint(dimensions, lower, upper) for i in xrange(num_points)]
# Cluster those data!
clusters = kmeans.kmeans(points, num_clusters, opt_cutoff)
# Print our clusters
for i,c in enumerate(clusters):
for p in c.points:
print " Cluster: ", i, "\t Point :", p
def detect(original,fr,to,count):
IJ.run(original,"Slice Keeper", "first=%d last=%d increment=1"%(fr,to))
imp = IJ.getImage()
name = 'kept%d'%count
imp.setTitle(name)
IJ.run("Invert", "stack")
IJ.run("Z Project...", "projection=[Average Intensity]")
ave = IJ.getImage()
IJ.selectWindow(name)
res = ImageCalculator().run("Subtract create stack", imp, ave)
# IJ.selectWindow("Result of kept1")
IJ.run(res,"Auto Threshold", "method=Otsu white stack")
IJ.run(res,"Invert", "stack")
IJ.run(res,"Set Measurements...", "centroid stack redirect=None decimal=3")
IJ.run(res,"Analyze Particles...", "size=100-Infinity display stack")
res.show()
detect(imp,1,21,1)
detect(imp,22,39,2)
detect(imp,40,62,3)
detect(imp,63,87,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment