Skip to content

Commit

Permalink
decode JPEG image data to numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlou05 committed Mar 30, 2024
1 parent 2f309e4 commit 4c16120
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lte/image_decode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Decodes images from JPEG bytes to numpy array.
"""

import io

from PIL import Image
import numpy as np


def decode(data: "io.BytesIO | bytes") -> np.ndarray:
"""
Decodes a JPEG encoded image and returns it as a numpy array.
Args:
data: bytes object containing the JPEG encoded image
Returns:
NDArray with in RGB format (Height, Width, 3)
"""
image = Image.open(data, formats=['JPEG'])

return np.asarray(image)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pytest
opencv-python
numpy

# Module lte
Pillow

# Module mavlink
dronekit

Expand Down

0 comments on commit 4c16120

Please sign in to comment.