Skip to content

Commit

Permalink
Merge pull request #74 from bertsky/fix-niblack-k
Browse files Browse the repository at this point in the history
Fix niblack k passing
  • Loading branch information
bertsky authored Oct 21, 2020
2 parents de82b91 + 2e2197b commit e2234b1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
40 changes: 27 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Versioned according to [Semantic Versioning](http://semver.org/).

## Unreleased

## [1.2.3] - 2020-10-13

Fixed:

- pass correct `k` value for `niblack`

Changed:

- also crop AlternativeImage to page border if not already
- remove temporary images from cropping afterwards

## [1.2.2] - 2020-09-30

Fixed:
Expand Down Expand Up @@ -142,17 +153,20 @@ Changed
First release

<!-- link-labels -->
[1.2.0]: ../../compare/v1.2.0...v1.1.10
[1.1.10]: ../../compare/v1.1.10...v1.1.9
[1.1.9]: ../../compare/v1.1.9...v1.1.8
[1.1.8]: ../../compare/v1.1.8...v1.1.7
[1.1.7]: ../../compare/v1.1.7...v1.1.6
[1.1.6]: ../../compare/v1.1.6...v1.1.5
[1.1.5]: ../../compare/v1.1.5...v1.1.4
[1.1.4]: ../../compare/v1.1.4...v1.1.3
[1.1.3]: ../../compare/v1.1.3...v1.1.2
[1.1.2]: ../../compare/v1.1.2...v1.1.1
[1.1.1]: ../../compare/v1.1.1...v1.1.0
[1.1.0]: ../../compare/v1.1.0...v1.0.0
[1.0.0]: ../../compare/v1.0.0...v0.0.2
[1.2.3]: ../../compare/v1.2.2...v1.2.3
[1.2.2]: ../../compare/v1.2.1...v1.2.2
[1.2.1]: ../../compare/v1.2.0...v1.2.1
[1.2.0]: ../../compare/v1.1.10...v1.2.0
[1.1.10]: ../../compare/v1.1.9...v1.1.10
[1.1.9]: ../../compare/v1.1.8...v1.1.9
[1.1.8]: ../../compare/v1.1.7...v1.1.8
[1.1.7]: ../../compare/v1.1.6...v1.1.7
[1.1.6]: ../../compare/v1.1.5...v1.1.6
[1.1.5]: ../../compare/v1.1.4...v1.1.5
[1.1.4]: ../../compare/v1.1.3...v1.1.4
[1.1.3]: ../../compare/v1.1.2...v1.1.3
[1.1.2]: ../../compare/v1.1.1...v1.1.2
[1.1.1]: ../../compare/v1.1.0...v1.1.1
[1.1.0]: ../../compare/v1.0.0...v1.1.0
[1.0.0]: ../../compare/v0.0.2...v1.0.0
[0.0.2]: ../../compare/HEAD...v0.0.2
49 changes: 28 additions & 21 deletions ocrd-olena-binarize
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,29 @@ EOF
"$out_fpath" )
image_in_fpath=$(xmlstarlet "${options[@]}")
ocrd log info "found imageFilename '${image_in_fpath}' for input file ID=${in_id} (pageId=${in_pageId})"
image_in_id=$(image_id_from_fpath "$image_in_fpath" "$in_id" "$in_pageId")
image_in_fpath="${image_in_fpath#file://}"
if options=( --no-doc-namespace sel
-N "pc=${namespace}" -t
-v '/pc:PcGts/pc:Page/pc:Border/pc:Coords/@points'
"$out_fpath" )
border=$(xmlstarlet "${options[@]}"); then
ocrd log debug "Using explicitly set page border '$border' for input file ID=${in_id} (pageId=${in_pageId})"
local tmpfile
tmpfile=$(mktemp --tmpdir ocrd-olena-binarize-cropped.XXXXXX)
xywh_from_points $border | {
read width height left top
convert "${image_in_fpath}[0]" -crop ${width}x${height}+${left}+${top} "$tmpfile"
}
image_in_fpath="$tmpfile"
comments="cropped,binarized"
else
comments="binarized"
fi
comments=binarized
fi

image_in_id=$(image_id_from_fpath "$image_in_fpath" "$in_id" "$in_pageId")
image_in_fpath="${image_in_fpath#file://}"
local tmpfile=
if [[ "$comments" =~ cropped ]]; then
ocrd log debug "Using page border in input file ID=${in_id} (pageId=${in_pageId})"
elif options=( --no-doc-namespace sel
-N "pc=${namespace}" -t
-v '/pc:PcGts/pc:Page/pc:Border/pc:Coords/@points'
"$out_fpath" )
# FIXME: add a bashlib wrapper for workspace.image_from_page to use here
border=$(xmlstarlet "${options[@]}"); then
ocrd log debug "Cropping to page border '$border' in input file ID=${in_id} (pageId=${in_pageId})"
tmpfile=$(mktemp --tmpdir ocrd-olena-binarize-cropped.XXXXXX)
xywh_from_points $border | {
read width height left top
convert "${image_in_fpath}[0]" -crop ${width}x${height}+${left}+${top} "$tmpfile"
}
image_in_fpath="$tmpfile"
comments="${comments%binarized}cropped,binarized"
fi

# set output names
image_out_id="${image_in_id}-BIN_${params[impl]}"
image_out_fpath="${out_file_grp}/${image_out_id}.png"
Expand All @@ -279,6 +281,11 @@ EOF
local scribo_extra=$(auto_winsize "${original_image_in_fpath}" "${in_pageId}")

scribo-cli "${params[impl]}" "${image_in_fpath}" "${image_out_fpath}" "${scribo_options[@]}" ${scribo_extra}

# Remove temporary image file, if any
if [ -n "$tmpfile" ]; then
rm "$tmpfile"
fi

# Add image file to METS
ocrd workspace add \
Expand Down Expand Up @@ -360,7 +367,7 @@ function main {
scribo_options+=(--disable-negate-input)
# has default -0.2 not 0.34
scribo_options+=(--k $($PYTHON -c "print(${params[k]}/-1.7)"))
;& # fall through
;;& # get more
sauvola|kim|wolf)
scribo_options+=(--k ${params[k]})
;;& # get more
Expand Down
6 changes: 3 additions & 3 deletions ocrd-tool.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"version": "1.2.2",
"version": "1.2.3",
"git_url": "https://github.com/OCR-D/ocrd_olena",
"tools": {
"ocrd-olena-binarize": {
"executable": "ocrd-olena-binarize",
"description": "OLENA's binarization algos for OCR-D (on page-level)",
"description": "popular binarization algorithms implemented by Olena/SCRIBO, wrapped for OCR-D (on page level only)",
"categories": [
"Image preprocessing"
],
Expand Down Expand Up @@ -36,7 +36,7 @@
"default": 0.34
},
"win-size": {
"description": "The (odd) window size in pixels; when zero (default), set to DPI; for Otsu, does not apply",
"description": "The (odd) window size in pixels; when zero (default), set to DPI (or 301); for Otsu, does not apply",
"type": "number",
"format": "integer",
"default": 0
Expand Down

0 comments on commit e2234b1

Please sign in to comment.