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

BMP files with alpha channel are read with incorrect channel order #2596

Closed
lassoan opened this issue Jun 15, 2021 · 1 comment · Fixed by #2685
Closed

BMP files with alpha channel are read with incorrect channel order #2596

lassoan opened this issue Jun 15, 2021 · 1 comment · Fixed by #2685
Assignees
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@lassoan
Copy link
Contributor

lassoan commented Jun 15, 2021

When a 32-bit ARGB BMP file is loaded using ITK, the colors are all mixed up.

Description

BMP files with transparency are stored with ARGB channel order. It seems that ITK assumes RGBA order.

Steps to Reproduce

Load this image using ITK: https://1drv.ms/u/s!Arm_AFxB9yqHxcpbEw34sbS-h1pjkA?e=cf39o8

img = sitk.ReadImage('15-14-49.bmp')
myshow(img)  # incorrect
nda = sitk.GetArrayFromImage(img)
img2=sitk.GetImageFromArray(nda[:,:,[1,2,3,0]])
myshow(img2)  # correct

image

Expected behavior

Colors should appear correctly in an application, regardless of what file format is loaded from (png, jpg, bmp, ...)

Actual behavior

Colors are not correct if BMP format is used (if transparency is stored with the image).

Reproducibility

100%

Versions

v5.2.0

Environment

all (Windows and Linux tested)

Additional Information

See original user report at https://discourse.slicer.org/t/grey-level-image-looking-blue-or-other-color/18095/3

@lassoan lassoan added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Jun 15, 2021
@dzenanz dzenanz self-assigned this Aug 11, 2021
@dzenanz
Copy link
Member

dzenanz commented Aug 11, 2021

It turns out BMP files use BGR and BGRA order. ITK assumed ABGR instead. #2596 fixes that.

@leodemachado can you confirm? I guess this will need to be integrated into Slicer first 😄

dzenanz added a commit to dzenanz/ITK that referenced this issue Aug 12, 2021
dzenanz added a commit to dzenanz/ITK that referenced this issue Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants