summaryrefslogtreecommitdiff
path: root/preproc/wipesides.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-06-03 10:54:02 +0100
committerNick White <git@njw.name>2019-06-03 10:54:02 +0100
commit20b694ee8510692804908f51fbbee3c39c859f37 (patch)
tree106a1354022f1f4ad8983799a88a26dd0f665969 /preproc/wipesides.go
parentd7f07893d08d9c29f46e50c4f779b0e701f411e4 (diff)
Add -m option to wipe to set minimum content area for wipe to proceed
If content is very light or sparse it may be better to not wipe at all than wipe almost all of the content leaving a small strip. This is done now by aborting the wipe if the detected content takes up less than the minimum % of the page (default is 30%).
Diffstat (limited to 'preproc/wipesides.go')
-rw-r--r--preproc/wipesides.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/preproc/wipesides.go b/preproc/wipesides.go
index 04bfa11..9b8387a 100644
--- a/preproc/wipesides.go
+++ b/preproc/wipesides.go
@@ -90,10 +90,25 @@ func wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray {
return new
}
+// toonarrow checks whether the area between lowedge and highedge is
+// less than min % of the total image width
+func toonarrow(img *image.Gray, lowedge int, highedge int, min int) bool {
+ b := img.Bounds()
+ imgw := b.Max.X - b.Min.X
+ wipew := highedge - lowedge
+ if float64(wipew) / float64(imgw) * 100 < float64(min) {
+ return true
+ }
+ return false
+}
+
// wipe fills the sections of image which fall outside the content
-// area with white
-func Wipe(img *image.Gray, wsize int, thresh float64) *image.Gray {
+// area with white, providing the content area is above min %
+func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
integral := integralimg.ToIntegralImg(img)
lowedge, highedge := findedges(integral, wsize, thresh)
+ if toonarrow(img, lowedge, highedge, min) {
+ return img
+ }
return wipesides(img, lowedge, highedge)
}