|
23 | 23 | from __future__ import division |
24 | 24 | from __future__ import print_function |
25 | 25 |
|
26 | | -from nucleus.io import gfile |
27 | 26 | from IPython import display |
28 | 27 | import numpy as np |
29 | 28 | from PIL import Image |
30 | 29 | from PIL import ImageDraw |
31 | 30 |
|
| 31 | +from nucleus.io import gfile |
32 | 32 | from nucleus.protos import variants_pb2 |
33 | 33 |
|
34 | 34 | DEEPVARIANT_CHANNEL_NAMES = [ |
@@ -264,7 +264,10 @@ def save_to_png(arr, |
264 | 264 |
|
265 | 265 | Args: |
266 | 266 | arr: numpy array. Input array to save. |
267 | | - path: str. file path at which to save the image. |
| 267 | + path: str. File path at which to save the image. A .png prefix is added if |
| 268 | + the path does not already have one. Leave empty to save at /tmp/tmp.png, |
| 269 | + which is useful when only temporarily showing the image in a Colab |
| 270 | + notebook. |
268 | 271 | image_mode: "RGB" or "L". Leave as default=None to choose based on image |
269 | 272 | dimensions. |
270 | 273 | show: bool. Whether to display the image using IPython (for notebooks). |
@@ -298,6 +301,9 @@ def save_to_png(arr, |
298 | 301 | # Saving to a temporary file is needed even when showing in a notebook |
299 | 302 | if path is None: |
300 | 303 | path = '/tmp/tmp.png' |
| 304 | + elif not path.endswith('.png'): |
| 305 | + # Only PNG is supported because JPEG files are unnecessarily 3 times larger. |
| 306 | + path = '{}.png'.format(path) |
301 | 307 | with gfile.Open(path, 'wb') as fout: |
302 | 308 | img.save(fout, format=path.split('.')[-1]) |
303 | 309 |
|
|
0 commit comments