Skip to content

Commit

Permalink
STYLE: Rename _unit_disk(r) to unit_disk(r)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellepace committed Jan 12, 2024
1 parent ba4e5fd commit 55a58b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ml4h/explorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ml4h.plots import evaluate_predictions, subplot_rocs, subplot_scatters, plot_categorical_tmap_over_time
from ml4h.defines import JOIN_CHAR, MRI_SEGMENTED_CHANNEL_MAP, CODING_VALUES_MISSING, CODING_VALUES_LESS_THAN_ONE
from ml4h.defines import TENSOR_EXT, IMAGE_EXT, ECG_CHAR_2_IDX, ECG_IDX_2_CHAR, PARTNERS_CHAR_2_IDX, PARTNERS_IDX_2_CHAR, PARTNERS_READ_TEXT
from ml4h.tensorize.tensor_writer_ukbb import _unit_disk
from ml4h.tensorize.tensor_writer_ukbb import unit_disk

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
Expand Down Expand Up @@ -815,7 +815,7 @@ def infer_stats_from_segmented_regions(args):

# Structuring element used for the erosion
if args.erosion_radius > 0:
structure = _unit_disk(args.erosion_radius)[np.newaxis, ..., np.newaxis]
structure = unit_disk(args.erosion_radius)[np.newaxis, ..., np.newaxis]

# Setup for intensity thresholding
do_intensity_thresh = args.intensity_thresh_in_structures and args.intensity_thresh_out_structure
Expand Down
8 changes: 4 additions & 4 deletions ml4h/tensorize/tensor_writer_ukbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,22 +647,22 @@ def _get_overlay_from_dicom(d, debug=False) -> Tuple[np.ndarray, np.ndarray]:
short_side = min((max_pos[0] - min_pos[0]), (max_pos[1] - min_pos[1]))
small_radius = max(MRI_MIN_RADIUS, short_side * MRI_SMALL_RADIUS_FACTOR)
big_radius = max(MRI_MIN_RADIUS+1, short_side * MRI_BIG_RADIUS_FACTOR)
small_structure = _unit_disk(small_radius)
small_structure = unit_disk(small_radius)
m1 = binary_closing(overlay, small_structure).astype(np.int)
big_structure = _unit_disk(big_radius)
big_structure = unit_disk(big_radius)
m2 = binary_closing(overlay, big_structure).astype(np.int)
anatomical_mask = m1 + m2
ventricle_pixels = np.count_nonzero(anatomical_mask == MRI_SEGMENTED_CHANNEL_MAP['ventricle'])
myocardium_pixels = np.count_nonzero(anatomical_mask == MRI_SEGMENTED_CHANNEL_MAP['myocardium'])
if ventricle_pixels == 0 and myocardium_pixels > MRI_MAX_MYOCARDIUM: # try to rescue small ventricles
erode_structure = _unit_disk(small_radius*1.5)
erode_structure = unit_disk(small_radius * 1.5)
anatomical_mask = anatomical_mask - binary_erosion(m1, erode_structure).astype(np.int)
ventricle_pixels = np.count_nonzero(anatomical_mask == MRI_SEGMENTED_CHANNEL_MAP['ventricle'])
myocardium_pixels = np.count_nonzero(anatomical_mask == MRI_SEGMENTED_CHANNEL_MAP['myocardium'])
return overlay, anatomical_mask, ventricle_pixels, myocardium_pixels


def _unit_disk(r) -> np.ndarray:
def unit_disk(r) -> np.ndarray:
y, x = np.ogrid[-r: r + 1, -r: r + 1]
return (x ** 2 + y ** 2 <= r ** 2).astype(np.int32)

Expand Down

0 comments on commit 55a58b0

Please sign in to comment.