Merge pull request #166 from qurator-spk/updating_readme_for_eynollah_use_cases-cli

Updating readme for eynollah use cases cli
This commit is contained in:
Clemens Neudecker 2025-07-24 15:30:57 +02:00 committed by GitHub
commit 2996fc8b30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 20 deletions

View file

@ -85,7 +85,7 @@ smoke-test: tests/resources/kant_aufklaerung_1784_0020.tif
eynollah layout -di $(<D) -o $(TMPDIR) -m $(CURDIR)/models_eynollah eynollah layout -di $(<D) -o $(TMPDIR) -m $(CURDIR)/models_eynollah
test -s $(TMPDIR)/euler_rechenkunst01_1738_0025.xml test -s $(TMPDIR)/euler_rechenkunst01_1738_0025.xml
# binarize: # binarize:
eynollah binarization -m $(CURDIR)/default-2021-03-09 $< $(TMPDIR)/$(<F) eynollah binarization -m $(CURDIR)/default-2021-03-09 -i $< -o $(TMPDIR)/$(<F)
test -s $(TMPDIR)/$(<F) test -s $(TMPDIR)/$(<F)
@set -x; test "$$(identify -format '%w %h' $<)" = "$$(identify -format '%w %h' $(TMPDIR)/$(<F))" @set -x; test "$$(identify -format '%w %h' $<)" = "$$(identify -format '%w %h' $(TMPDIR)/$(<F))"
$(RM) -r $(TMPDIR) $(RM) -r $(TMPDIR)

View file

@ -48,8 +48,7 @@ def machine_based_reading_order(dir_xml, dir_out_modal_image, dir_out_classes, i
@main.command() @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('--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.option('--model_dir', '-m', type=click.Path(exists=True, file_okay=False), required=True, help='directory containing models for prediction')
@click.argument('input_image', required=False) @click.option("--input-image", "-i", help="input image", type=click.Path(exists=True, dir_okay=False))
@click.argument('output_image', required=False)
@click.option( @click.option(
"--dir_in", "--dir_in",
"-di", "-di",
@ -57,16 +56,14 @@ def machine_based_reading_order(dir_xml, dir_out_modal_image, dir_out_classes, i
type=click.Path(exists=True, file_okay=False), type=click.Path(exists=True, file_okay=False),
) )
@click.option( @click.option(
"--dir_out", "--output",
"-do", "-o",
help="directory for output images", help="output image (if using -i) or output image directory (if using -di)",
type=click.Path(exists=True, file_okay=False), type=click.Path(file_okay=True, dir_okay=True),
) )
def binarization(patches, model_dir, input_image, output_image, dir_in, dir_out): def binarization(patches, model_dir, input_image, dir_in, output):
assert (dir_out is None) == (dir_in is None), "Options -di and -do are mutually dependent" assert (dir_in is None) != (input_image is None), "Specify either -di and or -i not both"
assert (input_image is None) == (output_image is None), "INPUT_IMAGE and OUTPUT_IMAGE are mutually dependent" SbbBinarizer(model_dir).run(image_path=input_image, use_patches=patches, output=output, dir_in=dir_in)
assert (dir_in is None) != (input_image is None), "Specify either -di and -do options, or INPUT_IMAGE and OUTPUT_IMAGE"
SbbBinarizer(model_dir).run(image_path=input_image, use_patches=patches, save=output_image, dir_in=dir_in, dir_out=dir_out)

View file

@ -314,8 +314,8 @@ class SbbBinarizer:
prediction_true = prediction_true.astype(np.uint8) prediction_true = prediction_true.astype(np.uint8)
return prediction_true[:,:,0] return prediction_true[:,:,0]
def run(self, image=None, image_path=None, save=None, use_patches=False, dir_in=None, dir_out=None): def run(self, image=None, image_path=None, output=None, use_patches=False, dir_in=None):
print(dir_in,'dir_in') # print(dir_in,'dir_in')
if not dir_in: if not dir_in:
if (image is not None and image_path is not None) or \ if (image is not None and image_path is not None) or \
(image is None and image_path is None): (image is None and image_path is None):
@ -343,8 +343,8 @@ class SbbBinarizer:
kernel = np.ones((5, 5), np.uint8) kernel = np.ones((5, 5), np.uint8)
img_last[:, :][img_last[:, :] > 0] = 255 img_last[:, :][img_last[:, :] > 0] = 255
img_last = (img_last[:, :] == 0) * 255 img_last = (img_last[:, :] == 0) * 255
if save: if output:
cv2.imwrite(save, img_last) cv2.imwrite(output, img_last)
return img_last return img_last
else: else:
ls_imgs = os.listdir(dir_in) ls_imgs = os.listdir(dir_in)
@ -374,4 +374,4 @@ class SbbBinarizer:
img_last[:, :][img_last[:, :] > 0] = 255 img_last[:, :][img_last[:, :] > 0] = 255
img_last = (img_last[:, :] == 0) * 255 img_last = (img_last[:, :] == 0) * 255
cv2.imwrite(os.path.join(dir_out,image_stem+'.png'), img_last) cv2.imwrite(os.path.join(output, image_stem + '.png'), img_last)

View file

@ -85,8 +85,8 @@ def test_run_eynollah_binarization_filename(tmp_path, subtests, pytestconfig, ca
outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png') outfile = tmp_path.joinpath('kant_aufklaerung_1784_0020.png')
args = [ args = [
'-m', SBBBIN_MODELS, '-m', SBBBIN_MODELS,
str(infile), '-i', str(infile),
str(outfile), '-o', str(outfile),
] ]
caplog.set_level(logging.INFO) caplog.set_level(logging.INFO)
def only_eynollah(logrec): def only_eynollah(logrec):
@ -117,7 +117,7 @@ def test_run_eynollah_binarization_directory(tmp_path, subtests, pytestconfig, c
args = [ args = [
'-m', SBBBIN_MODELS, '-m', SBBBIN_MODELS,
'-di', str(indir), '-di', str(indir),
'-do', str(outdir), '-o', str(outdir),
] ]
caplog.set_level(logging.INFO) caplog.set_level(logging.INFO)
def only_eynollah(logrec): def only_eynollah(logrec):