|
1 | 1 | import os
|
2 | 2 |
|
3 | 3 | import numpy as np
|
| 4 | +import imageio |
4 | 5 | from skimage import data_dir
|
5 | 6 | from skimage.io.collection import ImageCollection, MultiImage, alphanumeric_key
|
6 | 7 | from skimage.io import reset_plugins
|
@@ -94,30 +95,19 @@ def set_files(f):
|
94 | 95 | with testing.raises(AttributeError):
|
95 | 96 | set_files('newfiles')
|
96 | 97 |
|
97 |
| - def test_custom_pattern(self): |
98 |
| - load_pattern = os.path.join(data_dir, 'b??ck.png') |
99 |
| - files = [os.path.join(data_dir, pic) |
100 |
| - for pic in ['block.png', 'brick.png']] |
| 98 | + def test_custom_load_func_w_kwarg(self): |
| 99 | + load_pattern = os.path.join(data_dir, 'no_time_for_that_tiny.gif') |
101 | 100 |
|
102 |
| - def load_fn(x): |
103 |
| - return x |
104 |
| - |
105 |
| - ic = ImageCollection(load_pattern, load_func=load_fn) |
106 |
| - assert_equal(ic[0], files[0]) |
107 |
| - assert_equal(ic[1], files[1]) |
108 |
| - |
109 |
| - def test_custom_pattern_not_pil(self): |
110 |
| - load_pattern = os.path.join(data_dir, 'chessboard_*_U8.npz') |
111 |
| - files = [os.path.join(data_dir, pic) |
112 |
| - for pic in ['chessboard_GRAY_U8.npz', |
113 |
| - 'chessboard_RGB_U8.npz']] |
114 |
| - |
115 |
| - def load_fn(x): |
116 |
| - return x |
| 101 | + def load_fn(f, step): |
| 102 | + vid = imageio.get_reader(f) |
| 103 | + seq = [v for v in vid.iter_data()] |
| 104 | + return seq[::step] |
117 | 105 |
|
118 |
| - ic = ImageCollection(load_pattern, load_func=load_fn) |
119 |
| - assert_equal(ic[0], files[0]) |
120 |
| - assert_equal(ic[1], files[1]) |
| 106 | + ic = ImageCollection(load_pattern, load_func=load_fn, step=3) |
| 107 | + # Each file should map to one image (array). |
| 108 | + assert len(ic) == 1 |
| 109 | + # GIF file has 24 frames, so 24 / 3 equals 8. |
| 110 | + assert len(ic[0]) == 8 |
121 | 111 |
|
122 | 112 | def test_custom_load_func(self):
|
123 | 113 |
|
|
0 commit comments