You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, the resulting dataset that is displayed does not show the correct range of pixel values; they tend to be clustered around 109. Additionally, the sliders for navigating through the dataset do not change the displayed image when clicked.
What I Did
As a check, and because I'm ultimately interested in images with low contrast, I modified the example to show images of random integers between 90 and 110 with a dtype of np.uint16.
fromtypingimportAnyimportndvimportnumpyasnpif__name__=="__main__":
classMyArrayThing:
def__init__(self, shape: tuple[int, ...]) ->None:
self.shape=shapeself._data=np.random.randint(90, 110, shape, dtype=np.uint16)
def__getitem__(self, item: Any) ->np.ndarray:
returnself._data[item] # type: ignore [no-any-return]classMyWrapper(ndv.DataWrapper[MyArrayThing]):
@classmethoddefsupports(cls, data: Any) ->bool:
ifisinstance(data, MyArrayThing):
returnTruereturnFalsedefsizes(self):
"""Return a mapping of {dim: size} for the data"""return {f"dim_{k}": vfork, vinenumerate(self.data.shape)}
defisel(self, indexers) ->Any:
"""Convert mapping of {dim: index} to conventional indexing"""idx=tuple(indexers.get(k, slice(None)) forkinrange(len(self.data.shape)))
returnself.data[idx]
data=MyArrayThing((10, 3, 256, 256))
ndv.imshow(data)
A screenshot of what I see immediately after running the script follows:
I performed two sanity checks:
I checked the value of the _data attribute of the MyArrayThing instance and the array contains the correct range of values.
I used a normal numpy array data = np.random.randint(90, 110, (10, 3, 256, 256), dtype=np.uint16) in the call to ndv.imshow(data) and everything worked as expected.
I looked briefly into the code and it looks like the data is ultimately owned by a DataWrapper instance, so any distortion of the underlying values might occur there.
Edits
Minor typo in point two of the sanity checks
The text was updated successfully, but these errors were encountered:
Description
After a discussion with @tlambert03 on image.sc, I tested an example that he provided that demonstrates how to create custom
DataWrappers
: https://github.com/pyapp-kit/ndv/blob/5fefbd196242474c351587ded75aaff32ed8663c/examples/custom_store.pyUnfortunately, the resulting dataset that is displayed does not show the correct range of pixel values; they tend to be clustered around 109. Additionally, the sliders for navigating through the dataset do not change the displayed image when clicked.
What I Did
As a check, and because I'm ultimately interested in images with low contrast, I modified the example to show images of random integers between 90 and 110 with a dtype of
np.uint16
.A screenshot of what I see immediately after running the script follows:
I performed two sanity checks:
_data
attribute of theMyArrayThing
instance and the array contains the correct range of values.data = np.random.randint(90, 110, (10, 3, 256, 256), dtype=np.uint16)
in the call tondv.imshow(data)
and everything worked as expected.I looked briefly into the code and it looks like the data is ultimately owned by a
DataWrapper
instance, so any distortion of the underlying values might occur there.Edits
The text was updated successfully, but these errors were encountered: