Reading directory of files into volume

57 views
Skip to first unread message

David Haberthür

unread,
Jul 23, 2018, 11:58:57 AM7/23/18
to imageio
Dear all.
I have a directory of (PNG) files which come from tomography.
These files are slices of a stack which I would like to read into a volume with `imageio`.
I've had no luck with using `mimread` as specified here: http://imageio.readthedocs.io/en/stable/examples.html#read-medical-data-dicom

Could someone give me a pointer on how to read the stack of images as volume?
Currently I'm doing it like so


````python
import glob
import matplotlib.pyplot as plt

# Get a list of all the relevant files
recfolder = '/data/sample/reconstructions'
reconstructions = glob.glob(os.path.join(recfolder, '*rec*.png'))

# This shows me one image, as expected
rec=imageio.imread(reconstructions[123])
plt.imshow(rec)
````

This is all fine and well, but now I'd like to read more images into a volume (for further processing)
It does work with a crude loop as below, but then I have a list of images, which is not what I would like.

````python
# This loads some images into a list, but not a volume
iteration = 100
vol = [None] * len(reconstructions[::iteration])
for c, rec in enumerate(reconstructions[::iteration]):
    vol[c] = imageio.imread(rec)
````

I would expect this to read a subset of the images as volume, but get an error that imageion "could not find a format to read the specified file in mode 'v'"
````python
vol = imageio.volread(recfolder)
````

Also I would have expected that I can just put multiple filenames into `mimread` like below, but then I get an error about a non-understandable URI...
````python
vol = imageio.mimread(reconstructions[100:111])
````

I would greatly appreciate any pointers on how to read a bunch of images into a volume.

David Haberthür



Almar Klein

unread,
Jul 31, 2018, 5:12:51 AM7/31/18
to ima...@googlegroups.com, David Haberthür
Hi David,

First some explanations as to where some of the things that you tried do not work:

> I would expect this to read a subset of the images as volume [...]  imageio.volread(recfolder)

This does actually work with the DICOM plugin, but most other plugins require a file, not a folder.

> Also I would have expected that I can just put multiple filenames into `mimread` [...]  imageio.mimread(reconstructions[100:111])

That's not how imageio works; it would not be very "Pythonic".

You were almost there when you had the list of images. One final step: np.stack(vol, 0)

You can write that bit more compactly using a list comprehension: np.stack([imageio.imread(rec) for rec in reconstructions[::iteration]], 0)

Regards,
  Almar
--
You received this message because you are subscribed to the Google Groups "imageio" group.
To unsubscribe from this group and stop receiving emails from it, send an email to imageio+u...@googlegroups.com.
To post to this group, send email to ima...@googlegroups.com.
Visit this group at https://groups.google.com/group/imageio.
For more options, visit https://groups.google.com/d/optout.

David Haberthür

unread,
Aug 3, 2018, 11:23:05 AM8/3/18
to imageio
On Tuesday, July 31, 2018 at 11:12:51 AM UTC+2, Almar Klein wrote:
You were almost there when you had the list of images. One final step: np.stack(vol, 0)

You can write that bit more compactly using a list comprehension: np.stack([imageio.imread(rec) for rec in reconstructions[::iteration]], 0)

Thanks a lot for the help!
Reply all
Reply to author
Forward
0 new messages