pylinac icon indicating copy to clipboard operation
pylinac copied to clipboard

Image array normalization uses significant amounts of memory

Open Quantico-Bullet opened this issue 1 year ago • 1 comments

Description of the bug Normalization of image arrays using the normalize function in the array_utils.py (line: 57) uses a significant amount of memory due to conversion of the initial array dtype from np.int16 to np.float64 for the returned array.

To Reproduce/Check Simply amend the code to be as follows:

@validate(array=array_not_empty)
def normalize(array: np.ndarray, value: float | None = None) -> np.ndarray:
    """Normalize an array to the passed value. If not value is passed, normalize to the maximum value"""
    print("dtype before: ", array.dtype)
    if value is None:
        val = array.max()
    else:
        val = value
    array = array / val
    print("dtype after: ", array.dtype)
    return array

Possible solution Return the array with dtype np.float16 using:

return array.astype(np.float16)

Quantico-Bullet avatar Aug 02 '24 17:08 Quantico-Bullet

I can add a parameter for the desired datatype to the call.

jrkerns avatar Sep 04 '24 20:09 jrkerns