Back to godoc.org
rescribe.xyz/integralimg

# Package integralimg

v0.5.1
Latest Go to latest

The latest major version is .

Published: Aug 4, 2020 | License: | Module:

## Overview ¶

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 ¶

### func MeanStdDev ¶

`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

Code:

```package main

import (
"fmt"
"image"
"image/draw"
"log"
"os"
"rescribe.xyz/integralimg"

_ "image/png"
)

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)
}
```
```Mean: 54677.229042, Standard Deviation: 21643.721672
```

### type Image ¶

`type Image [][]uint64`

Image is an integral Image

### func NewImage ¶

`func NewImage(r image.Rectangle) *Image`

NewImage returns a new integral Image with the given bounds.

### func (Image) At ¶

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

### func (Image) Bounds ¶

`func (i Image) Bounds() image.Rectangle`

### func (Image) ColorModel ¶

`func (i Image) ColorModel() color.Model`

### func (Image) Mean ¶

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

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

Example

Code:

```package main

import (
"fmt"
"image"
"image/draw"
"log"
"os"
"rescribe.xyz/integralimg"

_ "image/png"
)

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))
}
```
```Mean: 54677.229042
```

### func (Image) Set ¶

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

### func (Image) Sum ¶

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

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

Example

Code:

```package main

import (
"fmt"
"image"
"image/draw"
"log"
"os"
"rescribe.xyz/integralimg"

_ "image/png"
)

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))
}
```
```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 ¶

`func NewSqImage(r image.Rectangle) *SqImage`

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

### func (SqImage) At ¶

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

### func (SqImage) Bounds ¶

`func (i SqImage) Bounds() image.Rectangle`

### func (SqImage) ColorModel ¶

`func (i SqImage) ColorModel() color.Model`

### func (SqImage) Mean ¶

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

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

### func (SqImage) Set ¶

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

### func (SqImage) Sum ¶

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

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

### Package Files ¶

• integralimg.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.