|
a |
|
b/mediaug/visulize.py |
|
|
1 |
from IPython.display import display |
|
|
2 |
from PIL import Image |
|
|
3 |
from matplotlib import pyplot as plt |
|
|
4 |
|
|
|
5 |
|
|
|
6 |
def show_image(img): |
|
|
7 |
""" Display image in jupyter noteobok |
|
|
8 |
Args: |
|
|
9 |
img (np.array): The image |
|
|
10 |
""" |
|
|
11 |
display(Image.fromarray(img)) |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
def plot_datapoint(dp): |
|
|
15 |
""" plot a datapoint image and mask side by side |
|
|
16 |
Args: |
|
|
17 |
dp (Datapoint): datapoint |
|
|
18 |
""" |
|
|
19 |
plt.figure(figsize=(15,15)) |
|
|
20 |
plt.subplot(121) |
|
|
21 |
plt.imshow(dp.img) |
|
|
22 |
plt.axis('off') |
|
|
23 |
plt.subplot(122) |
|
|
24 |
plt.imshow(dp.mask) |
|
|
25 |
plt.axis('off') |
|
|
26 |
plt.show() |
|
|
27 |
|
|
|
28 |
def plot_img_and_mask(img, mask): |
|
|
29 |
""" plot image next to mask |
|
|
30 |
Args: |
|
|
31 |
img (np.array): image |
|
|
32 |
mask (np.array): mask |
|
|
33 |
""" |
|
|
34 |
plt.figure(figsize=(15,15)) |
|
|
35 |
plt.subplot(121) |
|
|
36 |
plt.imshow(img) |
|
|
37 |
plt.axis('off') |
|
|
38 |
plt.subplot(122) |
|
|
39 |
plt.imshow(mask) |
|
|
40 |
plt.axis('off') |
|
|
41 |
plt.show() |