Skip to content

[io] Scale a 16-bit image to 8 bits in read_img_as_tensor and decode_img_as_tensor - #2217

Merged
felixdittrich92 merged 2 commits into
mindee:mainfrom
RavSinghChandan:read-16-bit-images
Nov 6, 2026
Merged

felixdittrich92 merged 2 commits into
mindee:mainfrom
RavSinghChandan:read-16-bit-images

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

A 16-bit grayscale PNG (Pillow mode I;16) was read as almost all white by read_img_as_tensor and decode_img_as_tensor: Pillow's convert("RGB") clips each value to 255 instead of scaling it, so every pixel above 255 out of 65535 became white. read_img_as_numpy (through cv2.imdecode) scales them to 8 bits instead, and the datasets load their images with read_img_as_tensor.

values  : 0  9362  18724 ... 65535
numpy   : 0    36     73 ...   255
tensor  : 0   255    255 ...   255   <- before

The 16-bit values are now shifted to 8 bits like cv2.imdecode does, and both readers give the same pixels. Test added (fails on main).

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.77%. Comparing base (a800f48) to head (926123f).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2217      +/-   ##
==========================================
- Coverage   97.79%   97.77%   -0.02%     
==========================================
  Files         170      170              
  Lines       10997    10999       +2     
==========================================
  Hits        10754    10754              
- Misses        243      245       +2     
Flag Coverage Δ
unittests 97.77% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 self-assigned this Nov 4, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Nov 6, 2026

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @RavSinghChandan 👍

@felixdittrich92 felixdittrich92 added type: enhancement Improvement module: io Related to doctr.io ext: tests Related to tests folder labels Nov 6, 2026
@felixdittrich92
felixdittrich92 merged commit 8d72e47 into mindee:main Nov 6, 2026
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: io Related to doctr.io type: enhancement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants