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

30 lines
760 B
Python

def unittest(data_path, temp_path):
import image
# Create test image with bimodal distribution
img = image.Image(100, 100, image.GRAYSCALE)
# Create two distinct regions (bimodal)
for y in range(100):
for x in range(100):
if x < 50:
img.set_pixel(x, y, 50)
else:
img.set_pixel(x, y, 200)
# Get histogram
hist = img.get_histogram()
# Get automatic threshold (Otsu's method)
threshold = hist.get_threshold()
# Verify threshold object
if not hasattr(threshold, 'value'):
return False
# Threshold should be between the two peaks (50 and 200)
if threshold.value() < 50 or threshold.value() > 200:
return False
return True