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

For LIFs, img.physical_pixel_sizes.X returns px/micon and not micron/px #287

Closed
psobolewskiPhD opened this issue Jul 15, 2021 · 1 comment · Fixed by #288
Closed

For LIFs, img.physical_pixel_sizes.X returns px/micon and not micron/px #287

psobolewskiPhD opened this issue Jul 15, 2021 · 1 comment · Fixed by #288
Assignees
Labels
bug Something isn't working

Comments

@psobolewskiPhD
Copy link
Contributor

System and Software

  • aicsimageio Version: 4.0.4
  • Python Version: 3.9.6
  • Operating System: MacOS BigSur 11.4 (Apple Silicon M1) (everything native arm64)

Description

Followup from:
https://forum.image.sc/t/setting-scale-bar-units-in-other-than-pixels-real-coordinates/49158/13?u=psobolewskiphd
When importing scenes from a LIF, img.physical_pixel_sizes.X which should return pixel size or a value of length (micron, nm) per pixel instead returns the reciprocal: px/length

You can access the LIF and the XML in the closed issue:
#277
Here's a relevant part of the XML:

DimID="1" NumberOfElements="1920" Origin="0.000000e+000" Length="1.244352e-003" Unit="m" BitInc="0" BytesInc="1" />
<DimensionDescription DimID="2" NumberOfElements="1440" Origin="0.000000e+000" Length="9.331016e-004" Unit="m" 

Based on this (and I've verified this with LAS X) the pixel size is:
(1.244e-3 m)/(1920 px) = 648 nm = 0.648 micron
Meanwhile:

>>> img.physical_pixel_sizes.X
1.542168132489842

which is 1/(pixel size)

Expected Behavior

That img.physical_pixel_sizes.X return the pixel size as advertised in the docs:

img.physical_pixel_sizes.X # returns the X dimension pixel size as found in the metadata

where 'size' means a value in the length dimension (micron, nm, m).

Reproduction

(You can access the LIF and the XML in the closed issue:
#277)
To set the scale in Napari, one needs to do 1/img.physical_pixel_sizes.X to get micron/pixel.

from aicsimageio import AICSImage
import napari
import dask.array as da
# if you want in-memory
import numpy as np
from vispy.color import Colormap

img = AICSImage("../Documents/Leica DMi8/20210428/20210428_24w_L929_Ho_B2C3.lif", reconstruct_mosaic=False)
scene_stack = []
for i, scene in enumerate(img.scenes):
        if i >46:
                img.set_scene(i)
                scene_stack.append(img.get_image_dask_data("YX"))
#                scene_stack.append(img.dask_data)

scene_stack = da.stack(scene_stack)
#scene_stack = np.stack(scene_stack)

#get pixel sizes (this is px/micron)
img.physical_pixel_sizes.X
microns_per_pixel = [1/img.physical_pixel_sizes.X, 1/img.physical_pixel_sizes.X]
        
I_Blueish = Colormap([[1, 1, 1], [0, .4, 1], [0, 0, 0]])
viewer = napari.view_image(scene_stack, colormap=('I Blueish', I_Blueish), scale=microns_per_pixel)
viewer.scale_bar.unit = "um"

Environment

My entire python environment is Apple Silicon M1 (arm64) native.

@toloudis toloudis added the bug Something isn't working label Jul 15, 2021
@toloudis
Copy link
Collaborator

Took a look at the documentation and code for readlif and it does indeed look like we have to use 1/scale instead of scale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants