Files
mmp_wise2526_franksim/mmp/a1/tensors.py

16 lines
413 B
Python
Raw Normal View History

2025-10-13 14:48:00 +02:00
import torch
2025-10-13 14:48:00 +02:00
def avg_color(img: torch.Tensor):
result = img.mean(dim=(1, 2)).tolist()
return tuple(result)
2025-10-13 14:48:00 +02:00
def mask(foreground: torch.Tensor, background: torch.Tensor, mask_tensor: torch.Tensor, threshold: float):
mask = mask_tensor > threshold
return torch.where(mask, foreground, background)
2025-10-13 14:48:00 +02:00
2025-10-13 14:48:00 +02:00
def add_matrix_vector(matrix: torch.Tensor, vector: torch.Tensor):
return matrix.add(vector)