Cameron F.
Cameron F.

Reputation: 213

imread_collection() Load Patterns (scikit-images Python)

I am having an issue (likely my own mistake) using imread_collection() to load a set of 480 .tif images from a folder.

I have an external drive with 480 images in it such that the path name for each image is:

'D:\img_channel000_position000_time000000000_z000.tif', 
'D:\img_channel000_position000_time000000001_z000.tif', 
'D:\img_channel000_position000_time000000002_z000.tif'

and so on. The 480 images are the only objects on the external drive. I know this is the path name as I have successfully used

import skimage
from skimage import io

image = skimage.io.imread('D:\img_channel000_position000_time000000000_z000.tif')

to import an image and perform a first-pass at the analysis I was looking to accomplish. I, perhaps naively, then attempted to use the following code to import the entirety of the collection

import skimage
from skimage import io

ic = skimage.io.imread_collection('D:\*.tif')

However, the variable ic is never even created. The code runs successfully without error, but nothing occurs. Is this a problem with how I have implemented the load pattern? I have also tried the more complete D:\img_channel000_position000_*_z000.tif, but nothing occurred. Any advice would be greatly appreciated!

Upvotes: 1

Views: 4142

Answers (1)

Tonechas
Tonechas

Reputation: 13743

The issue might be, as @Juan pointed out in the comments, that Linux and Windows use different directory separators. One possible way to make your code platform-independent would be using os.path.join like this:

In [18]: import os

In [19]: from skimage import io

In [20]: external_drive = 'D:'

In [21]: file_spec = '*.tif'

In [22]: load_pattern = os.path.join(external_drive, file_spec)

In [23]: ic = io.imread_collection(load_pattern)

In [24]: ic
Out[24]: <skimage.io.collection.ImageCollection at 0x1f94f27f080>

In [25]: ic.files
Out[25]: ['D:\\img_001.tif', 'D:\\img_002.tif', 'D:\\img_003.tif']

Test performed on a machine with Windows 10 and Python 3.6.3 (Anaconda).

Upvotes: 1

Related Questions