Skip to content

Commit 8f438d7

Browse files
authored
Merge pull request #83 from Hendrik-code/quickfix
Quickfix
2 parents c6cd014 + e39f87e commit 8f438d7

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

TPTBox/core/nii_wrapper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,23 @@ def normalize_to_range_(self, min_value: int = 0, max_value: int = 1500, verbose
965965
self.set_dtype_(self_dtype)
966966
log.print(f"Shifted from range {mi, ma} to range {self.min(), self.max()}", verbose=verbose)
967967

968+
def get_histogram(self, bins=256, hrange=None, density=False, c_val:float|None=None):
969+
"""Returns the histogram of the image array.
970+
971+
Args:
972+
bins (int, optional): Number of bins for the histogram. Defaults to 256.
973+
range (tuple, optional): Range of values to consider for the histogram. Defaults to None.
974+
density (bool, optional): If True, the result is the probability density function at the bin, normalized such that the integral over the range is 1. Defaults to False.
975+
c_val (float|None, optional): The value below which all values are set to c_val. Defaults to None.
976+
977+
Returns:
978+
tuple: A tuple containing the histogram values and the bin edges.
979+
"""
980+
arr = self.get_array()
981+
if c_val is not None:
982+
arr[arr <= c_val] = c_val
983+
return np.histogram(arr, bins=bins, range=hrange, density=density)
984+
968985
def match_histograms(self, reference:Image_Reference,c_val = 0,inplace=False):
969986
assert not self.seg
970987
ref_nii = to_nii(reference)
@@ -1268,6 +1285,7 @@ def filter_connected_components(self, labels: int |list[int]|None=None,min_volum
12681285
"""
12691286
assert self.seg, "This only works on segmentations"
12701287
arr = np_filter_connected_components(self.get_seg_array(), largest_k_components=max_count_component,label_ref=labels,connectivity=connectivity,return_original_labels=keep_label,min_volume=min_volume,max_volume=max_volume,removed_to_label=removed_to_label,)
1288+
assert arr.shape == self.shape, f"Shape mismatch: {arr.shape} != {self.shape}"
12711289
if keep_label and labels is not None:
12721290
if isinstance(labels,int):
12731291
labels = [labels]

TPTBox/core/np_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def np_dilate_msk(
357357
data = out.copy()
358358
data[i != data] = 0
359359
if use_crop:
360-
lcrop = np_bbox_binary(data, px_dist=2, raise_error=False)
360+
lcrop = np_bbox_binary(data, px_dist=2 + n_pixel, raise_error=False)
361361
data = data[lcrop]
362362
msk_ibe_data = _binary_dilation(data, struct=struct)
363363

TPTBox/core/poi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def apply_crop(self: Self, o_shift: tuple[slice, slice, slice] | Sequence[slice]
314314
"""
315315
origin: COORDINATE = None # type: ignore
316316
shape = None # type: ignore
317+
o_shift = tuple(o if o.start is not None else slice(0, None) for o in o_shift)
317318
try:
318319

319320
def shift(x, y, z):
@@ -1066,7 +1067,7 @@ def calc_centroids_from_two_masks(
10661067
org_shape = subreg_msk.shape
10671068
# crop to mask to speed up the segmentation
10681069
crop = vert_msk.compute_crop()
1069-
crop = subreg_msk.compute_crop(maximum_size=crop)
1070+
# crop = subreg_msk.compute_crop(maximum_size=crop)
10701071
# crop = (slice(0, subreg_msk.shape[0]), slice(0, subreg_msk.shape[1]), slice(0, subreg_msk.shape[2]))
10711072

10721073
vert_msk = vert_msk.apply_crop(crop)

0 commit comments

Comments
 (0)