code: def test_jpeg():
      """Test lossy image codec"""
      for size in [(300, 200), (300, 200, 3)]:
          expected_image = np.random.randint(
              0, 255, size=size, dtype=np.uint8
          )
          codec = CompressedImageCodec("jpeg", quality=100)
          assert codec.image_codec == "jpeg"
          field = UnischemaField(
              name="field_image",
              numpy_dtype=np.uint8,
              shape=size,
              codec=codec,
              nullable=False,
          )
  
          actual_image = codec.decode(
              field, codec.encode(field, expected_image)
          )
          # Check a non exact match between the images. Verifying reasonable mean absolute error (up to 10)
          mean_abs_error = np.mean(
              np.abs(
                  expected_image.astype(np.float)
                  - actual_image.astype(np.float)
              )
          )
          # The threshold is relatively high as compressing random images with jpeg results in a significant
          # quality loss
          assert mean_abs_error < 50
          assert np.any(expected_image != actual_image, axis=None)
  
file_path: petastorm/petastorm/tests/test_codec_compressed_image.py
imports: import io
  import numpy
  import pytest
  from PIL import Image
  from petastorm.codecs import CompressedImageCodec
  from petastorm.unischema import UnischemaField
label_desc: Use image node_id 2 for calling a global function with example usage: test_jpeg() without return types