Skip to content

Commit

Permalink
STYLE: Rename intensity_thresh_perc -> intensity_thresh_percentile
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellepace committed Jan 12, 2024
1 parent 8eaa344 commit fa9303b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ml4h/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def parse_args():
parser.add_argument('--structures_to_analyze', nargs='*', default=[], help='Structure names to include in the .tsv files and scatter plots')
parser.add_argument('--erosion_radius', default=1, type=int, help='Radius of the unit disk structuring element for erosion preprocessing')
parser.add_argument('--intensity_thresh', type=float, help='Threshold value for preprocessing')
parser.add_argument('--intensity_thresh_perc', type=float, help='Threshold percentile for preprocessing, between 0 and 100 inclusive')
parser.add_argument('--intensity_thresh_percentile', type=float, help='Threshold percentile for preprocessing, between 0 and 100 inclusive')
parser.add_argument('--intensity_thresh_k_means', nargs='*', default=[], type=int, help='Preprocessing using k-means specified as two numbers, the first is the number of clusters and the second is the cluster index to keep')
parser.add_argument('--intensity_thresh_in_structures', nargs='*', default=[], help='Structure names whose pixels should be replaced if the images has intensity above the threshold')
parser.add_argument('--intensity_thresh_out_structure', help='Replacement structure name')
Expand Down
12 changes: 6 additions & 6 deletions ml4h/explorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,12 @@ def _get_csv_row(sample_id, means, medians, stds, date):
csv_row = [sample_id] + res[0].astype('str').tolist() + [date]
return csv_row

def _thresh_labels_above(y, img, intensity_thresh, intensity_thresh_perc, in_labels, out_label, nb_orig_channels):
def _thresh_labels_above(y, img, intensity_thresh, intensity_thresh_percentile, in_labels, out_label, nb_orig_channels):
y = np.argmax(y, axis=-1)[..., np.newaxis]
if intensity_thresh:
img_intensity_thresh = intensity_thresh
elif intensity_thresh_perc:
img_intensity_thresh = np.percentile(img, intensity_thresh_perc)
elif intensity_thresh_percentile:
img_intensity_thresh = np.percentile(img, intensity_thresh_percentile)
y[np.logical_and(img >= img_intensity_thresh, np.isin(y, in_labels))] = out_label
y = y[..., 0]
y = _to_categorical(y, nb_orig_channels)
Expand Down Expand Up @@ -829,7 +829,7 @@ def infer_stats_from_segmented_regions(args):
# Setup for intensity thresholding
do_intensity_thresh = args.intensity_thresh_in_structures and args.intensity_thresh_out_structure
if do_intensity_thresh:
assert (not (args.intensity_thresh and args.intensity_thresh_perc))
assert (not (args.intensity_thresh and args.intensity_thresh_percentile))
assert (not (args.intensity_thresh_k_means and len(args.intensity_thresh_in_structures) > 1))
intensity_thresh_in_channels = [tm_out.channel_map[k] for k in args.intensity_thresh_in_structures]
intensity_thresh_out_channel = tm_out.channel_map[args.intensity_thresh_out_structure]
Expand Down Expand Up @@ -881,7 +881,7 @@ def infer_stats_from_segmented_regions(args):

if args.analyze_ground_truth:
if do_intensity_thresh:
y_true = _thresh_labels_above(y_true, img, args.intensity_thresh, args.intensity_thresh_perc, intensity_thresh_in_channels, intensity_thresh_out_channel, nb_orig_channels)
y_true = _thresh_labels_above(y_true, img, args.intensity_thresh, args.intensity_thresh_percentile, intensity_thresh_in_channels, intensity_thresh_out_channel, nb_orig_channels)
y_true = np.delete(y_true, bad_channels, axis=-1)
if args.erosion_radius > 0:
y_true = binary_erosion(y_true, structure).astype(y_true.dtype)
Expand All @@ -892,7 +892,7 @@ def infer_stats_from_segmented_regions(args):
inference_writer_true.writerow(csv_row_true)

if do_intensity_thresh:
y_pred = _thresh_labels_above(y_pred, img, args.intensity_thresh, args.intensity_thresh_perc, intensity_thresh_in_channels, intensity_thresh_out_channel, nb_orig_channels)
y_pred = _thresh_labels_above(y_pred, img, args.intensity_thresh, args.intensity_thresh_percentile, intensity_thresh_in_channels, intensity_thresh_out_channel, nb_orig_channels)
y_pred = np.delete(y_pred, bad_channels, axis=-1)
if args.erosion_radius > 0:
y_pred = binary_erosion(y_pred, structure).astype(y_pred.dtype)
Expand Down

0 comments on commit fa9303b

Please sign in to comment.