Exemple #1
0
func mean(img image.Image, disk int) image.Image {
	g := gift.New(gift.Grayscale())
	g.Add(gift.Mean(disk, false)) // use square neighborhood
	dst := image.NewRGBA(g.Bounds(img.Bounds()))
	g.Draw(dst, img)
	return (dst)
}
Exemple #2
0
func meanF(img image.Image, disk int) imageF {

	g := gift.New(gift.Grayscale())
	g.Add(gift.Mean(disk, false)) // use square neighborhood
	dst := image.NewRGBA(g.Bounds(img.Bounds()))
	g.Draw(dst, img)

	// now convert this to float array of arrays
	floatData := make([][]float32, dst.Bounds().Max.Y-dst.Bounds().Min.Y)
	for i := range floatData {
		floatData[i] = make([]float32, dst.Bounds().Max.X-dst.Bounds().Min.X)
	}
	bounds := dst.Bounds()
	for y := bounds.Min.X; y < bounds.Max.X; y++ {
		for x := bounds.Min.Y; x < bounds.Max.Y; x++ {
			pr, _, _, _ := dst.At(x, y).RGBA()
			floatData[x][y] = float32(pr) // 0.2125*float32(pr) + 0.7154*float32(pg) + 0.0721*float32(pb)
		}
	}

	return floatData
}