`dask_image.imread.imread(*.png)` as 8bit, not RGB

I’m loading a big bunch of tomographic reconstructions (8bit grayvalue PNGs) for ‘treatment’ with something along the lines of Reconstructions = dask_image.imread.imread('*rec*.png').

This works fine, but dask unnecessarily creates arrays with three dimensions, e.g. Reconstructions=[1234].shape is “(3072, 3072, 3)”, it seems to load the files as RBG.
identify Sample_rec1234.png via ImageMagick tells me that the file is a “PNG 3072x3072 3072x3072+0+0 8-bit sRGB 256c 1.66705MiB 0.000u 0:00.000” and ImageJ also loads it at 8bit image.

I can do all the computation and treatment on the “RGB” data, but ultimately this creates unnecessary headache in the end, when I want to save out some results again.

Is there a way I can force dask_image.imread.imread to read such 8bit PNGs as 8bit gray value data?

dask.__version__ = '2023.11.0'
dask_image.__version__ = '2023.08.1'

Hi @habi, welcome to Dask discourse!

Looking at the source code, I don’t think there is a way to force Dask image to do otherwise.

See dask_image.imread — dask-image 2023.08.1+4.g20e1b30.dirty documentation.

In particular, dask-image relies on pims library to infer the image shape:

with pims.open(sfname) as imgs:
        shape = (len(imgs),) + imgs.frame_shape
        dtype = np.dtype(imgs.pixel_type)

Only solutions I can think of is code your own imgread function, or try droping dimensions just after reading the images as a Dask Array.

I can drop a dimension, but I also know that dask_image.imread didn’t use to load my PNG files like this.
Unfortunately I don’t have time to further debug this at the moment…

Maybe it comes from a change in pims library?

That might well be.
Since I’m running all my different projects in different conda environments I might even be able to figure out what’s the difference between them.
But first I need to finish this current project :slight_smile: