PY-67

Save and Reload an Image Artifact

  • Medium
  • Image Artifacts
  • Python

Task

Write save_and_check_image(path, image, mode, encode_image, decode_image). Mode is "L" for a two-dimensional image or "RGB" for a three-dimensional image with three channels. The input must have dtype uint8 and the declared shape. Return {"status":"invalid image", "shape":None, "dtype":None, "equal":False} without calling either helper when it does not.

Otherwise pass an independent contiguous copy to encode_image(path, copy, mode), then call decode_image(path, mode). Return the reloaded shape and dtype string. Status is "ok" and equal is true only when shape, dtype, and every value exactly match the saved copy; otherwise status is "reload mismatch". Do not modify the input.

Example

If a supplied codec reloads one changed pixel, shape and dtype may still match, but equal is false and status is "reload mismatch".

Your implementation

You may import NumPy as np. The helpers own image-file syntax. Do not print or ask for input.