MCPcopy Create free account
hub / github.com/dask/dask / imread

Function imread

dask/array/image.py:19–71  ·  view source on GitHub ↗

Read a stack of images into a dask array Parameters ---------- filename: string A globstring like 'myfile.*.png' imread: function (optional) Optionally provide custom imread function. Function should expect a filename and produce a numpy array. Defau

(filename, imread=None, preprocess=None)

Source from the content-addressed store, hash-verified

17
18
19def imread(filename, imread=None, preprocess=None):
20 """Read a stack of images into a dask array
21
22 Parameters
23 ----------
24
25 filename: string
26 A globstring like 'myfile.*.png'
27 imread: function (optional)
28 Optionally provide custom imread function.
29 Function should expect a filename and produce a numpy array.
30 Defaults to ``skimage.io.imread``.
31 preprocess: function (optional)
32 Optionally provide custom function to preprocess the image.
33 Function should expect a numpy array for a single image.
34
35 Examples
36 --------
37
38 >>> from dask.array.image import imread
39 >>> im = imread('2015-*-*.png') # doctest: +SKIP
40 >>> im.shape # doctest: +SKIP
41 (365, 1000, 1000, 3)
42
43 Returns
44 -------
45
46 Dask array of all images stacked along the first dimension.
47 Each separate image file will be treated as an individual chunk.
48 """
49 imread = imread or sk_imread
50 filenames = sorted(glob(filename))
51 if not filenames:
52 raise ValueError(f"No files found under name {filename}")
53
54 name = f"imread-{tokenize(filenames, map(os.path.getmtime, filenames))}"
55
56 sample = imread(filenames[0])
57 if preprocess:
58 sample = preprocess(sample)
59
60 keys = [(name, i) + (0,) * len(sample.shape) for i in range(len(filenames))]
61 if preprocess:
62 values = [
63 (add_leading_dimension, (preprocess, (imread, fn))) for fn in filenames
64 ]
65 else:
66 values = [(add_leading_dimension, (imread, fn)) for fn in filenames]
67 dsk = dict(zip(keys, values))
68
69 chunks = ((1,) * len(filenames),) + tuple((d,) for d in sample.shape)
70
71 return Array(dsk, name, chunks, sample.dtype)

Callers

nothing calls this directly

Calls 3

ArrayClass · 0.90
preprocessFunction · 0.85
tokenizeFunction · 0.50

Tested by

no test coverage detected