From d528e08977568430f9e5da7ded54b5822d8256bc Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Tue, 2 Jun 2020 17:23:54 -0300 Subject: [PATCH] Remove imgnormalize (FIX #235) --- invesalius/data/imagedata_utils.py | 34 ++++------------------------------ invesalius/segmentation/brain/segment.py | 2 +- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/invesalius/data/imagedata_utils.py b/invesalius/data/imagedata_utils.py index 8b9e362..e1fbd98 100644 --- a/invesalius/data/imagedata_utils.py +++ b/invesalius/data/imagedata_utils.py @@ -500,34 +500,6 @@ def img2memmap(group): return matrix, scalar_range, temp_file -def imgnormalize(data, srange=(0, 255)): - """ - Normalize image pixel intensity for int16 gray scale values. - - :param data: image matrix - :param srange: range for normalization, default is 0 to 255 - :return: normalized pixel intensity matrix - """ - - dataf = numpy.asarray(data) - rangef = numpy.asarray(srange) - faux = numpy.ravel(dataf).astype(float) - minimum = numpy.min(faux) - maximum = numpy.max(faux) - lower = rangef[0] - upper = rangef[1] - - if minimum == maximum: - datan = numpy.ones(dataf.shape)*(upper + lower) / 2. - else: - datan = (faux-minimum)*(upper-lower) / (maximum-minimum) + lower - - datan = numpy.reshape(datan, dataf.shape) - datan = datan.astype(numpy.int16) - - return datan - - def get_LUT_value_255(data, window, level): shape = data.shape data_ = data.ravel() @@ -539,6 +511,8 @@ def get_LUT_value_255(data, window, level): return data -def image_normalize(image, min_=0.0, max_=1.0): +def image_normalize(image, min_=0.0, max_=1.0, output_dtype=np.int16): + output = np.empty(shape=image.shape, dtype=output_dtype) imin, imax = image.min(), image.max() - return (image - imin) * ((max_ - min_) / (imax - imin)) + min_ + output[:] = (image - imin) * ((max_ - min_) / (imax - imin)) + min_ + return output diff --git a/invesalius/segmentation/brain/segment.py b/invesalius/segmentation/brain/segment.py index 778d417..a79405a 100644 --- a/invesalius/segmentation/brain/segment.py +++ b/invesalius/segmentation/brain/segment.py @@ -64,7 +64,7 @@ def brain_segment(image, probability_array, comm_array): model.load_weights(str(folder.joinpath("model.h5"))) model.compile("Adam", "binary_crossentropy") - image = imagedata_utils.image_normalize(image, 0.0, 1.0) + image = imagedata_utils.image_normalize(image, 0.0, 1.0, output_dtype=np.float32) sums = np.zeros_like(image) # segmenting by patches for completion, sub_image, patch in gen_patches(image, SIZE, OVERLAP): -- libgit2 0.21.2