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>
28 lines
742 B
Python
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
|