示例#1
0
 def test_command_clean_section_with_palette(self):
     image_path = fixtures_path('icon.png')
     image = cv2.imread(image_path)
     palette = utils.get_palette(image[:, :, ::-1], n_colors=2)
     clean_image_b64 = self.runner.invoke(
         cli.clean,
         [image_path, '-c', 2, '-f', 100, '-p',
          json.dumps(palette.tolist())]
     ).output.strip()
     clean_image = decode_base64(clean_image_b64)
     section_path = fixtures_path('icon_section.png')
     section = cv2.imread(section_path)
     clean_section_b64 = self.runner.invoke(
         cli.clean,
         [section_path, '-c', 2, '-f', 100, '-p',
          json.dumps(palette.tolist())]
     ).output.strip()
     clean_section = decode_base64(clean_image_b64)
     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 'Error' not in clean_image_b64
     assert 'Error' not in clean_section_b64
     assert section_colors != clean_section_colors
     assert clean_section_colors == clean_image_colors
示例#2
0
 def test_command_enhance_with_palette(self):
     image_path = fixtures_path('icon.png')
     image = cv2.imread(image_path)
     palette = utils.get_palette(image[:, :, ::-1], n_colors=8)
     result = self.runner.invoke(
         cli.enhance,
         [image_path, '-p', json.dumps(palette.tolist())]
     ).output.strip()
     assert 'Error' not in result
     assert len(result) > 0
示例#3
0
 def test_posterization_linear_4_colors_with_palette(self):
     image = self.image
     test_image = cv2.imread(fixtures_path('poster_linear4.png'))
     palette = utils.get_palette(image.reshape((-1, 3)), 4, method='linear')
     # palette is given as RGB and get_color_histogram returns colors
     # in the color scheme of image, which by default is BGR
     reduce_image = histonets.color_reduction(image,
                                              4,
                                              'linear',
                                              palette=palette)
     assert (len(utils.get_color_histogram(test_image)) == len(
         utils.get_color_histogram(reduce_image)))
示例#4
0
 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
示例#5
0
    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