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

Loading 16-bit tiff images #5005

Merged
merged 12 commits into from
Jan 11, 2023
Merged

Loading 16-bit tiff images #5005

merged 12 commits into from
Jan 11, 2023

Conversation

MyNameIsFu
Copy link
Contributor

@MyNameIsFu MyNameIsFu commented Sep 27, 2022

Pull Request regarding Issue #2987

PIL.Image conversion from I;16 to L or RGB are unsuccessful as for now.
See the corresponding Issue in the Pillow GitHub (Opened 2018, so no changes to be expected)
python-pillow/Pillow#3011

The proposed changes at least fix this issue for the mode 'I;16' and delivers a possible solution for other modes (eg. I;16B/L/N).

This results in a correct calculation of the preview thumbnail and the actual image, the annotation will be performed on.

We have used this solution on our own dataset and created annotations accordingly.

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@nmanovic
Copy link
Contributor

/check

@github-actions
Copy link
Contributor

github-actions bot commented Sep 27, 2022

❌ Some checks failed
📄 See logs here

@nmanovic
Copy link
Contributor

@MyNameIsFu , thanks for the contribution. Could you please add a line into CHANGELOG.md?

@MyNameIsFu
Copy link
Contributor Author

I added a comment. Is there anything I have to change regarding the failed pipeline?

@sizov-kirill
Copy link
Contributor

/check

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2022

🚫 Workflows has been canceled
📄 See logs here

@sizov-kirill
Copy link
Contributor

sizov-kirill commented Sep 29, 2022

Hi, @MyNameIsFu, I checked your PR and met with problem: I can't create an issue with an image. This error is also the cause of the failure of the entire our testing pipeline. We can't merge PR until the entire test pipeline goes green.

I attach the image to this comment, so you can reproduce this problem.
image.zip

@MyNameIsFu
Copy link
Contributor Author

@kirill-sizov The attached image seems to be cropped. Can you upload it again?

@sizov-kirill
Copy link
Contributor

sizov-kirill commented Sep 29, 2022

@MyNameIsFu, I've uploaded the right image, this is a cropped small image that I have a problem with.

@MyNameIsFu
Copy link
Contributor Author

Ah sorry, I'll debug it and push the changes 👍

@MyNameIsFu
Copy link
Contributor Author

MyNameIsFu commented Sep 29, 2022

@kirill-sizov
I created a new Project for the test image and 2 separate tasks (from .png and from .zip). Both are created successfully and i can annotate and save correctly. The image you provided is in png format and open in from PIL.Image as mode 'rgba'. My code changes explicitly take effect on mode == 'I;16' only. Are you sure this is the correct image that throws the errors?
Screenshot from 2022-09-29 15-11-20

@sizov-kirill
Copy link
Contributor

@MyNameIsFu, I got the following error:
Screenshot from 2022-09-29 19-07-15

And here is logs from cvat_worker_default container log.zip

@MyNameIsFu
Copy link
Contributor Author

Okay I looked into the Error, the CI Pipeline and the Tests and None of my changes should have any effect on the above error. I'm not even able to reproduce the Issue with CVAT. Nevertheless I tried to reproduce the Error without CVAT and instead with pure PIL and it appears to be a problem with implicit image conversion from RGBA to RGB (PNG to JPEG format).
Just as a reminder, I only touched the code regarding single-channel Images and can't think of a reason why it should have an impact on the 3 and 4 Channel images.

I'll take another look at the error and why it might differently behave on the Pipeline and my System. I also pushed Pillow version 9.2.0, just out of curiousity.

@sizov-kirill
Copy link
Contributor

/check

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2022

❌ Some checks failed
📄 See logs here

@nmanovic
Copy link
Contributor

@MyNameIsFu , thanks for the contribution once again. If tests are OK, I will merge the PR. In general I hope to reimplement the solution in the future. Actually we need to have 16-bit image in UI to change contract and brightness dynamically. Even it sounds simple, the actual implementation is going to be non-trivial.

@nmanovic nmanovic changed the title Issue 2987 Loading 16-bit tiff images Dec 10, 2022
# Issue was opened 2018, so don't expect any changes soon and work with manual conversions.
mode: str = preview.mode
if mode == "I;16":
preview = np.array(preview, dtype=np.uint16) # 'I;16' := Unsigned Integer 16, Grayscale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have a function to avoid code duplication.

@nmanovic nmanovic merged commit 881c1aa into cvat-ai:develop Jan 11, 2023
mikhail-treskin pushed a commit to retailnext/cvat that referenced this pull request Jul 1, 2023
Pull Request regarding Issue cvat-ai#2987 

PIL.Image conversion from I;16 to L or RGB are unsuccessful as for now.
See the corresponding Issue in the Pillow GitHub (Opened 2018, so no
changes to be expected)
python-pillow/Pillow#3011

The proposed changes at least fix this issue for the mode 'I;16' and
delivers a possible solution for other modes (eg. I;16B/L/N).

This results in a correct calculation of the preview thumbnail and the
actual image, the annotation will be performed on.

We have used this solution on our own dataset and created annotations
accordingly.
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

Successfully merging this pull request may close these issues.

None yet

4 participants