def draw_classes(inputfile,data): pathname,filename = os.path.split(inputfile) # last subdir is for well ## TODO ## support multiple plates, read plate and well from csv well = os.path.basename(pathname) # create output directory outputdir = os.path.join(OUTPUTROOT,well) if not os.path.isdir(outputdir): os.makedirs(outputdir) # create output filename head,tail = os.path.splitext(filename) outputfilename = head + "_classes" + tail outputfilename = os.path.join(outputdir,outputfilename) print outputfilename imp = IJ.openImage(inputfile).duplicate() IJ.run(imp,"RGB Color","") for d in data: x = int(float(d[0])) y = int(float(d[1])) c = int(float(d[2])) classname = classes[str(c)] colorname = colors[classname] color = colormap[colorname] #print colorname roi = PointRoi(x,y) roi.setDefaultMarkerSize("Large") roi.setStrokeColor(colormap[colorname]) imp.getProcessor().drawRoi(roi) IJ.saveAs(imp,"png",outputfilename)
def draw_centers(data): pathname = data[1] filename = data[2] platename = data[3] print data[4] nx = int(data[4]) ny = int(data[5]) nx_com = int(data[6]) ny_com = int(data[7]) ax = int(data[8]) ay = int(data[9]) orientation = 2*math.pi * float(data[10]) / 360.0 line_dy = int(round(math.atan(orientation) * LINE_DX)) ax2 = ax - LINE_DX ay2 = ay - line_dy orientation_avg = 2*math.pi * float(data[11]) / 360.0 line_dy = int(round(math.atan(orientation_avg) * LINE_DX)) ax3 = ax - LINE_DX ay3 = ay - line_dy imp = IJ.openImage(os.path.join(pathname,filename)) roi_nucleus = PointRoi(nx,ny) roi_nucleus.setDefaultMarkerSize("Large") roi_nucleus.setStrokeColor(Color.CYAN) roi_nucleus_com = PointRoi(nx_com,ny_com) roi_nucleus_com.setDefaultMarkerSize("Large") roi_nucleus_com.setStrokeColor(Color.GREEN) roi_anchor = PointRoi(ax,ay) roi_anchor.setDefaultMarkerSize("Large") imp.getProcessor().drawRoi(roi_nucleus) imp.getProcessor().drawRoi(roi_nucleus_com) imp.getProcessor().drawRoi(roi_anchor) imp.setColor(Color.RED) imp.getProcessor().drawLine(ax,ay,ax2,ay2) imp.setColor(Color.WHITE) imp.getProcessor().drawLine(ax,ay,ax3,ay3) IJ.saveAsTiff(imp,os.path.join(pathname,filename))
def processOneImage(inputDir): tmp = glob.glob(os.path.join(inputDir, "fibrone*")) fibronectin = tmp[0] tmp = glob.glob(os.path.join(inputDir, "nucleus*")) nucleus = tmp[0] tmp = glob.glob(os.path.join(inputDir, "actin*")) actin = tmp[0] # read sample name head,tail = os.path.split(inputDir) sample = tail.replace(".tif_Files","") # original images imp_fn_orig = IJ.openImage(fibronectin) imp_nuc_orig = IJ.openImage(nucleus) # work copies imp_fn = imp_fn_orig.duplicate() imp_nuc = imp_nuc_orig.duplicate() IJ.run(imp_fn,"Set Scale...", "distance=1 known=1 pixel=1 unit=pixels") IJ.run(imp_fn,"Gaussian Blur...","sigma=5") IJ.run(imp_fn,"Make Binary","") IJ.run(imp_nuc,"Set Scale...", "distance=1 known=1 pixel=1 unit=pixels") IJ.run(imp_nuc,"Gaussian Blur...","sigma=5") IJ.run(imp_nuc,"Make Binary","") # get moments of the fibronectin image moments_file = os.path.join(OUTPUT, sample + " moments.txt") printMoments(fibronectin, moments_file) moments = readMoments(moments_file) print moments.m00 sys.exit() # centroid of fibronectin anchor centers = getParticleCenters(imp_fn) cxfn = int(round(centers[0][0])) cyfn = int(round(centers[1][0])) fn_centroid_roi = PointRoi(cxfn,cyfn) fn_centroid_roi.setDefaultMarkerSize("Large") fn_centroid_roi.setStrokeColor(Color.CYAN) # center of mass of nucleus centers = getParticleCenters(imp_nuc) cxnuc = int(round(centers[2][0])) cynuc = int(round(centers[3][0])) nuc_com_roi = PointRoi(cxnuc,cynuc) nuc_com_roi.setDefaultMarkerSize("Large") # skeletonize fibronectin anchor to find its orientation IJ.run(imp_fn,"Skeletonize","") skel = AnalyzeSkeleton_() skel.setup("",imp_fn) skelResult = skel.run(skel.NONE, False, True, None, True, True) graph = skelResult.getGraph() print len(graph) print skelResult.getNumOfTrees() # find the longest graph graph = sorted(graph, key=lambda g: getGraphLength(g), reverse=True) graph = graph[0] edges = graph.getEdges() # find longest edge, the main axis of the anchor edges = sorted(edges, key=lambda edge: edge.getLength(), reverse=True) #for e in edges: # print e.getLength() v1long = edges[0].getV1() v2long = edges[0].getV2() x1 = v1long.getPoints()[0].x y1 = v1long.getPoints()[0].y x2 = v2long.getPoints()[0].x y2 = v2long.getPoints()[0].y anchor_roi = PointRoi(x1,y1) anchor_roi = anchor_roi.addPoint(x2,y2) # find top and bottom vertices of the graph vertices = graph.getVertices() vertices = sorted(vertices, key=lambda vertex: vertex.getPoints()[0].y) v1short = vertices[len(vertices)-1] v2short = vertices[0] x3 = v1short.getPoints()[0].x y3 = v1short.getPoints()[0].y x4 = v2short.getPoints()[0].x y4 = v2short.getPoints()[0].y anchor_roi = anchor_roi.addPoint(x3,y3) anchor_roi = anchor_roi.addPoint(x4,y4) # calculate angles a1 = math.atan(abs(float(y2-y1)/float(x2-x1))) / math.pi * 360 a2 = math.atan(abs(float(x4-x3)/float(y4-y3))) / math.pi * 360 amean = float((a1+a2)/2) dx = cxfn-cxnuc print sample,cxfn,cyfn,cxnuc,cynuc,dx,math.cos(amean)*dx,x1,y1,x2,y2,x3,y3,x4,y4,a1,a2 # create composite comp = ImagePlus("composite",imp_nuc_orig.getProcessor().convertToColorProcessor()) comp.getProcessor().setChannel(2,imp_fn_orig.getProcessor()) comp.getProcessor().setChannel(3,imp_fn.getProcessor()) comp.show() comp.getProcessor().drawRoi(fn_centroid_roi) comp.getProcessor().drawRoi(nuc_com_roi) comp.getProcessor().drawRoi(anchor_roi) comp.repaintWindow() IJ.saveAsTiff(comp, os.path.join(OUTPUT,sample + ".tif"))