-
Notifications
You must be signed in to change notification settings - Fork 6
Description
As part of the HPSS PR #62, Kate found a few improvements for SciCat thumbnail ingestion. I'm tracking these as a new issue rather than incorporating into that PR.
This is kind of a big block for the thumbnail creation, suggest splitting it into a one or a few separate functions so it can be tested independently.
Also fwiw I found that just saving the imshow of an array with [2,98] percentile and no axes to .png makes a good thumbnail without having to do 8 bit conversion and deal with PIL and all and and all the normalization... maybe worth exploring for you because it would get rid of a lot of code. But I guess it would add numpy and matplotlib as dependencies.
from pyscicat.client import (
encode_thumbnail
)
thumbnail = data[slice] # this is a numpy array of whatever type
vmin, vmax = np.percentile(thumbnail, [2, 98])
np.clip(thumbnail, vmin, vmax)
with tempfile.TemporaryDirectory() as tmpdir:
fig = plt.figure(figsize=(10,10))
# Add an axes that fills the entire figure
ax = fig.add_axes([0, 0, 1, 1])
# Turn off the axes
ax.set_axis_off()
ax.imshow(thumbnail, cmap='gray')
fig.show()
fig.savefig(os.path.join(tmpdir, 'thumbnail.png'))
thumbnail_encoded = encode_thumbnail(os.path.join(tmpdir, 'thumbnail.png'))
Originally posted by @kkamdin in #62 (comment)
With regards to encode_image_2_thumbnail(), SciCat now has a built in encode_thumbnail() function
I thought scicat has a method for this already, but maybe we're on an older version of the API.
Originally posted by @kkamdin in #62 (comment)
same comment here about piggybacking on matplot lib if you're not happy with the thumbnail resolution. Here are some of my results from trying different methods:
Originally posted by @kkamdin in #62 (comment)