Charles Kabui
commited on
Commit
·
1843265
1
Parent(s):
1a7472d
show_tile_images
Browse files- utils/show_tile_images.py +10 -1
utils/show_tile_images.py
CHANGED
|
@@ -1,8 +1,17 @@
|
|
| 1 |
-
from utils.fig2img import fig2img
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def show_tile_images(
|
| 8 |
images: List[np.ndarray | Image.Image],
|
|
|
|
|
|
|
| 1 |
import matplotlib.pyplot as plt
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
from typing import List
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
def fig2img(fig: plt.Figure):
|
| 8 |
+
"""Convert a Matplotlib figure to a PIL Image and return it"""
|
| 9 |
+
plt.close()
|
| 10 |
+
buf = io.BytesIO()
|
| 11 |
+
fig.savefig(buf)
|
| 12 |
+
buf.seek(0)
|
| 13 |
+
img = Image.open(buf)
|
| 14 |
+
return img
|
| 15 |
|
| 16 |
def show_tile_images(
|
| 17 |
images: List[np.ndarray | Image.Image],
|