Example #1
0
    def test_cli(self):

        from color_matcher.bin.cli import main
        import sys

        sys.args = ''
        main()
Example #2
0
    def test_cli_help(self, kw):

        # print help message
        sys.argv.append(kw)
        try:
            ret = main()
        except SystemExit:
            ret = True

        self.assertEqual(True, ret)
Example #3
0
    def test_batch_process(self):

        # compose CLI arguments
        sys.argv.append('-s ' + self.dat_path)                                        # pass directory path
        sys.argv.append('-r ' + os.path.join(self.dat_path, 'scotland_plain.png'))    # pass file path
        sys.argv.append('method==' + METHODS[0])                                      # pass method

        # run CLI command
        ret = main()

        # assertion
        self.assertEqual(True, ret)
Example #4
0
    def test_cli_args(self, kw):

        # compose cli arguments
        sys.argv.append(kw[0] +
                        os.path.join(self.dat_path, 'scotland_house.png'))
        sys.argv.append(kw[1] +
                        os.path.join(self.dat_path, 'scotland_plain.png'))

        # run cli command
        ret = main()

        # assertion
        self.assertEqual(True, ret)
Example #5
0
    def test_kodak_images(self):

        # prepare data
        url = 'https://www.math.purdue.edu/~lucier/PHOTO_CD/BMP_IMAGES/'
        self.fnames = ['IMG' + str(i + 1).zfill(4) + '.bmp' for i in range(24)]
        loc_path = os.path.join(self.dat_path, 'kodak')

        try:
            os.makedirs(loc_path, 0o755)
            os.makedirs(os.path.join(loc_path, 'results'), 0o755)
        except:
            pass

        if not os.path.exists(loc_path):
            main(url, loc_path)

        for fn_img1 in self.fnames:
            for fn_img2 in self.fnames:

                # load images
                img1 = load_img_file(os.path.join(loc_path, fn_img1))
                img2 = load_img_file(os.path.join(loc_path, fn_img2))

                # create color match object
                res = ColorMatcher(img1, img2, method='hm-mkl-hm').main()

                # assess quality
                val = self.avg_hist_dist(res, img2)
                print('Avg. histogram distance %s' % val)

                # save result
                output_filename = os.path.join(
                    loc_path, 'results',
                    fn_img1.split('.')[0] + '_from_' + fn_img2)
                save_img_file(res, file_path=output_filename)

                # assertion
                self.assertEqual(True, val != 0)
Example #6
0
    def test_cli(self, kw):

        from color_matcher.bin.cli import main
        import sys

        # compose cli arguments
        sys.argv.append(kw[0]+os.path.join(self.dat_path, 'scotland_house.png'))
        sys.argv.append(kw[1]+os.path.join(self.dat_path, 'scotland_plain.png'))

        # run cli command
        ret = main()

        # assertion
        self.assertEqual(True, ret)
Example #7
0
    def test_cli_args(self, kw, exp_val):

        # compose CLI arguments
        sys.argv.append(kw[0] + os.path.join(self.dat_path, 'scotland_house.png'))
        sys.argv.append(kw[1] + os.path.join(self.dat_path, 'scotland_plain.png'))

        # run CLI command
        try:
            ret = main()
        except SystemExit:
            ret = False

        # clear sys.argv
        sys.argv = [sys.argv[0]]

        # assertion
        self.assertEqual(exp_val, ret)