Skip to content

Commit 46f7846

Browse files
committed
quick fixes
1 parent f4bd085 commit 46f7846

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

TPTBox/core/nii_wrapper.py

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

955+
def get_histogram(self, bins=256, hrange=None, density=False, c_val:float|None=None):
956+
"""Returns the histogram of the image array.
957+
958+
Args:
959+
bins (int, optional): Number of bins for the histogram. Defaults to 256.
960+
range (tuple, optional): Range of values to consider for the histogram. Defaults to None.
961+
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.
962+
c_val (float|None, optional): The value below which all values are set to c_val. Defaults to None.
963+
964+
Returns:
965+
tuple: A tuple containing the histogram values and the bin edges.
966+
"""
967+
arr = self.get_array()
968+
if c_val is not None:
969+
arr[arr <= c_val] = c_val
970+
return np.histogram(arr, bins=bins, range=hrange, density=density)
971+
955972
def match_histograms(self, reference:Image_Reference,c_val = 0,inplace=False):
956973
assert not self.seg
957974
ref_nii = to_nii(reference)

TPTBox/core/np_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def np_dilate_msk(
341341
data = out.copy()
342342
data[i != data] = 0
343343
if use_crop:
344-
lcrop = np_bbox_binary(data, px_dist=2, raise_error=False)
344+
lcrop = np_bbox_binary(data, px_dist=2 + n_pixel, raise_error=False)
345345
data = data[lcrop]
346346
msk_ibe_data = _binary_dilation(data, struct=struct)
347347

TPTBox/core/poi.py

Lines changed: 1 addition & 0 deletions
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):

0 commit comments

Comments
 (0)