Example #1
0
                    target_cell_extend = self.dst_grid[i, j] - target_cell_origin

                    return target_cell_origin + rel * target_cell_extend

        return p

    def transform_points(self, ps):
        return np.array([self.transform_point(p) for p in ps])


if __name__ == '__main__':
    from database import DatabaseBook
    from database.file_formats.pcgts import PageScaleReference
    import matplotlib.pyplot as plt
    page = DatabaseBook('Gothic_Test').pages()[0]
    binary = Image.open(page.file('binary_highres_preproc', create_if_not_existing=True).local_path())
    gray = Image.open(page.file('gray_highres_preproc').local_path())
    pcgts = PcGts.from_file(page.file('pcgts', create_if_not_existing=True))
    overlay = np.array(gray)

    points_to_transform = np.array([(100, 50), (200, 50), (300, 50), (400, 50), (600, 50), (800, 50), (100, 100), (200, 150), (300, 200)], dtype=int)

    # staffs.draw(overlay)
    images = [binary, gray, Image.fromarray(overlay)]
    f, ax = plt.subplots(2, len(images), True, True)
    for a, l in enumerate(images):
        l = np.array(l)
        for p in points_to_transform:
            l[p[1]-5:p[1]+5, p[0]-5:p[0]+5] = 255
        ax[0, a].imshow(l)
Example #2
0
            ImagePadToPowerOf2(),  # Padding also done in line detector
        ])

    def __init__(
        self,
        pcgts: List[PcGts],
        params: DatasetParams,
    ):
        super().__init__(pcgts, params)


if __name__ == '__main__':
    import matplotlib.pyplot as plt
    from database import DatabaseBook
    page = DatabaseBook('Graduel').pages()[0]
    pcgts = PcGts.from_file(page.file('pcgts'))
    params = DatasetParams(
        full_page=True,
        gray=True,
        pad=(5, 5),
    )
    dataset = PCDataset([pcgts], params)
    images = dataset.load()

    f, ax = plt.subplots(len(images), 3, sharex='all')
    for i, out in enumerate(images):
        img, region, mask = out.line_image, out.region, out.mask
        if np.min(img.shape) > 0:
            print(img.shape)
            if params.full_page:
                ax[0].imshow(img)