8000 Remove flattening of multi-frame files · scikit-image/scikit-image@eeffe8a · GitHub
[go: up one dir, main page]

Skip to content

Commit eeffe8a

Browse files
committed
Remove flattening of multi-frame files
1 parent e5df785 commit eeffe8a

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

skimage/io/collection.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,24 @@ class ImageCollection(object):
138138
ImageCollection can be modified to load images from an arbitrary
139139
source by specifying a combination of `load_pattern` and
140140
`load_func`. For an ImageCollection ``ic``, ``ic[5]`` uses
141-
``load_func(file_pattern[5])`` to load the image.
141+
``load_func(load_pattern[5])`` to load the image.
142142
143-
Imagine, for example, an ImageCollection that loads every tenth
143+
Imagine, for example, an ImageCollection that loads every third
144144
frame from a video file::
145145
146-
class AVILoader:
147-
video_file = 'myvideo.avi'
146+
video_file = 'no_time_for_that_tiny.gif'
148147
149-
def __call__(self, frame):
150-
return video_read(self.video_file, frame)
148+
def vidread_step(f, step):
149+
vid = imageio.get_reader(f)
150+
seq = [v for v in vid.iter_data()]
151+
return seq[::step]
151152
152-
avi_load = AVILoader()
153+
ic = ImageCollection(video_file, load_func=vidread_step, step=3)
153154
154-
frames = range(0, 1000, 10) # 0, 10, 20, ...
155-
ic = ImageCollection(frames, load_func=avi_load)
155+
ic # is an ImageCollection object of length 1 because there is 1 file
156156
157-
x = ic[5] # calls avi_load(frames[5]) or equivalently avi_load(50)
157+
x = ic[0] # calls vidread_step(video_file, step=3)
158+
x[5] # is the sixth element of a list of length 8 (24 / 3)
158159
159160
Another use of ``load_func`` would be to convert all images to ``uint8``::
160161
@@ -191,7 +192,15 @@ def __init__(self, load_pattern, conserve_memory=True, load_func=None,
191192
raise TypeError('Invalid pattern as input.')
192193

193194
self._files = sorted(self._files, key=alphanumeric_key)
194-
self._numframes = self._find_images()
195+
196+
if load_func is None:
197+
from ._io import imread
198+
self.load_func = imread
199+
self._numframes = self._find_images()
200+
else:
201+
self.load_func = load_func
202+
self._numframes = len(self._files)
203+
self._frame_index = None
195204

196205
if conserve_memory:
197206
memory_slots = 1
@@ -201,12 +210,6 @@ def __init__(self, load_pattern, conserve_memory=True, load_func=None,
201210
self._conserve_memory = conserve_memory
202211
self._cached = None
203212

204-
if load_func is None:
205-
from ._io import imread
206-
self.load_func = imread
207-
else:
208-
self.load_func = load_func
209-
210213
self.load_func_kwargs = load_func_kwargs
211214
self.data = np.empty(memory_slots, dtype=object)
212215

0 commit comments

Comments
 (0)
0