def main(select=3, **kwargs): """Script main function. select: int 1: Medical data 2: Blocky data, different every time 3: Two donuts 4: Ellipsoid """ import visvis as vv # noqa: delay import visvis and GUI libraries # Create test volume if select == 1: vol = vv.volread('stent') isovalue = kwargs.pop('level', 800) elif select == 2: vol = vv.aVolume(20, 128) isovalue = kwargs.pop('level', 0.2) elif select == 3: with timer('computing donuts'): vol = donuts() isovalue = kwargs.pop('level', 0.0) # Uncommenting the line below will yield different results for # classic MC # vol *= -1 elif select == 4: vol = ellipsoid(4, 3, 2, levelset=True) isovalue = kwargs.pop('level', 0.0) else: raise ValueError('invalid selection') # Get surface meshes with timer('finding surface lewiner'): vertices1, faces1 = marching_cubes_lewiner(vol, isovalue, **kwargs)[:2] with timer('finding surface classic'): vertices2, faces2 = marching_cubes_classic(vol, isovalue, **kwargs) # Show vv.figure(1) vv.clf() a1 = vv.subplot(121) vv.title('Lewiner') m1 = vv.mesh(np.fliplr(vertices1), faces1) a2 = vv.subplot(122) vv.title('Classic') m2 = vv.mesh(np.fliplr(vertices2), faces2) a1.camera = a2.camera # visvis uses right-hand rule, gradient_direction param uses left-hand rule m1.cullFaces = m2.cullFaces = 'front' # None, front or back vv.use().Run()
""" Example demonstrating the stent segmentation algorithm on the stent CT volume that comes with visvis. """ import numpy as np import visvis as vv from visvis import ssdf from stentseg.stentdirect import StentDirect, StentDirect_old, getDefaultParams, stentgraph from stentseg.stentdirect.stentgraph import create_mesh # Load volume data, use Aarray class for anisotropic volumes vol = vv.volread('stent') vol = vv.Aarray(vol,(1,1,1)) #stentvol = vv.ssdf.load(r'C:\Users\Maaike\Dropbox\UT MA3\Research Aortic Stent Grafts\Data_nonECG-gated\lspeas\lspeas_003.ssdf') #vol = vv.Aarray(stentvol.vol,stentvol.sampling) #stentvol = vv.ssdf.load('/home/almar/data/lspeas/LSPEAS_002/LSPEAS_002_1month_ring_avg3090.ssdf') #vol = vv.Aarray(stentvol.vol,stentvol.sampling) # Get parameters. Different scanners/protocols/stent material might need # different parameters. p = getDefaultParams() p.graph_weakThreshold = 10 # step 3, stentgraph.prune_very_weak: p.mcp_maxCoverageFronts = 0.03 # step 2, create MCP object p.graph_expectedNumberOfEdges = 2 # 2 for zig-zag, 4 for diamond shaped # # step 3, in stentgraph.prune_weak #p.graph_trimLength = # step 3, stentgraph.prune_tails #p.graph_strongThreshold # step 3, stentgraph.prune_weak and stentgraph.prune_redundant p.seed_threshold = 800 # step 1 #p.graph_minimumClusterSize # step 3, stentgraph.prune_clusters
#!/usr/bin/env python """ This example demonstrates rendering a color volume. We demonstrate two renderers capable of rendering color data: the colormip and coloriso renderer. """ import visvis as vv app = vv.use() # Load volume vol = vv.volread("stent") # Create figure and make subplots with different renderers vv.figure(1) vv.clf() RS = ["mip", "iso", "edgeray", "ray", "litray"] a0 = None tt = [] for i in range(5): a = vv.subplot(3, 2, i + 2) t = vv.volshow(vol) vv.title("Renderstyle " + RS[i]) t.colormap = vv.CM_HOT t.renderStyle = RS[i] t.isoThreshold = 200 # Only used in iso render style tt.append(t) if a0 is None: a0 = a else: a.camera = a0.camera
#!/usr/bin/env python """ This example illustrates how to create an isosurface from a volume and display it. This code relies on scikit-image. """ import visvis as vv vol = vv.volread('stent') # a standard visvis volume mesh = vv.isosurface(vol) # returns a visvis BaseMesh object vv.figure(1) vv.clf() vv.volshow2(vol) m = vv.mesh(mesh) m.faceColor = (0, 1, 1) vv.title('Isosurface') app = vv.use() app.Run()
import time import numpy as np import visvis as vv from skimage.measure import marching_cubes_classic, marching_cubes_lewiner from skimage.draw import ellipsoid # Create test volume SELECT = 3 gradient_dir = 'descent' # ascent or descent if SELECT == 1: # Medical data vol = vv.volread('stent') isovalue = 800 elif SELECT == 2: # Blocky data vol = vv.aVolume(20, 128) # Different every time isovalue = 0.2 elif SELECT == 3: # Generate two donuts using a formula by Thomas Lewiner n = 48 a, b = 2.5 / n, -1.25 isovalue = 0.0 # vol = np.empty((n, n, n), 'float32') for iz in range(vol.shape[0]):
Parameters ---------- vol : 3D numpy array The volume for which to calculate the isosurface. isovalue : float The value at which the surface should be created. If not given or None, the average of the min and max of vol is used. step : int The stepsize for stepping through the volume. Larger steps yield faster but coarser results. The result shall always be topologically correct though. useClassic : bool If True, uses the classic marching cubes by Lorensen (1987) is used. This algorithm has many ambiguities and is not guaranteed to produce a topologically correct result. useValues : bool If True, the returned BaseMesh object will also have a value for each vertex, which is related to the maximum value in a local region near the isosurface. """ from visvis.utils.iso import isosurface as _isosurface return _isosurface(im, isovalue, step, useClassic, useValues) if __name__ == '__main__': vv.mesh(isosurface(vv.volread('stent')))
ls = l.split('[') lsc = ls[1].split(',') z = int(lsc[0]) y = int(lsc[1]) x = int(lsc[2]) print('point indices z,y,x: {},{},{}.'.format(z, y, x)) return [x, y, z] def get_picked_seed(data, label): """ Picked point (SHIFT+r-click) is converted to world coordinates as in Step1 Input: volume data, label """ from stentseg.utils import PointSet coord = label2volindices(label) # [x,y,z] p = PointSet(coord, dtype=np.float32) # Correct for anisotropy and offset if hasattr(data, 'sampling'): p *= PointSet(list(reversed(data.sampling))) if hasattr(data, 'origin'): p += PointSet(list(reversed(data.origin))) return list(p.flat) if __name__ == '__main__': vol = vv.Aarray(vv.volread('stent'), (0.5, 0.5, 0.5), (100, 40, 10)) a = vv.gca() t = vv.volshow(vol) pick3d(a, vol)