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

Neurosift shows images rotated #179

Open
h-mayorquin opened this issue Jun 14, 2024 · 2 comments
Open

Neurosift shows images rotated #179

h-mayorquin opened this issue Jun 14, 2024 · 2 comments

Comments

@h-mayorquin
Copy link

image

But in neurosift:

image

Code to reproduce

import numpy as np 
img  = np.zeros((1000,1000))
img[:, 200:400] = 1

plt.imshow(img, cmap="gray")
# plt.imshow(np.rot90(img, k=1), cmap="gray")

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

nwbfile = mock_NWBFile()

image = GrayscaleImage(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, cmap="gray")
@magland
Copy link
Collaborator

magland commented Jul 24, 2024

Thanks @h-mayorquin for the very helpful example for calibration. I have fixed this.

@CodyCBakerPhD @bendichter This change is going to affect the Neurosift orientation of all Image neurodata objects. I know there was discussion about having a rotate button in NS, but in this case (where it's an "Image") I feel like there should be one true orientation, so if it works with @h-mayorquin 's example, then we should be good? I could be wrong about this though, that's why I'm tagging you.

BTW, a slightly updated script that adds a bit more structure to calibrate the vertical flip

import numpy as np
import matplotlib.pyplot as plt
from pynwb.testing.mock.file import mock_NWBFile
from pynwb.image import GrayscaleImage, Images
from pynwb import NWBHDF5IO


img = np.zeros((1000, 1500))
img[:, 200:400] = 1
img[0:50][:, 200:400] = 0.5

plt.imshow(img, cmap="gray")
# plt.imshow(np.rot90(img, k=1), cmap="gray")

nwbfile = mock_NWBFile()

image = GrayscaleImage(name="test_image", data=img)

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

nwbfile.add_stimulus(images_container)

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, cmap="gray")

plt.show()

Then compare that plot with

neurosift view-nwb test.nwb

@h-mayorquin
Copy link
Author

Thanks a bunch!

This works for my current dataset:
image

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