question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with aray shape when using `dask_image.imread` (and `dask.array.image.imread`) vs. `imageio.imread`

See original GitHub issue

I’m loading a big bunch of tomographic data in a preview/analysis notebook. As we keep scanning samples, the dataframe I put the preview images in gets larger and larger. I’ve been using imageio.imread to load the preview images (middle axial slices and MIPs) from disk. I’d like to switch to dask_image.imread for this, as I’m loading the full datasets with it and generate the preview files from the full stacks loaded like this.

I now saw that loading an image with imageio.imread returns an image with two coordinates (size of the image), while dask_image.imread (and dask.array.image.imread return an image with three coordinates, the first one being 1, the second and third being the size of the image. I’m very well aware that I can just .squeeze() the array before displaying with matplotlib, but expect that all the imread functions return the same kind of array.

Minimal Complete Verifiable Example:

I’ve made a gist which shows my issue fully self-contained, it can be found here and can be started in Binder: Binder

It boils down to

imgio = imageio.imread('random.png')
imgdask = dask.array.image.imread('random.png')
imgdaskimg = dask_image.imread.imread('random.png')

returning different shapes.

This is closely related to https://github.com/dask/dask-image/issues/229 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
GenevieveBuckleycommented, Jul 6, 2021

Thank you for the report (and binder example!) @habi

My best suggestion is to squeeze the array to remove the singleton dimension(s) if they’re causing you problems.

import numpy as np

squeezed_imgdask = np.squeeze(imgdask)
squeezed_imgdask.shape
# (100, 100)

Since this has no effect if no singleton dimensions are present, you would be able to add this generally to your code. Then you’ll get the same output, regardless of whether you happen to be using dask or not.

0reactions
habicommented, Mar 31, 2022

Thanks for the comment @jakirkham!

The underlying issue is more that I’m using

for c, sample in Data.iterrows()):
    Reconstructions[c] = dask_image.imread.imread(os.path.join(sample['Folder'], '*rec*.png'))

to lazily load +10000 of images from disk (several samples with each a folder of +1000 reconstructions).

From these I then generate files as necessary (axial views and MIPs), but do not view them directly. It seems to me that I have to switch everything to the ‘pure dask’ way mentioned in issue #181 above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dask.array.image.imread - Dask documentation
Function should expect a filename and produce a numpy array. ... from dask.array.image import imread >>> im = imread('2015-*-*.png') >>> im.shape (365, ...
Read more >
problem computing chunk size of dask array after dask_image ...
After scrolling through the dask-image issues on GitHub I found that this issue had been reported previously. Creating a new environment ...
Read more >
aicsimageio package - AICS Modeling
AICSImage takes microscopy image data types (files or arrays) of varying ... aicsimageio.aics_image.imread(image: Union[str, Path, ndarray, Array, ...
Read more >
dask-image - bytemeta
Issues with aray shape when using `dask_image.imread` (and `dask.array.image.imread`) vs. `imageio.imread` · Performance issue with `sum`.
Read more >
Dask Dask-Image Statistics & Issues - Codesti
Issues with aray shape when using `dask_image.imread` (and `dask.array.image.imread`) vs. `imageio.imread`, closed, 6, 2021-06-22, 2022-11-14, 2021-07-07.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found