Пример #1
0
def close_all():
    """Close all visvis windows."""
    vv.closeAll()
Пример #2
0
# Get image
im1 = vv.imread('astronaut.png')[:, :, 1].astype('float32')
im1 = pirt.diffuse(im1, 1)[::2, ::2] / 255.0

# Deform image
scale = im1.shape[0] * 0.4
rd = pirt.create_random_deformation(im1, 40, 40, mapping='backward', seed=1001)
im2 = rd.apply_deformation(im1)

# Add noise
im1 += np.random.normal(0, 0.1, im1.shape)
im2 += np.random.normal(0, 0.1, im1.shape)

# Get figure
vv.closeAll()
fig = vv.figure(1)
vv.clf()
fig.position = 200, 100, 900, 500

# Init registration
reg = pirt.GravityRegistration(im1, im2)
# reg = pirt.DiffeomorphicDemonsRegistration(im1, im2)
# reg = pirt.ElastixRegistration(im1, im2)

if isinstance(reg, pirt.DiffeomorphicDemonsRegistration):
    reg.params.speed_factor = 2
    reg.params.noise_factor = 0.1
    reg.params.mapping = 'backward'
    reg.params.scale_sampling = 16
    reg.params.final_grid_sampling = 35
Пример #3
0
def select_stent(volnr, params=None):
    """
    This functions calls the stent extration function. It contains seed points
    for each dataset
    """

    if params is None:
        params = getDefaultParams()
    ssdf._stent_tracking_params = params

    if volnr == 1:
        #vol 1
        vol, sampling, origin = load_volume(1)
        seed_points = Pointset(3)
        seed_points.Append(60, 110, 133)
        seed_points.Append(100, 75, 150)
        seed_points.Append(160, 70, 148)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 2:
        #vol 2
        vol, sampling, origin = load_volume(2)
        seed_points = Pointset(3)
        seed_points.Append(60, 175, 155)
        seed_points.Append(100, 150, 170)
        seed_points.Append(165, 140, 167)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 3:
        #vol 3
        vol, sampling, origin = load_volume(3)
        seed_points = Pointset(3)
        seed_points.Append(47, 160, 140)
        seed_points.Append(80, 145, 130)
        seed_points.Append(130, 130, 128)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 4:
        #vol 4
        vol, sampling, origin = load_volume(4)
        seed_points = Pointset(3)
        seed_points.Append(40, 160, 160)
        seed_points.Append(140, 145, 135)
        seed_points.Append(150, 150, 150)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 5:
        #vol 5
        vol, sampling, origin = load_volume(5)
        seed_points = Pointset(3)
        seed_points.Append(34, 150, 170)
        seed_points.Append(60, 135, 180)
        seed_points.Append(130, 140, 180)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 6:
        #vol 6
        vol, sampling, origin = load_volume(6)
        seed_points = Pointset(3)
        seed_points.Append(40, 170, 175)
        seed_points.Append(70, 160, 180)
        seed_points.Append(140, 142, 168)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 7:
        #vol 7
        vol, sampling, origin = load_volume(7)
        seed_points = Pointset(3)
        seed_points.Append(40, 180, 160)
        seed_points.Append(110, 160, 160)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    elif volnr == 8:
        #vol 8
        vol, sampling, origin = load_volume(8)
        seed_points = Pointset(3)
        seed_points.Append(60, 130, 190)
        seed_points.Append(80, 110, 180)
        seed_points.Append(120, 112, 140)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)

    elif volnr == 18:
        #vol 18
        vol, sampling, origin = load_volume(18)
        seed_points = Pointset(3)
        seed_points.Append(70, 170, 140)
        seed_points.Append(135, 150, 160)
        node_points_stent, center_points_stent, stent_points_stent = stent_detection(
            vol, sampling, origin, seed_points)
    else:
        raise ValueError('Invalid volnr')

    plot = True
    if plot:
        points = Pointset(3)
        for i in range(len(node_points_stent)):
            points.Append(node_points_stent[i][2], node_points_stent[i][1],
                          node_points_stent[i][0])

        points_2 = Pointset(3)
        for i in range(len(stent_points_stent)):
            points_2.Append(stent_points_stent[i][2], stent_points_stent[i][1],
                            stent_points_stent[i][0])

        vv.closeAll()
        vv.volshow(vol)
        vv.plot(points_2, ls='', ms='.', mc='g', mw=4, alpha=0.5)
        vv.plot(points, ls='', ms='.', mc='b', mw=4, alpha=0.9)

    graph = from_nodes_to_graph(node_points_stent)

    return graph
Пример #4
0
def save_3D_gradient_images(save_path, data, name):
    """ Makes an avi of the volume rendered gradient specified by the name
        parameter using visvis
    """
    #load all of the volumes into memory
    vols = []
    #setup the visvis setup to capture all of the images
    f = vv.clf()
    a = vv.gca()
    m = vv.MotionDataContainer(a, interval = 500)
    #loop over all the times
    times = data.get_times()
    mn = 1000000000000
    mx = -1
    #get the min and max range over which to scale the image set
    for i in range(0, len(times)):
        #load the volume
        vol = data.get_gradient_at_time(times[i], name).C
        #get the min and max of these to save
        mx = max(np.max(vol), mx)
        mn = min(np.min(vol), mn)
        #delete the loaded volume for memory issues
        del vol
    #now take screen shots of these images
    for i in range(0, len(times)):
        #load the volume
        vol = data.get_gradient_at_time(times[i], name).C
        print(vol.shape)
        #draw it
        t = vv.volshow(vol)
        t.colormap = vv.CM_HOT
        t.renderstyle = 'iso'
        t.parent = m
        #set the camera filed of view
        a.camera.fov = 60
        a.camera.elevation = 30
        a.camera.zoom = 0.01
        #set the limits to the min and max
        t.clim = (mn, mx)
        #Force the axis to draw now
        a.Draw()
        f.DrawNow()
        t_m.sleep(1)
        #get the zero padded time
        s = ZeroPad(times[-1], times[i])
        #create the save file path
        file_path = save_path + name + "_" + s + ".jpeg"
        #Now get the screenshot
        vv.screenshot(file_path)
        #load this image using PIL, append a color bar showing the min and max
        ss = Image.open(file_path)
        w, h = ss.size
        #make a new font
        font = ImageFont.truetype("arial.ttf", 24)
        color_bar = draw_color_bar(mn, mx, 50, int(.99*h), font)
        #get the colorbar dimension
        w1, h1 = color_bar.size
        #make a new image
        ht = max(h, h1)
        im_final = Image.new("RGB", (w + w1 + 10, ht), "white")
        #paste the other images on to this
        im_final.paste(color_bar, (w + 10, 0))
        im_final.paste(ss, (0, 0))
        #Now finally draw the time and the text on top of this
        draw = ImageDraw.Draw(im_final)
        #get the text to draw
        txt = "Species: " + name + "    Time: " + repr(times[i])
        #gte the position
        pos = (25, 20)
        draw.text(pos, txt, font = font, fill = (0,0,0))
        #save the final file
        im_final.save(file_path)
    #close all the figures
    vv.closeAll()
Пример #5
0
# -*- coding: utf-8 -*-
# Copyright (C) 2012, Almar Klein
#
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.

import visvis as vv

def closeAll():
    """ closeAll()
    
    Closes all figures.
    
    """
    
    for fig in [fig for fig in vv.BaseFigure._figures.values()]:
        fig.Destroy()

if __name__ == '__main__':
    import time
    # Create figures
    vv.figure()
    vv.figure()
    vv.processEvents(); vv.processEvents()
    time.sleep(1.0)
    # Close all
    vv.closeAll()
Пример #6
0
def closeAll():
    vv.closeAll()