Skip to content

Commit

Permalink
added example code snippet for depth images
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed May 8, 2024
1 parent 1977c5e commit deb60e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ import pillow_heif
pillow_heif.register_avif_opener()
```

### Accessing Depth Images

```python3
from PIL import Image
from pillow_heif import register_heif_opener
import numpy as np

register_heif_opener()

im = Image.open("../tests/images/heif_other/pug.heic")
if im.info["depth_images"]:
depth_im = im.info["depth_images"][0] # Access the first depth image (usually there will be only one).
# Depth images are instances of `class HeifDepthImage(BaseImage)`,
# so work with them as you would with any usual image in pillow_heif.
# Depending on what you need the depth image for, you can convert it to a NumPy array or convert it to a Pillow image.
pil_im = depth_im.to_pillow()
np_im = np.asarray(depth_im)
print(pil_im)
print(pil_im.info["metadata"])
```


### More Information

- [Documentation](https://pillow-heif.readthedocs.io/)
Expand Down
21 changes: 21 additions & 0 deletions pi-heif/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ if pi_heif.is_supported("input.heic"):
np_array = np.asarray(heif_file)
```

### Accessing Depth Images

```python3
from PIL import Image
from pillow_heif import register_heif_opener
import numpy as np

register_heif_opener()

im = Image.open("../tests/images/heif_other/pug.heic")
if im.info["depth_images"]:
depth_im = im.info["depth_images"][0] # Access the first depth image (usually there will be only one).
# Depth images are instances of `class HeifDepthImage(BaseImage)`,
# so work with them as you would with any usual image in pillow_heif.
# Depending on what you need the depth image for, you can convert it to a NumPy array or convert it to a Pillow image.
pil_im = depth_im.to_pillow()
np_im = np.asarray(depth_im)
print(pil_im)
print(pil_im.info["metadata"])
```

### Wheels

| **_Wheels table_** | macOS<br/>Intel | macOS<br/>Silicon | Windows<br/>64bit | musllinux* | manylinux* |
Expand Down

0 comments on commit deb60e3

Please sign in to comment.