Skip to content

Commit

Permalink
refactor/line2page
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnth committed Nov 21, 2023
1 parent 1a9453d commit 2d0ce37
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 21 deletions.
103 changes: 84 additions & 19 deletions pagetools/cli/transformations/line2page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,91 @@
import click


@click.command("line2page", help="Merges line images and line texts into combined images and XML files")
@click.option('-c', '--creator', type=str, default='PAGETools', help='Creator tag for PAGE XML', show_default=True)
@click.option('-s', '--source-folder', type=str, required=True, help='Path to images and GT')
@click.option('-i', '--image-folder', default='', type=str, help='Path to images', show_default=True)
@click.option('-gt', '--gt-folder', default='', type=str, help='Path to GT', show_default=True)
@click.option('-d', '--dest-folder', default=Path(Path.cwd(), 'merged'), type=str, help='Path where output gets stored',
@click.command("line2page",
help="Merges line images and line texts into combined images and XML files")
@click.option("-c",
"--creator",
type=str,
default="PAGETools",
help="Creator tag for PAGE XML",
show_default=True)
@click.option('-e', '--ext', default='.bin.png', type=str, help='Image extension', show_default=True)
@click.option('-p', '--pred', default=False, is_flag=True, help='Sets flag to also include .pred.txt', show_default=True)
@click.option('-l', '--lines', default=20, type=click.IntRange(min=0, clamp=True), help='Lines per page',
@click.option("-s",
"--source-folder",
type=str,
required=True,
help="Path to images and GT")
@click.option("-i",
"--image-folder",
type=str,
help="Path to images",
show_default=True)
@click.option('-ls', '--line-spacing', default=5, type=click.IntRange(min=0, clamp=True),
help='Spacing between lines (in pixel)', show_default=True)
@click.option('-b', '--border', nargs=4, default=(10, 10, 10, 10), type=click.IntRange(min=0, clamp=True),
help='Border (in pixel): TOP BOTTOM LEFT RIGHT', show_default=True)
@click.option('--debug', default='20', type=click.Choice(['10', '20', '30', '40', '50']),
help='Sets the level of feedback to receive: DEBUG=10, INFO=20, WARNING=30, ERROR=40, CRITICAL=50',
@click.option("-gt",
"--gt-folder",
type=str,
help="Path to GT",
show_default=True)
@click.option('--threads', default=16, type=click.IntRange(min=1, clamp=True), help='Thread count to be used',
@click.option("-d",
"--dest-folder",
default=Path(Path.cwd(), "merged"),
type=str,
help="Path where output gets stored",
show_default=True)
@click.option("-e",
"--ext",
default=".bin.png",
type=str,
help="Image extension",
show_default=True)
@click.option("-p",
"--pred",
default=False,
is_flag=True,
help="Sets flag to also include .pred.txt",
show_default=True)
@click.option("-l",
"--lines",
default=20,
type=click.IntRange(min=0, clamp=True),
help="Lines per page",
show_default=True)
@click.option("-ls",
"--line-spacing",
default=5,
type=click.IntRange(min=0, clamp=True),
help="Spacing between lines (in pixel)",
show_default=True)
@click.option("-oe",
"--output-extension",
type=str,
help="Output image extension")
@click.option("-b",
"--border",
nargs=4,
default=(10, 10, 10, 10),
type=click.IntRange(min=0, clamp=True),
help="Border (in pixel): TOP BOTTOM LEFT RIGHT", show_default=True)
@click.option("-bg",
"--background-color",
nargs=3,
default=(255, 255, 255),
type=click.IntRange(min=0, max=255, clamp=True),
help="RGB background color",
show_default=True)
@click.option("--debug",
default="20",
type=click.Choice(["10", "20", "30", "40", "50"]),
help="Sets the level of feedback to receive: DEBUG=10, INFO=20, WARNING=30, ERROR=40, CRITICAL=50",
show_default=True)
@click.option("--threads",
default=16,
type=click.IntRange(min=1, clamp=True),
help="Thread count to be used",
show_default=True)
@click.option("--xml-schema",
default="2019",
type=click.Choice(["2017", "2019"]),
help="Sets the year of the xml-Schema to be used",
show_default=True)
@click.option('--xml-schema', default='2019', type=click.Choice(['2017', '2019']),
help='Sets the year of the xml-Schema to be used', show_default=True)
def line2page_cli(creator: str,
source_folder: str,
image_folder: str,
Expand All @@ -41,7 +104,9 @@ def line2page_cli(creator: str,
pred: str,
lines: int,
line_spacing: int,
output_extension: str,
border: Tuple[int],
background_color: Tuple[int],
debug: bool,
threads: int,
xml_schema: str):
Expand All @@ -53,7 +118,7 @@ def line2page_cli(creator: str,
tic = time.perf_counter()

opt_obj = Line2Page(creator, source_folder, image_path, gt_path, dest_folder, ext, pred, lines, line_spacing,
border, debug, threads, xml_schema)
output_extension, border, background_color, debug, threads, xml_schema)
opt_obj.match_files()

pages = list(opt_obj.chunks(opt_obj.matches, opt_obj.lines))
Expand Down
6 changes: 4 additions & 2 deletions pagetools/src/line2page/Line2Page.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def __init__(self,
pred: str,
lines: int,
spacing: int,
output_extension: str,
border: Tuple[int],
background_color: Tuple[int],
debug: bool,
threads: int,
xml_schema: str):
Expand Down Expand Up @@ -58,9 +60,9 @@ def __init__(self,
# Extension strings used
self.gt_suffix = ".gt.txt"
self.pred_suffix = ".pred.txt"
self.img_suffix = '.nrm.png'
self.img_suffix = output_extension if output_extension else ext

self.background_colour = (255, 255, 255)
self.background_colour = background_color
self.colour_channels = 3
if border[1] > lines:
footer_size = border[1] - lines
Expand Down

0 comments on commit 2d0ce37

Please sign in to comment.