This code is repeated later.  Can you move it to a function, like "normalize_image"?  Even if we remove it later, better to have only one place to make changes.