I'm writing Python functions to process very large images and I'm trying to minimize memory footprint when possible. My question is this : when I pass an image((a numpy ndarray) to a processing function, does it make a copy of the image during processing? For example in the following code, while I call subtract_value
, will the function make a copy and increase memory usage?
def subtract_value(input, value): # this is defined in another module
input = input - value
return input
img = subtract_value(img, value) # this statement is part of a function
I understand if I write nested function I can definitely avoid this (Am I correct, by the way? ) but I'd like to make the function reusable by other programs.
def subtract_value(value):
nonlocal img
img = img - value
subtract_value(value)