def test_fbc(): """Test the FBC measures on a set of fibers""" # Generate two fibers of 10 points streamlines = [] for i in range(2): fiber = np.zeros((10, 3)) for j in range(10): fiber[j, 0] = j fiber[j, 1] = i*0.2 fiber[j, 2] = 0 streamlines.append(fiber) # Create lookup table. # A fixed set of orientations is used to guarantee deterministic results D33 = 1.0 D44 = 0.04 t = 1 sphere = Sphere(xyz=np.array([[0.82819078, 0.51050355, 0.23127074], [-0.10761926, -0.95554309, 0.27450957], [0.4101745, -0.07154038, 0.90919682], [-0.75573448, 0.64854889, 0.09082809], [-0.56874549, 0.01377562, 0.8223982]])) k = EnhancementKernel(D33, D44, t, orientations=sphere, force_recompute=True) # run FBC fbc = FBCMeasures(streamlines, k, verbose=True) # get FBC values fbc_sl_orig, clrs_orig, rfbc_orig = \ fbc.get_points_rfbc_thresholded(0, emphasis=0.01) # check mean RFBC against tested value npt.assert_almost_equal(np.mean(rfbc_orig), 1.0500466494329224)
def bundle_coherence(streamlines, affine, k, t1_data=None, interactive=False): # Compute lookup table # Apply FBC measures from dipy.tracking.fbcmeasures import FBCMeasures fbc = FBCMeasures(streamlines, k) # Calculate LFBC for original fibers fbc_sl_orig, clrs_orig, rfbc_orig = \ fbc.get_points_rfbc_thresholded(0, emphasis=0.01) # Apply a threshold on the RFBC to remove spurious fibers fbc_sl_thres, clrs_thres, rfbc_thres = \ fbc.get_points_rfbc_thresholded(0.125, emphasis=0.01) # Visualize the results from dipy.viz import window, actor # Create renderer ren = window.Renderer() # Original lines colored by LFBC lineactor = actor.line(fbc_sl_orig, clrs_orig, linewidth=0.2) ren.add(lineactor) # Horizontal (axial) slice of T1 data if t1_data is not None: vol_actor1 = actor.slicer(t1_data, affine=affine) vol_actor1.display(z=20) ren.add(vol_actor1) # Vertical (sagittal) slice of T1 data vol_actor2 = actor.slicer(t1_data, affine=affine) vol_actor2.display(x=35) ren.add(vol_actor2) # Show original fibers ren.set_camera(position=(-264, 285, 155), focal_point=(0, -14, 9), view_up=(0, 0, 1)) window.record(ren, n_frames=1, out_path='OR_before.png', size=(900, 900)) if interactive: window.show(ren) # Show thresholded fibers ren.rm(lineactor) ren.add(actor.line(fbc_sl_thres, clrs_thres, linewidth=0.2)) window.record(ren, n_frames=1, out_path='OR_after.png', size=(900, 900)) if interactive: window.show(ren) return k
from dipy.denoise.enhancement_kernel import EnhancementKernel D33 = 1.0 D44 = 0.02 t = 1 k = EnhancementKernel(D33, D44, t) """ The FBC measures are now computed, taking the tractography results and the lookup tables as input. """ # Apply FBC measures from dipy.tracking.fbcmeasures import FBCMeasures fbc = FBCMeasures(streamlines, k) """ After calculating the FBC measures, a threshold can be chosen on the relative FBC (RFBC) in order to remove spurious fibers. Recall that the relative FBC (RFBC) is calculated by the minimum of the moving average LFBC along the fiber. In this example we show the results for threshold 0 (i.e. all fibers are included) and 0.2 (removing the 20 percent most spurious fibers). """ # Calculate LFBC for original fibers fbc_sl_orig, clrs_orig, rfbc_orig = \ fbc.get_points_rfbc_thresholded(0, emphasis=0.01) # Apply a threshold on the RFBC to remove spurious fibers fbc_sl_thres, clrs_thres, rfbc_thres = \
'/Structural image/T1w_acpc_dc_restore_brain1.25.nii.gz') fiber = nibtck.TckFile.load( '/nfs/s2/userhome/quyukun/workingdir/fiberdata/100206/selectedfiber/' '100206_IFO_L_prob25.tck') fiber_data = fiber.streamlines affine = T1w.affine img_T1w_data = T1w.get_data() D33 = 1.0 D44 = 0.02 t = 1 k = EnhancementKernel(D33, D44, t) # Apply FBC measures fbc = FBCMeasures(fiber_data, k) #Calculate LFBC for original fibers fbc_sl_orig, clrs_orig, rfbc_orig = fbc.get_points_rfbc_thresholded( 0, emphasis=0.01) # Apply a threshold on the RFBC to remove spurious fibers fbc_sl_thres, clrs_thres, rfbc_thres = fbc.get_points_rfbc_thresholded( 0.125, emphasis=0.01) print("The process is already running here.") # Visualize the results from dipy.viz import window, actor # Enables/disables interactive visualization