-
Notifications
You must be signed in to change notification settings - Fork 0
/
binarization.py
25 lines (24 loc) · 993 Bytes
/
binarization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cv2
import numpy as np
from importlib.resources import contents, path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .. import Testbench
def test_binarization(bench: 'Testbench'):
if bench.function is None:
return
base_data_pkg: str = 'testbench.tests.datasets.binarization'
input_data_pkg: str = f'{base_data_pkg}.input'
output_data_pkg: str = f'{base_data_pkg}.output'
for resource in contents(input_data_pkg):
if not resource.endswith('.png'):
continue
image_in = None
image_out = None
with path(input_data_pkg, resource) as data_path:
image_in = cv2.imread(str(data_path))
with path(output_data_pkg, resource) as data_path:
image_out = cv2.imread(str(data_path))
image_out = cv2.cvtColor(image_out, cv2.COLOR_RGB2GRAY)
image_test: np.ndarray = bench.function(np.array(image_in))
bench.assert_expr(np.array_equal(image_out, image_test))