Skip to content

Commit

Permalink
add possibility to show the background ROI
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Schramm committed Aug 24, 2020
1 parent 53cb07c commit dc4fafe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/wb_nema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

# try also doing the fit without fixing the radii
fitres, sphere_results = nema.fit_WB_NEMA_sphere_profiles(vol, voxsize, sameSignal = True,
Rfix = [18.5, 14.0, 11.0, 8.5, 6.5, 5.])
Rfix = [18.5, 14.0, 11.0, 8.5, 6.5, 5.],
showBGROI = True)

print('fit with same signal and fixed radii')
print(sphere_results)
Expand Down
25 changes: 20 additions & 5 deletions pynemaiqpet/nema_wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from lmfit import Model

def find_background_roi(vol, voxsize, Rcenter = 82, edge_margin = 28.):
def find_background_roi(vol, voxsize, Rcenter = 82, edge_margin = 28., showROI= False):
""" find the 2D background ROI for a NEMA sphere phantom
Parameters
Expand All @@ -31,6 +31,9 @@ def find_background_roi(vol, voxsize, Rcenter = 82, edge_margin = 28.):
edge_margin : float (optional)
margin (mm) to stay away from the boarder of the phantom - default 28.
showROI : bool (optional)
whether to show 2D background ROI in a figure - default False
Returns
-------
Expand Down Expand Up @@ -71,6 +74,14 @@ def find_background_roi(vol, voxsize, Rcenter = 82, edge_margin = 28.):
tmp[...,sphere_sl] = bg_mask
bg_inds = np.where(tmp == 1)

if showROI:
fig, ax = py.subplots(figsize = (5,5))
ax.imshow(sphere_2d_img.T, cmap = py.cm.Greys, vmin = 0, vmax = np.percentile(sphere_2d_img,99.9))
ax.contour(bg_mask.T)
ax.set_title(f'background ROI slice {sphere_sl}')
fig.tight_layout()
fig.show()

return bg_inds

#--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -648,7 +659,8 @@ def fit_WB_NEMA_sphere_profiles(vol,
FWHMfix = None,
wm = 'dist',
nmax_spheres = 6,
sameSignal = False):
sameSignal = False,
showBGROI = False):
""" Analyse the sphere profiles of a NEMA scan
Parameters
Expand All @@ -674,11 +686,14 @@ def fit_WB_NEMA_sphere_profiles(vol,
wm : str, optional
the weighting method of the data (equal, dist, sqdist)
nmax_spheres: int (optional)
nmax_spheres: int, optional
maximum number of spheres to consider (default 6)
sameSignal : bool, optional
whether to forace all spheres to have the signal from the biggest sphere
whether to forace all spheres to have the signal from the biggest sphere
showBGROI : bool ,optional
whether to show the background ROI in a separate figure - default False
Returns
-------
Expand All @@ -695,7 +710,7 @@ def fit_WB_NEMA_sphere_profiles(vol,
vol = gaussian_filter(vol, sigma = sigmas)

# find the 2D background ROI
bg_inds = find_background_roi(vol, voxsizes)
bg_inds = find_background_roi(vol, voxsizes, showROI = showBGROI)
bg_mean = vol[bg_inds].mean()
bg_cov = vol[bg_inds].std() / bg_mean

Expand Down

0 comments on commit dc4fafe

Please sign in to comment.