def test_auto_clean_invalid_higher(self): image = self.image test_image = cv2.imread(fixtures_path('clean100.png')) reduce_image = histonets.auto_clean(image, background_value=110, background_saturation=110, colors=150, sample_fraction=110) assert (len(utils.get_color_histogram(test_image)) == len( utils.get_color_histogram(reduce_image)))
def test_auto_clean_with_palette(self): image = cv2.imread(fixtures_path('map.png')) palette = utils.get_palette(image[:, :, ::-1], n_colors=8) distances = [] for _ in range(10): clean1 = histonets.auto_clean(image, colors=8, sample_fraction=100, palette=palette) clean2 = histonets.auto_clean(image, colors=8, sample_fraction=100) hist1 = utils.get_color_histogram(clean1) hist1_colors = np.asarray(sorted(hist1.keys())) hist2 = utils.get_color_histogram(clean2) hist2_colors = np.asarray(sorted(hist2.keys())) distances.append(int(np.linalg.norm(hist1_colors - hist2_colors))) distance = np.array(distances).mean() # threshold value is experimentally set as the highest distance # after running the comparison 10k times threshold = 298 # 976 in L*a*b colorspace assert distance <= threshold
def test_auto_clean_non_default(self): image = self.image test_image = cv2.imread(fixtures_path('clean.png')) reduce_image = histonets.auto_clean(image, background_value=30, background_saturation=25, colors=12, sample_fraction=7, white_background=True, saturate=False) assert (len(utils.get_color_histogram(test_image)) != len( utils.get_color_histogram(reduce_image)))
def test_auto_clean_section_with_palette(self): image = cv2.imread(fixtures_path('icon.png')) palette = utils.get_palette(image[:, :, ::-1], n_colors=2) clean_image = histonets.auto_clean(image, colors=2, sample_fraction=100, palette=palette) section = cv2.imread(fixtures_path('icon_section.png')) clean_section = histonets.auto_clean(section, colors=2, sample_fraction=100, palette=palette) clean_image_colors = sorted( utils.get_color_histogram(clean_image[:, :, ::-1]).keys()) section_colors = sorted( utils.get_color_histogram(section[:, :, ::-1]).keys()) clean_section_colors = sorted( utils.get_color_histogram(clean_section[:, :, ::-1]).keys()) assert section_colors != clean_section_colors assert clean_section_colors == clean_image_colors
def test_auto_clean_channels_order(self): reduce_image = histonets.auto_clean(self.image) b_channel_sum = reduce_image[:, :, 0].sum() g_channel_sum = reduce_image[:, :, 1].sum() r_channel_sum = reduce_image[:, :, 2].sum() assert r_channel_sum > g_channel_sum > b_channel_sum
def test_auto_clean(self): image = self.image test_image = cv2.imread(fixtures_path('clean.png')) reduce_image = histonets.auto_clean(image) assert (len(utils.get_color_histogram(test_image)) >= len( utils.get_color_histogram(reduce_image)))