# Create a copy of the image.
input_image_plus_copy = input_image_plus.duplicate()
image_processor_copy = input_image_plus_copy.getProcessor()

try:
    # Set binary options.
    options = jython_utils.get_binary_options(
        black_background=black_background)
    IJ.run(input_image_plus_copy, "Options...", options)

    # Convert image to binary if necessary.
    if not image_processor_copy.isBinary():
        IJ.run(input_image_plus_copy, "Make Binary", "")

    # Run AnalyzeSkeleton
    analyze_skeleton = AnalyzeSkeleton_()
    analyze_skeleton.setup("", input_image_plus_copy)
    if prune_cycle_method == 'none':
        prune_index = analyze_skeleton.NONE
    elif prune_cycle_method == 'shortest_branch':
        prune_index = analyze_skeleton.SHORTEST_BRANCH
    elif prune_cycle_method == 'lowest_intensity_voxel':
        prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL
    elif prune_cycle_method == 'lowest_intensity_branch':
        prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH
    result = analyze_skeleton.run(prune_index, prune_ends,
                                  calculate_largest_shortest_path,
                                  input_image_plus_copy, True, True)
    # Save the results.
    save(result, output, show_detailed_info, calculate_largest_shortest_path)
except Exception, e:
Exemple #2
0
# Open the input image file.
input_image_plus = IJ.openImage( input )
bit_depth = input_image_plus.getBitDepth()
image_type = input_image_plus.getType()

# Create a copy of the image.
input_image_plus_copy = input_image_plus.createImagePlus()
image_processor_copy = input_image_plus.getProcessor().duplicate()
input_image_plus_copy.setProcessor( "iCopy", image_processor_copy )

try:
    if image_type not in VALID_IMAGE_TYPES:
        # Convert the image to binary grayscale.
        IJ.run( input_image_plus_copy, "Make Binary","" )
    # Run AnalyzeSkeleton
    analyze_skeleton = AnalyzeSkeleton_()
    analyze_skeleton.setup( "", input_image_plus_copy )
    if prune_cycle_method == 'none':
        prune_index  = analyze_skeleton.NONE
    elif prune_cycle_method == 'shortest_branch':
        prune_index  = analyze_skeleton.SHORTEST_BRANCH
    elif prune_cycle_method == 'lowest_intensity_voxel':
        prune_index  = analyze_skeleton.LOWEST_INTENSITY_VOXEL
    elif prune_cycle_method == 'lowest_intensity_branch':
        prune_index  = analyze_skeleton.LOWEST_INTENSITY_BRANCH
    result = analyze_skeleton.run( prune_index,
                                   prune_ends,
                                   calculate_largest_shortest_path,
                                   input_image_plus_copy,
                                   True,
                                   True )
Exemple #3
0
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"))