Last active
August 29, 2015 13:57
-
-
Save nebuta/9556354 to your computer and use it in GitHub Desktop.
Data processing on Fiji using Jython and a remote server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib, urllib, marshal | |
def getVal(table, i): | |
x = table.getValue('X', i) | |
y = table.getValue('Y', i) | |
return [x, y] | |
def draw_triangles(imp, triangles): | |
ip = imp.getProcessor() | |
for tri in triangles: | |
ip.drawLine(int(tri[0]), | |
int(tri[1]), | |
int(tri[2]), | |
int(tri[3])) | |
def delaunay(coords): | |
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} | |
params = urllib.urlencode({'data': coords, 'json': 0}) | |
host = "localhost:3000" | |
conn = httplib.HTTPConnection(host) | |
print "connected" | |
conn.request("POST", "/programming/delaunay", params, headers) | |
r = conn.getresponse() | |
# print r1.status, r1.reason | |
result = r.read() | |
ls = result.split("\n") | |
vs = [map(float,l.split(",")) for l in ls] | |
conn.close() | |
return vs | |
# imp is a thresholded image (binary image). | |
def find_dots(imp): | |
IJ.run(imp, "Set Measurements...", " centroid redirect=None decimal=2") | |
IJ.run(imp, "Analyze Particles...", "size=20-Infinity circularity=0.00-1.00 show=Ellipses display clear") | |
# Get a Results table. This content can be shown from Window -> Results | |
table = ResultsTable.getResultsTable() | |
# Get the number of rows. | |
n = table.getCounter() | |
# Call getVal to get every (x,y) coordinate. | |
return [getVal(table, i) for i in range(0, n)] | |
def threshold(imp): | |
imp2 = imp.duplicate() | |
ip2 = imp2.getProcessor() | |
IJ.run(imp2, "Auto Threshold", "method=RenyiEntropy white") | |
IJ.run(imp2, "Convert to Mask", "") | |
return imp2 | |
def main(): | |
imp = IJ.getImage() | |
th_imp = threshold(imp) | |
coords = find_dots(th_imp) | |
imp_ps = IJ.getImage() | |
triangles = delaunay(coords) | |
# print triangles | |
draw_triangles(imp_ps,triangles) | |
# Show an original image and a thresholded image. | |
imp_ps.repaintWindow() | |
# th_imp.show() | |
print "Done" | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment