Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Specify PNG image format in nucleus.util.vis.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 317767407
  • Loading branch information
MariaNattestad authored and copybara-github committed Jun 23, 2020
1 parent 2e2f38c commit c179b70
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nucleus/util/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from __future__ import division
from __future__ import print_function

from nucleus.io import gfile
from IPython import display
import numpy as np
from PIL import Image
from PIL import ImageDraw

from nucleus.io import gfile
from nucleus.protos import variants_pb2

DEEPVARIANT_CHANNEL_NAMES = [
Expand Down Expand Up @@ -264,7 +264,10 @@ def save_to_png(arr,
Args:
arr: numpy array. Input array to save.
path: str. file path at which to save the image.
path: str. File path at which to save the image. A .png prefix is added if
the path does not already have one. Leave empty to save at /tmp/tmp.png,
which is useful when only temporarily showing the image in a Colab
notebook.
image_mode: "RGB" or "L". Leave as default=None to choose based on image
dimensions.
show: bool. Whether to display the image using IPython (for notebooks).
Expand Down Expand Up @@ -298,6 +301,9 @@ def save_to_png(arr,
# Saving to a temporary file is needed even when showing in a notebook
if path is None:
path = '/tmp/tmp.png'
elif not path.endswith('.png'):
# Only PNG is supported because JPEG files are unnecessarily 3 times larger.
path = '{}.png'.format(path)
with gfile.Open(path, 'wb') as fout:
img.save(fout, format=path.split('.')[-1])

Expand Down

0 comments on commit c179b70

Please sign in to comment.