integralimg

package module
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2020 License: GPL-3.0 Imports: 3 Imported by: 0

README

# rescribe.xyz/integralimg package

NOTE: This package has been renamed rescribe.xyz/integral - future
updates will be there. Please update links.

This package contains methods and structures for dealing with
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.

This is a Go package, and can be installed in the standard go way,
by running `go get rescribe.xyz/integralimg` and documentation
can be read with the `go doc` command or online at
<https://pkg.go.dev/rescribe.xyz/integralimg>.

## Contributions

Any and all comments, bug reports, patches or pull requests would
be very welcomely received. Please email them to <nick@rescribe.xyz>.

## License

This package is licensed under the GPLv3. See the LICENSE file for
more details.

Documentation

Overview

NOTE: This package has been renamed rescribe.xyz/integral - future updates will be there. Please update links.

integralimg 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 added in v0.3.0

func MeanStdDev(i Image, sq SqImage, r image.Rectangle) (float64, float64)

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/integralimg"
)

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()
	integral := integralimg.NewImage(b)
	sqIntegral := integralimg.NewSqImage(b)
	draw.Draw(integral, b, img, b.Min, draw.Src)
	draw.Draw(sqIntegral, b, img, b.Min, draw.Src)
	mean, stddev := integralimg.MeanStdDev(*integral, *sqIntegral, b)
	fmt.Printf("Mean: %f, Standard Deviation: %f\n", mean, stddev)
}
Output:

Mean: 54677.229042, Standard Deviation: 21643.721672

Types

type Image added in v0.2.0

type Image [][]uint64

Image is an integral Image

func NewImage added in v0.2.0

func NewImage(r image.Rectangle) *Image

NewImage returns a new integral Image with the given bounds.

func (Image) At added in v0.2.0

func (i Image) At(x, y int) color.Color

func (Image) Bounds added in v0.2.0

func (i Image) Bounds() image.Rectangle

func (Image) ColorModel added in v0.2.0

func (i Image) ColorModel() color.Model

func (Image) Mean added in v0.3.0

func (i Image) Mean(r image.Rectangle) float64

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/integralimg"
)

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()
	integral := integralimg.NewImage(b)
	draw.Draw(integral, b, img, b.Min, draw.Src)
	fmt.Printf("Mean: %f\n", integral.Mean(b))
}
Output:

Mean: 54677.229042

func (Image) Set added in v0.2.0

func (i Image) Set(x, y int, c color.Color)

func (Image) Sum added in v0.3.0

func (i Image) Sum(r image.Rectangle) uint64

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/integralimg"
)

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()
	integral := integralimg.NewImage(b)
	draw.Draw(integral, b, img, b.Min, draw.Src)
	fmt.Printf("Sum: %d\n", integral.Sum(b))
}
Output:

Sum: 601340165

type SqImage added in v0.2.0

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 added in v0.2.0

func NewSqImage(r image.Rectangle) *SqImage

NewSqImage returns a new squared integral Image with the given bounds.

func (SqImage) At added in v0.2.0

func (i SqImage) At(x, y int) color.Color

func (SqImage) Bounds added in v0.2.0

func (i SqImage) Bounds() image.Rectangle

func (SqImage) ColorModel added in v0.2.0

func (i SqImage) ColorModel() color.Model

func (SqImage) Mean added in v0.3.0

func (i SqImage) Mean(r image.Rectangle) float64

Mean returns the average value of pixels in a section of an image

func (SqImage) Set added in v0.2.0

func (i SqImage) Set(x, y int, c color.Color)

func (SqImage) Sum added in v0.3.0

func (i SqImage) Sum(r image.Rectangle) uint64

Sum returns the sum of all pixels in a section of an image

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL