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>
30 lines
760 B
Python
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
|