flatironinstitute / neurosift

Browser-based NWB visualization and DANDI exploration
Apache License 2.0
45 stars 6 forks source link

Neurosfit widget for images can't display RGB #180

Open h-mayorquin opened 5 months ago

h-mayorquin commented 5 months ago
import numpy as np 
import matplotlib.pyplot as plt
# Initialize an RGBA image with zeros
img = np.zeros((1000, 1000, 3))

# Set the desired region to white (1, 1, 1, 1) in RGBA
img[:, 200:400, :] = [1, 1, 1]

from pynwb.testing.mock.file import mock_NWBFile
from pynwb.image import RGBImage, Images

nwbfile = mock_NWBFile()

image = RGBImage(name='test_image', data=img)

images_container = Images(
    name="stimuli",
    images=[image],
    description=f"test image",
)

nwbfile.add_stimulus(images_container)

from pynwb import NWBHDF5IO

with NWBHDF5IO('test.nwb', 'w') as io:
    io.write(nwbfile)

with NWBHDF5IO('test.nwb', 'r') as io:
    nwbfile_read = io.read()
    image_data = nwbfile_read.stimulus["stimuli"].images["test_image"].data
    plt.imshow(image_data)

Error in neurosfit

image

magland commented 3 months ago

@h-mayorquin I got this working... but I assume values are integer between 0 and 255, so your particular example won't work.

Here's are a couple examples from DANDI

https://neurosift.app/?p=/nwb&url=https://api.dandiarchive.org/api/assets/acd6a646-f8c7-405e-9815-78fd6b6e442d/download/&dandisetId=000673&dandisetVersion=0.240524.1758&tab=neurodata-item:/stimulus/templates/StimulusTemplates|Images

https://neurosift.app/?p=/nwb&url=https://api.dandiarchive.org/api/assets/ecfb1b42-96c4-4552-aeee-0f12c6da06d2/download/&dandisetId=000469&dandisetVersion=0.240123.1806&tab=neurodata-item:/stimulus/templates/StimulusTemplates|Images

h-mayorquin commented 3 months ago

@h-mayorquin I got this working... but I assume values are integer between 0 and 255, so your particular example won't work.

Because of the floats.

As discussed on https://github.com/flatironinstitute/neurosift/issues/179#issuecomment-2256078886 this seems to be working on my images so probably something wrong with my example.

Thanks.