Exemplo n.º 1
0
    def test_chessboard(self):
        """
        Test compute method on the chessboard matrix.
        Test the final result is still a chessboard matrix with tiles of the
        same size as the ones in the input.
        """
        q = Quilt(np.float64(self.chessboard),
                  output_size=[16, 16],
                  tilesize=4,
                  overlap=2,
                  error=0,
                  constraint_start=True)
        q.debug = False
        q.compute()
        result = q.get_result()[0]

        # check the dimension
        self.assertEqual((16, 16, 3), result.shape)
        assert_array_equal(result[:, :, 0], result[:, :, 1], result[:, :, 2])

        # check the values
        result = result[:, :, 0]
        expected = np.asarray([[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1],
                               [0, 0, 1, 1]])
        for i in xrange(0, result.shape[0] - 4, 4):
            for j in xrange(0, result.shape[1] - 4, 4):
                patch = result[i:i + 4, j:j + 4]
                assert_array_equal(expected, patch)
Exemplo n.º 2
0
def _launch_quilt(debug, final_path, src, **kwargs):
    """
    Launches quilt process with the parsed arguments.
    """

    multi_proc = kwargs.pop('multiprocess')

    # ------------- quilt --------------

    qs = time.time()
    log.info('Quilt started at {0}'.format(time.strftime("%H:%M:%S")))

    try:
        # compute quilting
        Quilt.debug = debug
        q = Quilt(src, **kwargs)
        if multi_proc:
            q.optimized_compute()
        else:
            q.compute()

        # get the result
        result = q.get_result()
        if debug:
            show(result)
        save(result, final_path)

    except ValueError as err:
        log.error(err.message)
        return

    t = (time.time() - qs) / 60
    log.debug('Quilt took {0:0.6f} minutes'.format(t))
    log.info('End {0}'.format(time.strftime("%H:%M:%S")))
Exemplo n.º 3
0
    def test_eye(self):
        """
        Test compute method on the known eye matrix. This method is more
        accurate but it is slower.
        Test the final result is a composition of eye matrices:
            for every pixel P, check its neighborhood as following:
                - if P = 1:  1 .5 .5      - if P = .5: .5  *  *
                            .5  P .5                    *  P  *
                            .5 .5  1                    *  * .5
        """
        q = Quilt(self.eye,
                  output_size=[10, 10],
                  tilesize=4,
                  overlap=2,
                  error=0,
                  constraint_start=True)
        q.debug = False
        q.compute()
        result = q.get_result()[0]

        # if there is a 1, its neighborhood must be:   1 .5 .5
        #                                             .5  1 .5
        #                                             .5 .5  1
        self.assertEqual((10, 10, 3), result.shape)
        assert_array_equal(result[:, :, 0], result[:, :, 1], result[:, :, 2])

        result = result[:, :, 0]
        expected = np.asarray([[1, 0.5, 0.5], [0.5, 1, 0.5], [0.5, 0.5, 1]])
        for i in range(1, result.shape[0] - 1):
            for j in range(1, result.shape[1] - 1):
                self.assertIn(result[i, j], [1, 0.5])
                if result[i, j] == 1:
                    np.testing.assert_array_equal(
                        expected, result[i - 1:i + 2, j - 1:j + 2])
                else:
                    try:
                        np.testing.assert_array_equal(0.5, result[i - 1,
                                                                  j - 1])
                        np.testing.assert_array_equal(0.5, result[i + 1,
                                                                  j + 1])
                    except AssertionError as err:
                        print err