Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mediapy display_images() downsamples images seemingly arbitrarily.... #42

Open
erictabellion opened this issue Feb 8, 2024 · 3 comments

Comments

@erictabellion
Copy link

Issue tested with version: #41

a) If I call media.show_images() once passing it a dict of 32 images, each with shape (512, 512, 3), it stubbornly displays a row matrix of images that are (256, 256, 3) each.

b) If I call media.show_images() 32 times passing it a dict with a single image each time, each with shape (512, 512, 3), it displays the images at the correct resolution (however the images are displayed one below each other which is not what I want).

c) In case a), if I pass the argument height=512 then the images are displayed pixelated 2x: it looks like mediapy makes a 256x256 internal image buffer and displays it pixelated at 512x512.

d) Passing downsample=False doesn't fix the issue either (too easy-no points).

e) I also have a repro case where it dowsamples from 480 to 240 so this seems like a 2x downsample bug.

f) Aha!!! It looks like displaying a smaller number of images (6 vs. 32) works as intended.

Looks like it is some kind of cap on total memory it can consume?

@hhoppe
Copy link
Collaborator

hhoppe commented Feb 8, 2024

Hi Eric!

I can't seem to be able to reproduce it.
In Colab, I tried:

import mediapy as media
images = {f'image{index}': media.color_ramp((512, 512)) for index in range(32)}
media.show_images(images)

and it shows 32 images of size (512, 512, 3).
When I right-click Save_as_image on one of them, it does save as a 512x512 image.

In Jupyter Lab, it shows 32 shrunk images such that all of them appear in the window width.
But again when I shift-right-click Save_as_image it is natively 512x512.
(The scaling there might be adjustable using CSS styles.)

Please give us more details. Perhaps try Chrome Developer Tools (Control-Shift-i) to examine the native image resolution?
Is there any OS display scaling (e.g., Windows "Make everything bigger") or Chrome Zoom scaling?

@erictabellion
Copy link
Author

Hi Hugues!

All the input image resolutions I reported were obtained printing the np.ndarray.shape.
All the display resolutions I reported were obtained after right-clicking on the image displayed by mediapy and selecting "Open in a new tab" in Google Chrome. I then hover the mouse over the new tab and a tooltip appears showing the native resolution of the image being displayed among other things. right-click+save the image produces an image file of that resolution.

In my use-case I get an image_batch from my ML pipeline data-loader, with shape (1, 32, 512, 512, 3) and dtype=np.float32. I display it with:

def display_image_row(image_row):
  image_dict = {}
  for col in range(image_row.shape[0]):
    image_dict[f'{col}'] = image_row[col]
  media.show_images(image_dict, height=512, downsample=False, ylabel='row0')

display_image_row(image_batch[0])

Whether or not I convert the input image_batch first to uint8, I get the same issue.

image_batch = image_batch * 255
image_batch = image_batch.astype(np.uint8)

@hhoppe
Copy link
Collaborator

hhoppe commented Feb 8, 2024

Are you using Colab? Please see my shared Colab notebook in https://colab.research.google.com/drive/1pkTsS0v40kbf66d6a_rfMS1V6VrS247d?usp=sharing
which seems to work fine with both np.uint8 and np.float32 and with/without the height and downsample flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants