def show_ctvolume(vol, graph=None, axis=None, showVol='MIP', clim=(0, 2500), isoTh=250, removeStent=True, climEditor=False, stripSize=6, stripSizeZ=None): """ Different ways to visualize the CT volume as reference For '2D' clim (-550,500) often good range """ import visvis as vv colormap = { 'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)] } if axis is None: axis = vv.gca() axis.MakeCurrent() if showVol == 'MIP': t = vv.volshow(vol, clim=clim, renderStyle='mip') elif showVol == 'ISO': if removeStent == True: vol = remove_stent_from_volume( vol, graph, stripSize=stripSize, stripSizeZ=stripSizeZ) # rings are removed for vis. t = vv.volshow(vol, clim=clim, renderStyle='iso') t.isoThreshold = isoTh t.colormap = colormap elif showVol == '2D': t = vv.volshow2(vol) t.clim = clim # bind ClimEditor to figure if climEditor: if showVol == 'ISO': c = _utils_GUI.IsoThEditor(axis) else: c = vv.ClimEditor(axis) c.position = (10, 50) # bind for show hide fig = vv.gcf() fig.eventKeyDown.Bind( lambda event: _utils_GUI.ShowHideSlider(event, c)) print('****') print('Use "s" to show/hide slider') print('****') return t
def psf_volume(stack, xyz_ratio, filepath): app = vv.use() # Init a figure with two axes a1 = vv.subplot(121) vv.title('PSF Volume') a2 = vv.subplot(122) vv.title('PSF XYZ Cross Sections') # show t1 = vv.volshow(stack, axes=a1) # volume t2 = vv.volshow2(stack, axes=a2) # cross-section interactive # set labels for both axes vv.xlabel('Pixel X', axes=a1) vv.ylabel('Pixel Y', axes=a1) vv.zlabel('Z-Slice', axes=a1) vv.xlabel('Pixel X', axes=a2) vv.ylabel('Pixel Y', axes=a2) vv.zlabel('Z-Slice', axes=a2) # set colormaps t1.colormap = vv.CM_JET t2.colormap = vv.CM_JET # set correct aspect ration corresponding to voxel size a1.daspect = 1, 1, xyz_ratio a2.daspect = 1, 1, xyz_ratio # show grid a1.axis.showGrid = 1 a2.axis.showGrid = 1 # run visvis and show results app.Run() # save screenshot if filepath != 'nosave': print 'Saving PSF volume.' savename = filepath[:-4] + '_PSF_3D.png' # sf: scale factor vv.screenshot(savename, sf=1, bg='w')
def volshow(*args, **kwargs): """ volshow(vol, clim=None, cm=CM_GRAY, axesAdjust=True, axes=None) Display a 3D image (a volume). This is a convenience function that calls either volshow3() or volshow2(). If the current system supports it (OpenGL version >= 2.0), displays a 3D rendering (volshow3). Otherwise shows three slices that can be moved interactively (volshow2). Parameters ---------- vol : numpy array The 3D image to visualize. Can be grayscale, RGB, or RGBA. If the volume is an anisotropic array (vv.Aaray), the appropriate scale and translate transformations are applied. clim : 2-element tuple The color limits to scale the intensities of the image. If not given, the im.min() and im.max() are used (neglecting nan and inf). cm : Colormap Set the colormap to apply in case the volume is grayscale. axesAdjust : bool If axesAdjust==True, this function will call axes.SetLimits(), and set the camera type to 3D. If daspectAuto has not been set yet, it is set to False. axes : Axes instance Display the image in this axes, or the current axes if not given. Any other keyword arguments are passed to either volshow2() or volshow3(). """ # Make sure that a figure exists vv.gcf() # Test and run if vv.settings.volshowPreference == 3 and vv.misc.getOpenGlCapable(2.0): return vv.volshow3(*args, **kwargs) else: return vv.volshow2(*args, **kwargs)
def volshow(*args, **kwargs): """ volshow(vol, clim=None, cm=CM_GRAY, axesAdjust=True, axes=None) Display a 3D image (a volume). This is a convenience function that calls either volshow3() or volshow2(). If the current system supports it (OpenGL version >= 2.0), displays a 3D rendering (volshow3). Otherwise shows three slices that can be moved interactively (volshow2). Parameters ---------- vol : numpy array The 3D image to visualize. Can be grayscale, RGB, or RGBA. If the volume is an anisotropic array (vv.Aaray), the appropriate scale and translate transformations are applied. clim : 2-element tuple The color limits to scale the intensities of the image. If not given, the im.min() and im.max() are used (neglecting nan and inf). cm : Colormap Set the colormap to apply in case the volume is grayscale. axesAdjust : bool If axesAdjust==True, this function will call axes.SetLimits(), and set the camera type to 3D. If daspectAuto has not been set yet, it is set to False. axes : Axes instance Display the image in this axes, or the current axes if not given. Any other keyword arguments are passed to either volshow2() or volshow3(). """ # Make sure that a figure exists vv.gcf() # Test and run if vv.settings.volshowPreference==3 and vv.misc.getOpenGlCapable(2.0): return vv.volshow3(*args, **kwargs) else: return vv.volshow2(*args, **kwargs)
#!/usr/bin/env python """ This example illustrates how you can visualize a volume using 2D slices. We explicitly use volshow2() here. Note that volshow() calls volshow3() by default, but volshow2() when the system does not support 3D rendering (OpenGL version <2.0). """ import visvis as vv vol = vv.aVolume() t = vv.volshow2(vol) t.colormap = vv.CM_HOT t.edgeColor = (0.8, 0.8, 0.8) app = vv.use() app.Run()
colormap = { 'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)] } import visvis as vv fig = vv.figure(1) vv.clf() fig.position = 0, 22, 1366, 706 a1 = vv.subplot(121) t1 = vv.volshow(vol1, clim=(0, 3000), renderStyle='iso') # iso or mip t1.isoThreshold = 400 t1.colormap = colormap a1b = vv.volshow2(vol1, clim=(-550, 500)) vv.xlabel('x'), vv.ylabel('y'), vv.zlabel('z') # vv.title('One volume at %i procent of cardiac cycle' % phase ) vv.title('Vol40') a2 = vv.subplot(122) a2.daspect = 1, 1, -1 t2 = vv.volshow(vol2, clim=(0, 3000), renderStyle='iso') # iso or mip t2.isoThreshold = 400 t2.colormap = colormap a2b = vv.volshow2(vol2, clim=(-550, 500)) vv.xlabel('x'), vv.ylabel('y'), vv.zlabel('z') # vv.title('One volume at %i procent of cardiac cycle' % phase ) vv.title('Vol78') a1.camera = a2.camera
## Start vis f = vv.figure(1) vv.clf() f.position = 8.00, 31.00, 944.00, 1001.00 a = vv.gca() a.axis.axisColor = 1, 1, 1 a.axis.visible = False a.bgcolor = 0, 0, 0 a.daspect = 1, 1, -1 vv.title('Model for LSPEAS %s - %s' % (ptcode[7:], ctcode)) vv.xlabel('x (mm)') vv.ylabel('y (mm)') vv.zlabel('z (mm)') t = vv.volshow2(volavg, clim=(-550, 500)) # -750, 1000 # m = vv.mesh(mesh) # m.faceColor = 'g' # Create deformable mesh dm = DeformableMesh(a, mesh) dm.SetDeforms(*[list(reversed(deform)) for deform in deforms_f]) dm.clim = 0, 4 dm.colormap = vv.CM_JET vv.colorbar() # Run mesh a.SetLimits() # a.SetView(viewringcrop) dm.MotionPlay(5, 1) # (10, 0.2) = each 10 ms do a step of 20%
#!/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()
def showVolPhases(basedir, vols=None, ptcode=None, ctcode=None, cropname=None, showVol='iso', mipIsocolor=False, isoTh=310, slider=False, clim=(0,3000), clim2D=(-550, 500), fname=None): """ Show vol phases in motion container showVol= mip or iso or 2D; Provide either vols or location """ if vols is None: # Load volumes s = loadvol(basedir, ptcode, ctcode, cropname, 'phases', fname=fname) vols = [] for key in dir(s): if key.startswith('vol'): vols.append(s[key]) # Start vis f = vv.figure(1); vv.clf() f.position = 9.00, 38.00, 992.00, 944.00 a = vv.gca() a.daspect = 1, 1, -1 a.axis.axisColor = 1,1,1 a.axis.visible = False a.bgcolor = 0,0,0 if showVol=='mip': if not ptcode is None and not ctcode is None: vv.title('Maximum intensity projection cine-loop of the original ECG-gated CT volumes of patient %s at %s ' % (ptcode[8:], ctcode)) else: vv.title('Maximum intensity projection cine-loop of the original ECG-gated CT volumes ') else: if not ptcode is None and not ctcode is None: vv.title('ECG-gated CT scan cine-loop of the original ECG-gated CT volumes of patient %s at %s ' % (ptcode[8:], ctcode)) else: vv.title('ECG-gated CT scan cine-loop of the original ECG-gated CT volumes ') # Setup data container container = vv.MotionDataContainer(a) for vol in vols: if showVol == '2D': t = vv.volshow2(vol, clim=clim2D) # -750, 1000 t.parent = container else: t = vv.volshow(vol, clim=clim, renderStyle = showVol) t.parent = container if showVol == 'iso': t.isoThreshold = isoTh # iso or mip work well t.colormap = {'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)]} if mipIsocolor: t.colormap = {'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)]} # bind ClimEditor to figure if slider: if showVol=='mip': c = vv.ClimEditor(vv.gcf()) c.position = (10, 50) f.eventKeyDown.Bind(lambda event: _utils_GUI.ShowHideSlider(event, c) ) if showVol=='iso': c = IsoThEditor(vv.gcf()) c.position = (10, 50) f.eventKeyDown.Bind(lambda event: _utils_GUI.ShowHideSlider(event, c) ) f.eventKeyDown.Bind(lambda event: _utils_GUI.ViewPresets(event, [a]) ) print('------------------------') print('Use keys 1, 2, 3, 4 and 5 for preset anatomic views') print('Use v for a default zoomed view') print('Use x to show and hide axis') print('------------------------') return t
# clipping is not automatic! Babsgrid = np.clip(Babsgrid, 0, 0.005) Babsgrid = vv.Aarray(Babsgrid, sampling=(resolution, resolution, resolution), origin=(volume_corner1[2], volume_corner1[1], volume_corner1[0])) # set labels vv.xlabel('x axis') vv.ylabel('y axis') vv.zlabel('z axis') bs.vv_PlotWires() t = vv.volshow2(Babsgrid, renderStyle='mip', cm=vv.CM_JET) vv.colorbar() app = vv.use() app.Run() # matplotlib plot fig = plt.figure() # 3d quiver #ax = fig.gca(projection='3d') #ax.quiver(points[:, 0], points[:, 1], points[:, 2], B[:, 0], B[:, 1], B[:, 2], length=0.005) #2d quiver ax = fig.gca()
def dicom2ssdf(dicom_basedir, ptcode, ctcode, basedir, cropnames=['stent'], savedistolicavg=False, visvol=True, visdynamic=False): """ read dicom volumes and store as ssdf format """ #Step A vols2 = [vol2 for vol2 in imageio.get_reader(dicom_basedir, 'DICOM', 'V')] try: for i, vol in enumerate(vols2): print(vol.meta.ImagePositionPatient) for i, vol in enumerate(vols2): print(vol.shape) for i, vol in enumerate(vols2): print(vol.meta.AcquisitionTime) print(vol.meta.sampling) assert vol.shape == vols2[0].shape assert vol.meta.SeriesTime == vols2[0].meta.SeriesTime except AttributeError: print('Some meta information is not available') pass # check order of phases vols = vols2.copy() try: for i, vol in enumerate(vols): print(vol.meta.SeriesDescription) assert str(i * 10) in vol.meta.SeriesDescription # 0% , 10% etc. except AttributeError: # meta info is missing print('vol.meta.SeriesDescription meta information is not available') pass except AssertionError: # not correct order, fix vols = [None] * len(vols2) for i, vol in enumerate(vols2): print(vol.meta.SeriesDescription) phase = int(vol.meta.SeriesDescription[:1]) # use phase to fix order of phases vols[phase] = vol # Step B: Crop and Save SSDF # Load and show first volume: crop with a margin of at least ~25 mm print() print('Crop with margins ~25 mm around ROI for the registration algorithm') stenttype = None # deprecate, not needed for cropname in cropnames: savecropvols(vols, basedir, ptcode, ctcode, cropname, stenttype) # Step C: average diastolic phases if savedistolicavg: phases = 50, 10 # use 7 phases from 50% to 10% saveaveraged(basedir, ptcode, ctcode, cropname, phases) # Visualize 1 phase import visvis as vv if visvol: vol1 = vols[1] colormap = { 'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)] } fig = vv.figure(2) vv.clf() fig.position = 0, 22, 1366, 706 a1 = vv.subplot(111) a1.daspect = 1, 1, -1 renderStyle = 'mip' t1 = vv.volshow(vol1, clim=(0, 3000), renderStyle=renderStyle) # iso or mip if renderStyle == 'iso': t1.isoThreshold = 300 t1.colormap = colormap a1 = vv.volshow2(vol1, clim=(-500, 500), renderStyle=renderStyle) vv.xlabel('x'), vv.ylabel('y'), vv.zlabel('z') vv.title('One volume at 10\% procent of cardiac cycle') if visdynamic: from lspeas.utils.vis import showVolPhases showVol = 'mip' t = showVolPhases(basedir, vols2, showVol=showVol, mipIsocolor=True, isoTh=310, clim=(60, 3000), slider=True) return vols
def __init__(self, dicom_basedir, ptcode, ctcode, basedir): import imageio #import easygui from stentseg.utils.datahandling import loadvol from stentseg.utils.datahandling import savecropvols, saveaveraged ## Select base directory for LOADING DICOM data #dicom_basedir = easygui.diropenbox() print('DICOM Path = ', dicom_basedir) #ctcode = '12months' # 'pre', 'post_x', '12months' stenttype = 'nellix' ## Select base directory to SAVE SSDF #basedir = easygui.diropenbox() print('Base Path = ', basedir) # Set which crops to save cropnames = ['prox'] #,'stent'] # ['ring'] or ['ring','stent'] or .. #=============================================================================== ## Step A: read single volumes to get vols: # folder1 = '10%' # folder2 = '60%' # vol1 = imageio.volread(os.path.join(dicom_basedir, folder1), 'dicom') # vol2 = imageio.volread(os.path.join(dicom_basedir, folder2), 'dicom') # print( ) # # if vol1.meta.SeriesDescription[:2] < vol2.meta.SeriesDescription[:2]: # vols4078 = [vol1,vol2] # else: # vols4078 = [vol2,vol1] # # vols = vols4078.copy() # # for vol in vols: # vol.meta.PatientName = ptcode # anonimyze # vol.meta.PatientID = 'anonymous' # print(vol.meta.SeriesDescription,'-', vol.meta.sampling) #=============================================================================== ##Orginele code #=============================================================================== # # folder1 = '40% iDose' # folder2 = '78 iDose' # vol1 = imageio.volread(os.path.join(dicom_basedir, folder1), 'dicom') # vol2 = imageio.volread(os.path.join(dicom_basedir, folder2), 'dicom') # print( ) # # if vol1.meta.SeriesDescription[:2] < vol2.meta.SeriesDescription[:2]: # vols4078 = [vol1,vol2] # else: # vols4078 = [vol2,vol1] # # vols = vols4078.copy() # # for vol in vols: # vol.meta.PatientName = ptcode # anonimyze # vol.meta.PatientID = 'anonymous' # print(vol.meta.SeriesDescription,'-', vol.meta.sampling) #=============================================================================== ## Step A: read 10 volumes to get vols # Deze zoekt alle mappen en dat zijn er dus 10 maar niet in de goede volgorde vols2 = [ vol2 for vol2 in imageio.get_reader(dicom_basedir, 'DICOM', 'V') ] vols = [None] * len(vols2) for i, vol in enumerate(vols2): # print(vol.meta.sampling) print(vol.meta.SeriesDescription) phase = int(vol.meta.SeriesDescription[:1]) # use phase to fix order of phases vols[phase] = vol #vols[phase].meta.ImagePositionPatient = (0.0,0.0,0.0) for i, vol in enumerate( vols): #wat ik heb veranderd is i, en enumerate() print(vol.meta.SeriesDescription) assert vol.shape == vols[0].shape assert str(i * 10) in vol.meta.SeriesDescription # 0% , 10% etc. ## Step B: Crop and Save SSDF # 1 of 2 cropnames opgeven voor opslaan 1 of 2 crpos. # Het eerste volume wordt geladen in MIP, crop met marges van minimaal 30 mm for cropname in cropnames: savecropvols(vols, basedir, ptcode, ctcode, cropname, stenttype) # saveaveraged(basedir, ptcode, ctcode, cropname, range(0,100,10)) ## Visualize result #s1 = loadvol(basedir, ptcode, ctcode, cropnames[0], what ='10avgreg') #s2 = loadvol(basedir, ptcode, ctcode, cropnames[0], what ='10phases') s1 = loadvol(basedir, ptcode, ctcode, cropnames[0], what='phases') #s2 = loadvol(basedir, ptcode, ctcode, cropnames[0], what = 'avg010') #vol1 = s1.vol vol1 = s1.vol40 # Visualize and compare colormap = { 'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)] } import visvis as vv fig = vv.figure(1) vv.clf() fig.position = 0, 22, 1366, 706 a1 = vv.subplot(111) a1.daspect = 1, 1, -1 # t1 = vv.volshow(vol1, clim=(0, 3000), renderStyle='iso') # iso or mip # t1.isoThreshold = 600 # stond op 400 maar je moet hoger zetten als je alleen stent wil # t1.colormap = colormap a1 = vv.volshow2(vol1, clim=(-500, 1500), renderStyle='mip') vv.xlabel('x'), vv.ylabel('y'), vv.zlabel('z') # vv.title('One volume at %i procent of cardiac cycle' % phase ) vv.title('Vol40')
# Step B: Crop and Save SSDF vols = [vol] for cropname in cropnames: savecropvols(vols, ssdf_basedir, ptcode, ctcode, cropname, stenttype) ## Visualize result s1 = loadvol(ssdf_basedir, ptcode, ctcode, cropnames[0], what ='phase') vol = s1.vol # Visualize and compare colormap = {'r': [(0.0, 0.0), (0.17727272, 1.0)], 'g': [(0.0, 0.0), (0.27272728, 1.0)], 'b': [(0.0, 0.0), (0.34545454, 1.0)], 'a': [(0.0, 1.0), (1.0, 1.0)]} import visvis as vv fig = vv.figure(1); vv.clf() fig.position = 0, 22, 1366, 706 a = vv.gca() a.daspect = 1,1,-1 t1 = vv.volshow(vol, clim=(0, 2500), renderStyle='iso') # iso or mip t1.isoThreshold = 400 t1.colormap = colormap t2 = vv.volshow2(vol, clim=(-550, 500)) vv.xlabel('x'), vv.ylabel('y'), vv.zlabel('z') # vv.title('One volume at %i procent of cardiac cycle' % phase ) vv.title('Static CT Volume' )
def showModelsStatic(ptcode,codes, vols, ss, mm, vs, showVol, clim, isoTh, clim2, clim2D, drawMesh=True, meshDisplacement=True, drawModelLines=True, showvol2D=False, showAxis=False, drawVessel=False, vesselType=1, meshColor=None, **kwargs): """ show one to four models in multipanel figure. Input: arrays of codes, vols, ssdfs; params from show_models_static Output: axes, colorbars """ # init fig f = vv.figure(1); vv.clf() # f.position = 0.00, 22.00, 1920.00, 1018.00 mw = 5 if drawMesh == True: lc = 'w' meshColor = meshColor else: lc = 'g' # create subplots if isinstance(codes, str): # if 1 ctcode, otherwise tuple of strings a1 = vv.subplot(111) axes = [a1] elif codes == (codes[0],codes[1]): a1 = vv.subplot(121) a2 = vv.subplot(122) axes = [a1,a2] elif codes == (codes[0],codes[1], codes[2]): a1 = vv.subplot(131) a2 = vv.subplot(132) a3 = vv.subplot(133) axes = [a1,a2,a3] elif codes == (codes[0],codes[1], codes[2], codes[3]): a1 = vv.subplot(141) a2 = vv.subplot(142) a3 = vv.subplot(143) a4 = vv.subplot(144) axes = [a1,a2,a3,a4] elif codes == (codes[0],codes[1], codes[2], codes[3], codes[4]): a1 = vv.subplot(151) a2 = vv.subplot(152) a3 = vv.subplot(153) a4 = vv.subplot(154) a5 = vv.subplot(155) axes = [a1,a2,a3,a4,a5] else: a1 = vv.subplot(111) axes = [a1] for i, ax in enumerate(axes): ax.MakeCurrent() vv.xlabel('x (mm)');vv.ylabel('y (mm)');vv.zlabel('z (mm)') vv.title('Model for LSPEAS %s - %s' % (ptcode[7:], codes[i])) t = show_ctvolume(vols[i], ss[i].model, axis=ax, showVol=showVol, clim=clim, isoTh=isoTh, **kwargs) label = pick3d(ax, vols[i]) if drawModelLines == True: ss[i].model.Draw(mc='b', mw = mw, lc=lc) if showvol2D: for i, ax in enumerate(axes): t2 = vv.volshow2(vols[i], clim=clim2D, axes=ax) cbars = [] # colorbars if drawMesh: for i, ax in enumerate(axes): m = vv.mesh(mm[i], axes=ax) if meshDisplacement: m.clim = clim2 m.colormap = vv.CM_JET #todo: use colormap Viridis or Magma as JET is not linear (https://bids.github.io/colormap/) cb = vv.colorbar(ax) cbars.append(cb) elif meshColor is not None: if len(meshColor) == 1: m.faceColor = meshColor[0] # (0,1,0,1) else: m.faceColor = meshColor[i] else: m.faceColor = 'g' if drawVessel: for i, ax in enumerate(axes): v = showVesselMesh(vs[i], ax, type=vesselType) for ax in axes: ax.axis.axisColor = 1,1,1 ax.bgcolor = 25/255,25/255,112/255 # midnightblue # http://cloford.com/resources/colours/500col.htm ax.daspect = 1, 1, -1 # z-axis flipped ax.axis.visible = showAxis # set colorbar position for cbar in cbars: p1 = cbar.position cbar.position = (p1[0], 20, p1[2], 0.98) # x,y,w,h # bind rotate view and view presets [1,2,3,4,5] f = vv.gcf() f.eventKeyDown.Bind(lambda event: _utils_GUI.RotateView(event,axes,axishandling=False) ) f.eventKeyDown.Bind(lambda event: _utils_GUI.ViewPresets(event,axes) ) return axes, cbars
# calculate B field at given points B = sol.CalculateB(points=points) Babs = np.linalg.norm(B, axis=1) # draw results # prepare axes a = vv.gca() a.cameraType = '3d' a.daspectAuto = False vol = Babs.reshape(grid.shape[1:]).T vol = np.clip(vol, 0.002, 0.01) vol = vv.Aarray(vol, sampling=(resolution, resolution, resolution), origin=(volume_corner1[2], volume_corner1[1], volume_corner1[0])) # set labels vv.xlabel('x axis') vv.ylabel('y axis') vv.zlabel('z axis') sol.vv_PlotWires() t = vv.volshow2(vol, renderStyle='mip', cm=vv.CM_JET) vv.colorbar() app = vv.use() app.Run()
s3 = loadvol(basedir, ptcode, ctcode, cropname, 'phases') vol0ori = s3.vol0 # todo: backward/forward based on how deforms were obtained?? # deforms was obtained as backward, from original phases to mean volume avgreg deform = pirt.DeformationFieldBackward(deforms[0]) # vol2 = pirt.interp.deform_backward(vol, deforms[0]) # te low level, gebruikt awarp niet vol2 = deform.inverse().as_backward().apply_deformation( vol0ori) # gebruikt pirt deformation.py vv.figure(1) vv.clf() a1 = vv.subplot(131) t1 = vv.volshow(vol) a1.daspect = (1, 1, -1) vv.title('vol average of cardiac cycle') # vv.figure(2); vv.clf() a2 = vv.subplot(132) t2 = vv.volshow(vol2) a2.daspect = (1, 1, -1) vv.title('vol 0 deformed to avg volume') # vv.figure(3); vv.clf() a3 = vv.subplot(133) t3 = vv.volshow2((vol2 - vol), clim=(-500, 500)) a3.daspect = (1, 1, -1) vv.title('difference') a1.camera = a2.camera = a3.camera t1.clim = t2.clim = 0, 2000 t3.clim = -500, 500
import numpy as np import argparse import visvis as vv app = vv.use() if __name__ == "__main__": parser = argparse.ArgumentParser( description='Plot the disparity space image (DSI) using 3D slices') parser.add_argument( '-i', '--input', default='dsi.npy', type=str, help='path to the NPY file containing the DSI (default: dsi.npy)') args = parser.parse_args() a = vv.gca() a.daspect = 1, -1, 1 a.daspectAuto = False vol = np.load(args.input) # Reorder axis so that the Z axis points forward instead of up vol = np.swapaxes(vol, 0, 1) vol = np.flip(vol, axis=0) t = vv.volshow2(vol) t.colormap = vv.CM_HOT app.Run()