PY-66

Load an Image into a Declared Array Form

  • Medium
  • Image Arrays
  • Python

Task

Write load_image_array(path, mode, decode_image). Mode is "L" for a grayscale (height, width) array or "RGB" for a (height, width, 3) array. decode_image(path, mode) is a supplied codec boundary that returns a NumPy array.

Return (image, evidence, status). Reject unknown mode, wrong shape, or any dtype other than uint8 with (None, None, "unknown mode"), "wrong shape", or "wrong dtype". On success, return an independent C-contiguous copy, evidence {"mode": mode, "shape": image.shape, "dtype": "uint8", "minimum": minimum, "maximum": maximum}, and "ok". For an empty image, minimum and maximum are None.

Example

A decoder returning an RGB uint8 array of shape (4, 5, 3) produces that shape in evidence. Changing the returned array later must not alter the loaded copy.

Your implementation

You may import NumPy as np. Do not implement an image codec, modify the decoder's array, print, or ask for input.