Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit c179b70

Browse files
MariaNattestadcopybara-github
authored andcommitted
Specify PNG image format in nucleus.util.vis.
PiperOrigin-RevId: 317767407
1 parent 2e2f38c commit c179b70

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

nucleus/util/vis.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
from __future__ import division
2424
from __future__ import print_function
2525

26-
from nucleus.io import gfile
2726
from IPython import display
2827
import numpy as np
2928
from PIL import Image
3029
from PIL import ImageDraw
3130

31+
from nucleus.io import gfile
3232
from nucleus.protos import variants_pb2
3333

3434
DEEPVARIANT_CHANNEL_NAMES = [
@@ -264,7 +264,10 @@ def save_to_png(arr,
264264
265265
Args:
266266
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.
268271
image_mode: "RGB" or "L". Leave as default=None to choose based on image
269272
dimensions.
270273
show: bool. Whether to display the image using IPython (for notebooks).
@@ -298,6 +301,9 @@ def save_to_png(arr,
298301
# Saving to a temporary file is needed even when showing in a notebook
299302
if path is None:
300303
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)
301307
with gfile.Open(path, 'wb') as fout:
302308
img.save(fout, format=path.split('.')[-1])
303309

0 commit comments

Comments
 (0)