Skip to content

Commit 692a7ff

Browse files
committed
Seperated mapping colors to its own function, so it can be used without the video-effect
1 parent 69ca12c commit 692a7ff

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

svidreader/filter/color_mapper.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
class ColorMapper(VideoSupplier):
66
def __init__(self, reader, source_colors, destination_colors):
77
super().__init__(n_frames=reader.n_frames, inputs=(reader,))
8-
self.cache = (None,None)
9-
# Ensure inputs are numpy arrays
10-
source_colors = np.array(source_colors)
11-
destination_colors = np.array(destination_colors)
8+
self.map_colors = self.get_color_mapper(source_colors, destination_colors)
129

10+
@staticmethod
11+
def get_color_mapper(source_colors:np.ndarray, destination_colors:np.ndarray):
1312
# Create a Delaunay triangulation for the source colors
14-
delaunay = Delaunay(source_colors)
1513

14+
source_colors = np.array(source_colors)
15+
destination_colors = np.array(destination_colors)
16+
delaunay = Delaunay(source_colors)
1617
def map_colors(query_colors):
1718
query_colors = np.atleast_2d(query_colors) # Ensure input is 2D
1819

19-
mapped_colors = np.empty((query_colors.shape[0], destination_colors.shape[1]))
20+
mapped_colors = np.empty((*query_colors.shape[:-1], destination_colors.shape[1]))
2021
# Find simplices (triangles) for each query color
2122
simplices = delaunay.find_simplex(query_colors)
2223

@@ -75,8 +76,7 @@ def map_colors(query_colors):
7576
mapped_colors[inside_mask] = inside_colors
7677

7778
return mapped_colors
78-
self.map_colors = map_colors
79-
79+
return map_colors
8080

8181
def read(self, index, force_type=np):
8282
current = self.inputs[0].read(index=index, force_type=np)

0 commit comments

Comments
 (0)