Skip to content

Commit

Permalink
binarization as a standalone command
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidrezanezhad committed Oct 21, 2024
1 parent f93fa12 commit 70772d4
Show file tree
Hide file tree
Showing 3 changed files with 418 additions and 3 deletions.
33 changes: 33 additions & 0 deletions qurator/eynollah/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import click
from ocrd_utils import initLogging, setOverrideLogLevel
from qurator.eynollah.eynollah import Eynollah
from qurator.eynollah.sbb_binarize import SbbBinarizer

@click.group()
def main():
Expand Down Expand Up @@ -48,6 +49,38 @@ def main():
def machine_based_reading_order(dir_xml, dir_out_modal_image, dir_out_classes, input_height, input_width, min_area_size):
xml_files_ind = os.listdir(dir_xml)

@main.command()
@click.option('--patches/--no-patches', default=True, help='by enabling this parameter you let the model to see the image in patches.')

@click.option('--model_dir', '-m', type=click.Path(exists=True, file_okay=False), required=True, help='directory containing models for prediction')

@click.argument('input_image')

@click.argument('output_image')
@click.option(
"--dir_in",
"-di",
help="directory of images",
type=click.Path(exists=True, file_okay=False),
)
@click.option(
"--dir_out",
"-do",
help="directory where the binarized images will be written",
type=click.Path(exists=True, file_okay=False),
)

def binarization(patches, model_dir, input_image, output_image, dir_in, dir_out):
if not dir_out and (dir_in):
print("Error: You used -di but did not set -do")
sys.exit(1)
elif dir_out and not (dir_in):
print("Error: You used -do to write out binarized images but have not set -di")
sys.exit(1)
SbbBinarizer(model_dir).run(image_path=input_image, use_patches=patches, save=output_image, dir_in=dir_in, dir_out=dir_out)




@main.command()
@click.option(
Expand Down
5 changes: 2 additions & 3 deletions qurator/eynollah/eynollah.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def __init__(
pcgts=pcgts)
self.logger = logger if logger else getLogger('eynollah')
self.dir_models = dir_models

self.model_dir_of_enhancement = dir_models + "/eynollah-enhancement_20210425"
self.model_dir_of_binarization = dir_models + "/eynollah-binarization_20210425"
self.model_dir_of_col_classifier = dir_models + "/eynollah-column-classifier_20210425"
Expand Down Expand Up @@ -4769,9 +4768,9 @@ def run(self):

textline_mask_tot_ea_deskew = resize_image(textline_mask_tot_ea,img_h_new, img_w_new )

slope_deskew, slope_first = self.run_deskew(textline_mask_tot_ea_deskew)
slope_deskew, slope_first = 0, 0#self.run_deskew(textline_mask_tot_ea_deskew)
else:
slope_deskew, slope_first = self.run_deskew(textline_mask_tot_ea)
slope_deskew, slope_first = 0, 0#self.run_deskew(textline_mask_tot_ea)
#print("text region early -2,5 in %.1fs", time.time() - t0)
#self.logger.info("Textregion detection took %.1fs ", time.time() - t1t)
num_col, num_col_classifier, img_only_regions, page_coord, image_page, mask_images, mask_lines, text_regions_p_1, cont_page, table_prediction, textline_mask_tot_ea, img_bin_light = \
Expand Down
Loading

0 comments on commit 70772d4

Please sign in to comment.