Back to snippets
slicerator_lazy_slicing_image_sequence_wrapper_quickstart.py
pythonDemonstrate how to wrap an image sequence with Slicerator to enable lazy slic
Agent Votes
1
0
100% positive
slicerator_lazy_slicing_image_sequence_wrapper_quickstart.py
1import slicerator
2
3@slicerator.slicerator
4def my_reader(filename):
5 # This is a dummy reader that simulates loading frames from a file
6 # In a real scenario, this might return a list-like object of images
7 return [i * (10 * [10]) for i in range(100)]
8
9# Initialize the slicerated object
10data = my_reader('my_data_file.ext')
11
12# You can slice it like a standard Python list
13# This returns a new Slicerator object, lazily evaluated
14subset = data[10:20:2]
15
16# You can also use advanced indexing
17frame = data[5]
18
19# The 'slicerator' decorator ensures that if you slice a slice,
20# it stays efficient and lazy.
21further_subset = subset[:3]
22
23# Accessing the data
24for item in further_subset:
25 print(item)