Skip to content

Use ChannelFiller so that indexed data is read as RGB#57

Merged
tlambert03 merged 7 commits intoimaging-formats:mainfrom
psobolewskiPhD:gif_as_rgb
Feb 23, 2026
Merged

Use ChannelFiller so that indexed data is read as RGB#57
tlambert03 merged 7 commits intoimaging-formats:mainfrom
psobolewskiPhD:gif_as_rgb

Conversation

@psobolewskiPhD
Copy link
Contributor

@psobolewskiPhD psobolewskiPhD commented Feb 22, 2026

Closes:
#41

Copilot (GPT-5.3-Codex) originally identified the source of the issue with GIF handling. It suggested a pretty complex refactor to mimic Fiji behavior, by checking the file name or metadata and then using the ChannelFiller plus ChannelSeparator. This yielded C=3, rgb False, but I dont think it's actually the correct behavior. As the palette consists of RGB values, the returned image should be RGB not multichannel. If we skip the ChannelSeparator requirement, it makes it much simpler to implement, because ChannelFiller should be safe to use on non-indexed data:
https://downloads.openmicroscopy.org/bio-formats/8.4.0/api/loci/formats/ChannelFiller.html

For indexed color data representing true color, factors out the indices, replacing them with the color table values directly.
For all other data (either non-indexed, or indexed with "false color" tables), does nothing.

I added some tests and did some testing of my own with napari and everything seems good.
Some np.asarray(data) timing tests, e.g. with CMU-1 do show a 30-200 ms hit, but my LIF don't show any 🤷

Alternatives would be to just use extension to check for gif? i think png can also be indexed? not sure what else honestly. Checking using the reader and core_metadata can work but that's essentially what ChannelFiller checks:
https://github.com/ome/bioformats/blob/eddfa670652145530db288bc8d4aa2f3b245c75a/components/formats-bsd/src/loci/formats/ChannelFiller.java#L49

Edit: Also fixes an issue caught by copilot that rgb_count was not set properly in core_metadata.

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tlambert03
Copy link
Member

thanks! I've done my homework now and I agree it's the right fix. just to leave an escape hatch though, I added a channel_filler kwarg to the BioFile constructor, where True/False mean use/don't-use .... and None (default) means "use whatever internal heuristics you want to autoapply"... and then I did add some logic that might just shave off some 10s-100 ms in cases where it wasn't necessary

@tlambert03 tlambert03 enabled auto-merge (squash) February 23, 2026 23:10
@tlambert03 tlambert03 merged commit 25e3cd7 into imaging-formats:main Feb 23, 2026
26 checks passed
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.

2 participants