def normalize(im, invert=False, scale=None, dtype=np.float64):
if dtype not in {np.float16, np.float32, np.float64}:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>out = im.astype('<STR_LIT:float>').copy()<EOL>scale = scale or (<NUM_LIT:0.0>, <NUM_LIT>)<EOL>l, u = (float(i) for i in scale)<EOL>out = (out - l) / (u - l)<EOL>if invert:<EOL><INDENT>out = -out + (out.max() + out.min())<EOL><DEDENT>return out.astype(dtype)<EOL>
Normalize a field to a (min, max) exposure range, default is (0, 255).
(min, max) exposure values. Invert the image if requested.