openmv/scripts/unittest/tests/binary.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

28 lines
742 B
Python

def unittest(data_path, temp_path):
import image
# Test grayscale binary thresholding
img_gray = image.Image(100, 100, image.GRAYSCALE)
# Fill with gradient pattern
for y in range(100):
for x in range(100):
img_gray.set_pixel(x, y, x + y)
# Apply binary threshold at 128
img_gray.binary([(128, 255)])
# Verify all pixels are either 0 or 255
for y in range(100):
for x in range(100):
pixel = img_gray.get_pixel(x, y)
if pixel != 0 and pixel != 255:
return False
# Verify we have both black and white pixels
stats = img_gray.get_statistics()
if stats.min() != 0 or stats.max() != 255:
return False
return True