openmv/scripts/unittest/tests/mask_operations.py
iabdalkader 4b1837f72e scripts: Update unit tests.
Co-authored-by: Kwabena W Agyeman <kwagyeman@users.noreply.github.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-10-18 17:14:36 +02:00

31 lines
869 B
Python

def unittest(data_path, temp_path):
import image
# Create main image
img = image.Image(50, 50, image.GRAYSCALE)
for y in range(50):
for x in range(50):
img.set_pixel(x, y, 150)
# Create mask (binary image)
mask = image.Image(50, 50, image.BINARY)
for y in range(50):
for x in range(50):
if 10 <= x <= 40 and 10 <= y <= 40:
mask.set_pixel(x, y, 1)
else:
mask.set_pixel(x, y, 0)
# Apply operation with mask (e.g., set masked region to 0)
img.binary([(0, 255)], invert=False, zero=True, mask=mask)
# Verify masked region was affected
center_pixel = img.get_pixel(25, 25)
corner_pixel = img.get_pixel(5, 5)
# Center should be modified, corner should remain
if center_pixel == corner_pixel:
return False
return True