summaryrefslogtreecommitdiff
path: root/wipesides.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-03-03 18:18:36 +0000
committerNick White <git@njw.name>2020-03-03 18:18:36 +0000
commit60071c2ea95e284f6c765528e81b930fe3fb4b92 (patch)
treeddd043afb8a97d94acee342a0f5e95dbee156cf3 /wipesides.go
parent83f6144cfe0e91df991e107e66b73d9e037ea969 (diff)
Add experimental vertical wiping feature to wiper
Diffstat (limited to 'wipesides.go')
-rw-r--r--wipesides.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/wipesides.go b/wipesides.go
index 3bedf67..0fc4a32 100644
--- a/wipesides.go
+++ b/wipesides.go
@@ -116,6 +116,19 @@ func toonarrow(img *image.Gray, lowedge int, highedge int, min int) bool {
return false
}
+// func sideways flips an image by sideways
+func sideways(img *image.Gray) *image.Gray {
+ b := img.Bounds()
+ newb := image.Rect(b.Min.Y, b.Min.X, b.Max.Y, b.Max.X)
+ new := image.NewGray(newb)
+ for x := b.Min.X; x < b.Max.X; x++ {
+ for y := b.Min.Y; y < b.Max.Y; y++ {
+ new.SetGray(y, x, img.GrayAt(x, y))
+ }
+ }
+ return new
+}
+
// Wipe fills the sections of image which fall outside the content
// area with white, providing the content area is above min %
func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
@@ -127,6 +140,19 @@ func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
return wipesides(img, lowedge, highedge)
}
+// VWipe fills the sections of image which fall outside the vertical
+// content area with white, providing the content area is above min %
+func VWipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
+ rotimg := sideways(img)
+ integral := integralimg.ToIntegralImg(rotimg)
+ lowedge, highedge := findedges(integral, wsize, thresh)
+ if toonarrow(img, lowedge, highedge, min) {
+ return img
+ }
+ wiped := wipesides(rotimg, lowedge, highedge)
+ return sideways(wiped)
+}
+
// WipeFile wipes an image file, filling the sections of the image
// which fall outside the content area with white, providing the
// content area is above min %.