diff --git a/foa3d/odf.py b/foa3d/odf.py index 4c8cb5f..63fae55 100644 --- a/foa3d/odf.py +++ b/foa3d/odf.py @@ -432,14 +432,16 @@ def generate_odf_background(bg_img, bg_mrtrix_mmap, vxl_side): # get shape of new downsampled array new_shape = bg_mrtrix_mmap.shape[:-1] - # normalize + # image normalization: get global minimum and maximum values if bg_img.ndim == 3: - bg_img = normalize_image(bg_img) + min_glob = np.min(bg_img) + max_glob = np.max(bg_img) # loop over z-slices, and resize them for z in range(0, bg_img.shape[0], vxl_side): if bg_img.ndim == 3: - tmp_slice = np.mean(bg_img[z:z + vxl_side, ...], axis=0) + tmp_slice = normalize_image(bg_img[z:z + vxl_side, ...], min_val=min_glob, max_val=max_glob) + tmp_slice = np.mean(tmp_slice, axis=0) elif bg_img.ndim == 4: tmp_slice = 255.0 * np.sum(np.abs(bg_img[z, ...]), axis=-1) tmp_slice = np.where(tmp_slice <= 255.0, tmp_slice, 255.0) diff --git a/foa3d/utils.py b/foa3d/utils.py index d0fd5a8..77c44ee 100644 --- a/foa3d/utils.py +++ b/foa3d/utils.py @@ -402,7 +402,7 @@ def normalize_angle(angle, lower=0.0, upper=360.0, dtype=None): return norm_angle -def normalize_image(img, max_out_val=255.0, dtype=np.uint8): +def normalize_image(img, min_val=None, max_val=None, max_out_val=255.0, dtype=np.uint8): """ Normalize image data. @@ -410,6 +410,12 @@ def normalize_image(img, max_out_val=255.0, dtype=np.uint8): ---------- img: numpy.ndarray input image + + min_val: float + minimum input value + + max_val: float + maximum input value max_out_val: float maximum output value @@ -424,8 +430,10 @@ def normalize_image(img, max_out_val=255.0, dtype=np.uint8): """ # get min and max values - min_val = np.min(img) - max_val = np.max(img) + if min_val is None: + min_val = np.min(img) + if max_val is None: + max_val = np.max(img) # normalize if max_val != 0: