mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Co-authored-by: Kwabena W Agyeman <kwagyeman@users.noreply.github.com> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
36 lines
846 B
Python
36 lines
846 B
Python
def unittest(data_path, temp_path):
|
|
import image
|
|
|
|
# Test grayscale invert
|
|
img = image.Image(50, 50, image.GRAYSCALE)
|
|
|
|
# Fill with known values
|
|
for y in range(50):
|
|
for x in range(50):
|
|
img.set_pixel(x, y, 100)
|
|
|
|
# Invert the image
|
|
img.invert()
|
|
|
|
# Verify all pixels are inverted (255 - 100 = 155)
|
|
for y in range(50):
|
|
for x in range(50):
|
|
pixel = img.get_pixel(x, y)
|
|
if pixel != 155:
|
|
return False
|
|
|
|
# Test with another value
|
|
img2 = image.Image(50, 50, image.GRAYSCALE)
|
|
for y in range(50):
|
|
for x in range(50):
|
|
img2.set_pixel(x, y, 200)
|
|
|
|
img2.invert()
|
|
|
|
stats = img2.get_statistics()
|
|
# 255 - 200 = 55
|
|
if stats.mean() != 55 or stats.min() != 55 or stats.max() != 55:
|
|
return False
|
|
|
|
return True
|