MCPcopy Index your code
hub / github.com/gonum/plot / Diff

Function Diff

cmpimg/cmpimg.go:208–238  ·  view source on GitHub ↗

Diff calculates an intensity-scaled difference between images a and b and places the result in dst, returning the intersection of a, b and dst. It is the responsibility of the caller to construct dst so that it will overlap with a and b. For the purposes of Diff, alpha is not considered. Diff is no

(dst draw.Image, a, b image.Image)

Source from the content-addressed store, hash-verified

206// difference between the input images, but rather to highlight differences
207// between them for testing purposes, so the calculation is rather naive.
208func Diff(dst draw.Image, a, b image.Image) image.Rectangle {
209 rect := dst.Bounds().Intersect(a.Bounds()).Intersect(b.Bounds())
210
211 // Determine greyscale dynamic range.
212 min := uint16(math.MaxUint16)
213 max := uint16(0)
214 for x := rect.Min.X; x < rect.Max.X; x++ {
215 for y := rect.Min.Y; y < rect.Max.Y; y++ {
216 p := diffColor{a.At(x, y), b.At(x, y)}
217 g := color.Gray16Model.Convert(p).(color.Gray16)
218 if g.Y < min {
219 min = g.Y
220 }
221 if g.Y > max {
222 max = g.Y
223 }
224 }
225 }
226
227 // Render intensity-scaled difference.
228 for x := rect.Min.X; x < rect.Max.X; x++ {
229 for y := rect.Min.Y; y < rect.Max.Y; y++ {
230 dst.Set(x, y, scaledColor{
231 min: uint32(min), max: uint32(max),
232 c: diffColor{a.At(x, y), b.At(x, y)},
233 })
234 }
235 }
236
237 return rect
238}
239
240type diffColor struct {
241 a, b color.Color

Callers 2

TestDiffFunction · 0.85
CheckPlotApproxFunction · 0.85

Calls 2

BoundsMethod · 0.80
AtMethod · 0.65

Tested by 1

TestDiffFunction · 0.68