Skip to content

Commit

Permalink
Merge pull request #388 from GSTT-CSC/94-BC-kernel
Browse files Browse the repository at this point in the history
Add command line option to change kernel size used in SNR task based on head or body coil.
  • Loading branch information
sophie22 authored Nov 28, 2023
2 parents 2ac4bd0 + 2f4293f commit c0ced4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions hazenlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
Usage:
hazen <task> <folder> [options]
hazen snr <folder> [--measured_slice_width=<mm>] [options]
hazen snr <folder> [--measured_slice_width=<mm>] [--coil=<head or body>] [options]
hazen acr_snr <folder> [--measured_slice_width=<mm>] [--subtract=<folder2>] [options]
hazen relaxometry <folder> --calc=<T1> --plate_number=<4> [options]
Expand All @@ -107,7 +107,6 @@
--plate_number=<n> Which plate to use for measurement: 4 or 5 (required)
"""


import importlib
import inspect
import logging
Expand Down Expand Up @@ -196,7 +195,8 @@ def main():
if arguments['snr'] or arguments['<task>'] == 'snr':
selected_task = 'snr'
task = init_task(selected_task, files, report, report_dir,
measured_slice_width=arguments['--measured_slice_width'])
measured_slice_width=arguments['--measured_slice_width'],
coil=arguments['--coil'])
result = task.run()
elif arguments['acr_snr'] or arguments['<task>'] == 'acr_snr':
selected_task = 'acr_snr'
Expand Down
15 changes: 13 additions & 2 deletions hazenlib/tasks/snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ class SNR(HazenTask):

def __init__(self, **kwargs):
super().__init__(**kwargs)

# measured slice width is expected to be a floating point number
try:
self.measured_slice_width = float(kwargs["measured_slice_width"])
except:
self.measured_slice_width = None

# Determining kernel size based on coil choice. Values of 9 and 25 come from McCann 2013 paper.
try:
coil = kwargs["coil"]
if coil is None or coil.lower() in ["hc", "head"]:
self.kernel_size = 9
elif coil.lower() in ["bc", "body"]:
self.kernel_size = 25
except:
self.kernel_size=9

def run(self) -> dict:

results = self.init_result_dict()
Expand Down Expand Up @@ -134,10 +145,10 @@ def filtered_image(self, dcm: pydicom.Dataset) -> np.array:
a = dcm.pixel_array.astype('int')

# filter size = 9, following MATLAB code and McCann 2013 paper for head coil, although note McCann 2013 recommends 25x25 for body coil.
filter_size = 9

# 9 for head coil, 25 for body coil
# TODO make kernel size optional
filtered_array = ndimage.uniform_filter(a, filter_size, mode='constant')
filtered_array = ndimage.uniform_filter(a, self.kernel_size, mode='constant')
return filtered_array

def get_noise_image(self, dcm: pydicom.Dataset) -> np.array:
Expand Down

2 comments on commit c0ced4a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
hazenlib
   ACRObject.py1071190%74, 77–79, 84–87, 125, 168–169
   HazenTask.py29390%41–43
   __init__.py571574%165, 196–200, 202–206, 208–210, 225–230, 234
   exceptions.py21576%17–21, 38
   utils.py1894377%61, 65, 75, 80, 117, 124–129, 140, 143–150, 170–172, 190–192, 211–213, 222, 227, 233, 284, 287, 295–300, 303, 346, 355, 371
hazenlib/tasks
   acr_geometric_accuracy.py1196248%42–86, 96–121, 134–168
   acr_ghosting.py1074261%35–51, 77–79, 109–111, 145–187
   acr_slice_position.py1364865%47–68, 194–241
   acr_slice_thickness.py1366056%34–53, 162–224
   acr_snr.py1365857%46, 51–92, 102, 172–182, 216–231, 264–281
   acr_spatial_resolution.py2066867%59–86, 131, 174, 187–196, 278–330
   acr_uniformity.py813260%38–56, 112–138
   ghosting.py1515166%19–36, 51, 113–114, 118, 128–129, 155–157, 174–176, 222–259
   relaxometry.py2918969%207–208, 210, 221–224, 230–236, 268–312, 353, 387–405, 580, 626–628, 695, 769–791, 809–824
   slice_position.py1244068%26, 31–62, 114–115, 141, 221, 229–247
   slice_width.py3525285%36–38, 42, 107, 166–187, 441, 446–447, 453, 458, 516–517, 767–809
   snr.py1757159%41–44, 72, 89–94, 190–208, 223–232, 250–260, 287–297, 302–312, 343–357, 362–370, 399–413
   snr_map.py108199%152
   spatial_resolution.py2494482%41–43, 47, 68, 153, 212, 338–375
   uniformity.py791976%47–49, 53, 95–96, 103, 137–152
TOTAL287881472% 

Tests Skipped Failures Errors Time
201 0 💤 0 ❌ 0 🔥 2m 18s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
hazenlib
   ACRObject.py1071190%74, 77–79, 84–87, 125, 168–169
   HazenTask.py28389%41–43
   __init__.py561573%165, 196–200, 202–206, 208–210, 225–230, 234
   exceptions.py21576%17–21, 38
   utils.py1894377%61, 65, 75, 80, 117, 124–129, 140, 143–150, 170–172, 190–192, 211–213, 222, 227, 233, 284, 287, 295–300, 303, 346, 355, 371
hazenlib/tasks
   acr_geometric_accuracy.py1196248%42–86, 96–121, 134–168
   acr_ghosting.py1074261%35–51, 77–79, 109–111, 145–187
   acr_slice_position.py1364865%47–68, 194–241
   acr_slice_thickness.py1366056%34–53, 162–224
   acr_snr.py1365857%46, 51–92, 102, 172–182, 216–231, 264–281
   acr_spatial_resolution.py2066867%59–86, 131, 174, 187–196, 278–330
   acr_uniformity.py813260%38–56, 112–138
   ghosting.py1515166%19–36, 51, 113–114, 118, 128–129, 155–157, 174–176, 222–259
   relaxometry.py2908969%207–208, 210, 221–224, 230–236, 268–312, 353, 387–405, 580, 626–628, 695, 769–791, 809–824
   slice_position.py1244068%26, 31–62, 114–115, 141, 221, 229–247
   slice_width.py3505285%36–38, 42, 107, 166–187, 441, 446–447, 453, 458, 516–517, 767–809
   snr.py1757159%41–44, 72, 89–94, 190–208, 223–232, 250–260, 287–297, 302–312, 343–357, 362–370, 399–413
   snr_map.py107199%152
   spatial_resolution.py2484482%41–43, 47, 68, 153, 212, 338–375
   uniformity.py791976%47–49, 53, 95–96, 103, 137–152
TOTAL287181472% 

Tests Skipped Failures Errors Time
201 0 💤 0 ❌ 0 🔥 2m 17s ⏱️

Please sign in to comment.