Documentation ¶
Overview ¶
integral is a package for processing integral images, aka summed area tables. These are structures which precompute the sum of pixels to the left and above each pixel, which can make several common image processing operations much faster.
A lot of image processing operations rely on many calculations of the sum or mean of a set of pixels. As these have been precalculated for an integral image, these calculations are much faster. Image.Sum() and Image.Mean() functions are provided by this package to take advantage of this.
Another common requirement is standard deviation over an area of an image. This can be calculated by creating an integral image and squared integral image (SqImage) for a base image, and passing them to the MeanStdDev() function provided.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MeanStdDev ¶
MeanStdDev calculates the mean and standard deviation of a section of an image, using the corresponding regular and square integral images.
Example ¶
package main import ( "fmt" "image" "image/draw" "log" "os" _ "image/png" "rescribe.xyz/integral" ) func main() { f, err := os.Open("testdata/in.png") if err != nil { log.Fatal(err) } defer f.Close() img, _, err := image.Decode(f) if err != nil { log.Fatal(err) } b := img.Bounds() in := integral.NewImage(b) sq := integral.NewSqImage(b) draw.Draw(in, b, img, b.Min, draw.Src) draw.Draw(sq, b, img, b.Min, draw.Src) mean, stddev := integral.MeanStdDev(*in, *sq, b) fmt.Printf("Mean: %f, Standard Deviation: %f\n", mean, stddev) }
Output: Mean: 54677.229042, Standard Deviation: 21643.721672
Types ¶
type Image ¶
type Image [][]uint64
Image is an integral image
func NewImage ¶
NewImage returns a new integral image with the given bounds.
func (Image) Mean ¶
Mean returns the average value of pixels in a section of an image
Example ¶
package main import ( "fmt" "image" "image/draw" "log" "os" _ "image/png" "rescribe.xyz/integral" ) func main() { f, err := os.Open("testdata/in.png") if err != nil { log.Fatal(err) } defer f.Close() img, _, err := image.Decode(f) if err != nil { log.Fatal(err) } b := img.Bounds() in := integral.NewImage(b) draw.Draw(in, b, img, b.Min, draw.Src) fmt.Printf("Mean: %f\n", in.Mean(b)) }
Output: Mean: 54677.229042
func (Image) Sum ¶
Sum returns the sum of all pixels in a section of an image
Example ¶
package main import ( "fmt" "image" "image/draw" "log" "os" _ "image/png" "rescribe.xyz/integral" ) func main() { f, err := os.Open("testdata/in.png") if err != nil { log.Fatal(err) } defer f.Close() img, _, err := image.Decode(f) if err != nil { log.Fatal(err) } b := img.Bounds() in := integral.NewImage(b) draw.Draw(in, b, img, b.Min, draw.Src) fmt.Printf("Sum: %d\n", in.Sum(b)) }
Output: Sum: 601340165
type SqImage ¶
type SqImage [][]uint64
SqImage is a Square integral image. A squared integral image is an integral image for which the square of each pixel is saved; this is useful for efficiently calculating Standard Deviation.
func NewSqImage ¶
NewSqImage returns a new squared integral image with the given bounds.
func (SqImage) Mean ¶
Mean returns the average value of pixels in a section of an image