Ejemplo n.º 1
0
'''
Work with vtkVolume objects and surface meshes 
in the same rendering window.
'''
from vtkplotter import loadImageData, Plotter, Volume, Sphere, Text

vp = Plotter(axes=0, verbose=0, bg='w')

# Load a 3D voxel dataset (returns a vtkImageData object):
img = loadImageData('data/embryo.slc', spacing=[1, 1, 1])

# Build a vtkVolume object.
# A set of transparency values - of any length - can be passed
# to define the opacity transfer function in the range of the scalar.
#  E.g.: setting alphas=[0, 0, 0, 1, 0, 0, 0] would make visible
#  only voxels with value close to 98.5 (see print output).
vol = Volume(img, c='green', alphas=[0, 0.4, 0.9, 1])  # vtkVolume

# can relocate volume in space:
#vol.scale(0.3).pos([10,100,0]).rotate(90, axis=[0,1,1])

sph = Sphere(pos=[100, 100, 100], r=20)  # add a dummy surface

doc = Text(__doc__, c='k')

# show both vtkVolume and vtkActor
vp.show([vol, sph, doc], zoom=1.4)
Ejemplo n.º 2
0
# Perform other simple mathematical operation between 3d images.
# Possible operations are: +, -, /, 1/x, sin, cos, exp, log, abs, **2, sqrt,
#   min, max, atan, atan2, median, mag, dot, gradient, divergence, laplacian.
# Alphas defines the opacity transfer function in the scalar range.
#
from vtkplotter import Plotter, loadImageData
from vtkplotter import imageOperation, Volume

vp = Plotter(N=8, axes=4)

img0 = loadImageData('data/embryo.slc')  # vtkImageData object
v0 = Volume(img0, c=0)  # build a vtk.vtkVolume derived object
vp.show(v0, at=0)

img1 = imageOperation(img0, 'gradient')
img1 = imageOperation(img1, '+', 92.0)
v1 = Volume(img1, c=1, alphas=[0, 1, 0, 0, 0])
vp.show(v1, at=1)

img2 = imageOperation(img0, 'divergence')
v2 = Volume(img2, c=2)
vp.show(v2, at=2)

img3 = imageOperation(img0, 'laplacian')
v3 = Volume(img3, c=3, alphas=[0, 1, 0, 0, 1])
vp.show(v3, at=3)

img4 = imageOperation(img0, 'median')
v4 = Volume(img4, c=4)
vp.show(v4, at=4)
Ejemplo n.º 3
0
"""
Perform other simple mathematical operation between 3d images.
Possible operations are: +, -, /, 1/x, sin, cos, exp, log, abs, **2, sqrt, 
  min, max, atan, atan2, median, mag, dot, gradient, divergence, laplacian.
Alphas defines the opacity transfer function in the scalar range.
"""
print(__doc__)

from vtkplotter import Plotter, loadImageData
from vtkplotter import imageOperation, Volume, datadir

vp = Plotter(N=8, axes=4, bg="w")

img0 = loadImageData(datadir + "embryo.slc")  # vtkImageData object
v0 = Volume(img0, c=0)  # build a vtk.vtkVolume derived object
vp.show(v0, at=0)

img1 = imageOperation(img0, "gradient")
img1 = imageOperation(img1, "+", 92.0)
v1 = Volume(img1, c=1, alphas=[0, 1, 0, 0, 0])
vp.show(v1, at=1)

img2 = imageOperation(img0, "divergence")
v2 = Volume(img2, c=2)
vp.show(v2, at=2)

img3 = imageOperation(img0, "laplacian")
v3 = Volume(img3, c=3, alphas=[0, 1, 0, 0, 1])
vp.show(v3, at=3)

img4 = imageOperation(img0, "median")
Ejemplo n.º 4
0
'''
Intersect a vtkImageData (voxel dataset) with planes.
'''
from vtkplotter import show, loadImageData, probeLine, vector, Text

img = loadImageData('data/embryo.slc')

pos = img.GetCenter()

lines = []
for i in range(60):  # probe scalars on 60 parallel lines
    step = (i - 30) * 2
    p1, p2 = pos + vector(-100, step, step), pos + vector(100, step, step)
    a = probeLine(img, p1, p2, res=200)
    a.alpha(0.5).lineWidth(6)
    lines.append(a)
    #print(a.scalars(0)) # numpy scalars can be access here
    #print(a.scalars('vtkValidPointMask')) # the mask of valid points

show(lines + [Text(__doc__)], axes=4, verbose=0, bg='w')
Ejemplo n.º 5
0
"""
Intersect a vtkImageData (voxel dataset) with planes
"""
from vtkplotter import show, loadImageData, probePlane, vector, Text, datadir

img = loadImageData(datadir + "embryo.slc")

planes = []
for i in range(6):
    print("probing slice plane #", i)
    pos = img.GetCenter() + vector(0, 0, (i - 3) * 25.0)
    a = probePlane(img, origin=pos, normal=(0, 0, 1)).alpha(0.2)
    planes.append(a)
    # print(max(a.scalars(0))) # access scalars this way, 0 means first

show(planes + [Text(__doc__)], axes=4, verbose=0, bg="w")
Ejemplo n.º 6
0
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from vtkplotter import loadImageData, Volume, isosurface, show, datadir

maxradius = 0.2
neurons = 30
epochs = 20

image = loadImageData(datadir + "embryo.tif")

vmin, vmax = image.GetScalarRange()
nx, ny, nz = image.GetDimensions()
print("Scalar Range:", vmin, vmax, "Dimensions", image.GetDimensions())

visdata = np.zeros([nx, ny, nz])
datalist, scalars = [], []
lsx = np.linspace(0, 1, nx, endpoint=False)
lsy = np.linspace(0, 1, ny, endpoint=False)
lsz = np.linspace(0, 1, nz, endpoint=False)
for i, x in enumerate(lsx):
    for j, y in enumerate(lsy):
        for k, z in enumerate(lsz):
            s = image.GetScalarComponentAsDouble(i, j, k, 0)
            s = (s - vmin) / (vmax - vmin)
            visdata[i, j, k] = s
            datalist.append([x, y, z])
            scalars.append(s)
datalist = np.array(datalist)
scalars = np.array(scalars)