From 60071c2ea95e284f6c765528e81b930fe3fb4b92 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 3 Mar 2020 18:18:36 +0000 Subject: Add experimental vertical wiping feature to wiper --- wipesides.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'wipesides.go') 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 %. -- cgit v1.2.1-24-ge1ad