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

Enhance Documentation of LoadImage to Clarify Image Transposition #4862

Closed
ericspod opened this issue Aug 8, 2022 · 4 comments · Fixed by #4892
Closed

Enhance Documentation of LoadImage to Clarify Image Transposition #4862

ericspod opened this issue Aug 8, 2022 · 4 comments · Fixed by #4892
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@ericspod
Copy link
Member

ericspod commented Aug 8, 2022

Is your feature request related to a problem? Please describe.
Image data loaded from non-medical 2D formats like jpeg are transposed by the ImageReader class loading them, this is because these images are WH order and typical Pytorch ordering is HW. It's not clear to users that this is happening and can be really confused when using the loaders with natural images or photographs, or even MedNIST data as compared to loading with PIL directly.

Describe the solution you'd like
Documentation for LoadImage should be updated to state that this occurs for a number of non-medical specific file formats.

Describe alternatives you've considered
Tilting my head to the side any time I visualise an image.

Additional context
I had forgotten this was intended behaviour and wasn't helped by documentation.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Aug 9, 2022

Thanks for raising this topic, OK, let me try to enhance the doc.

@Nic-Ma Nic-Ma self-assigned this Aug 9, 2022
@Nic-Ma Nic-Ma added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 9, 2022
@wyli
Copy link
Contributor

wyli commented Aug 11, 2022

I just wanted to show an example of the indexing convention difference (swapped), for your reference:

from PIL import Image
import itk

import monai

monai.apps.utils.download_url("https://monai.io/assets/img/MONAI-logo_color.png")
filename = "MONAI-logo_color.png"
im_pil = Image.open(filename).load()
im_itk = itk.imread(filename)

# check the indexing
for x in range(100):
    for y in range(31):
        assert tuple(im_itk[y, x]) == tuple(im_pil[x, y])

print(Image.__version__)  # 9.2.0
print(itk.__version__)  # 5.2.1

from monai's perspective, the design choice is to be consistent when using loadimage with different backend libraries.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Aug 11, 2022

Yes, and the "different backend libraries" represent the "medical specific" as @ericspod described.

Thanks.

@wyli
Copy link
Contributor

wyli commented Aug 11, 2022

not sure if it's medical specific, it's just the choice of row-major or column-major convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants