Esempio n. 1
0
File: vis.go Progetto: jvlmdr/go-cv
func Vis(feat *rimg64.Multi, weights WeightSet, cell int) image.Image {
	if feat.Channels == 31 {
		return Vis(compress(feat, weights), weights, cell)
	}

	width, height := feat.Width*cell, feat.Height*cell
	img := image.NewRGBA(image.Rect(0, 0, width, height))

	// Fill background.
	bg := color.Gray{0}
	if weights == Signed {
		bg = color.Gray{128}
	}
	draw.Draw(img, img.Bounds(), image.NewUniform(bg), image.ZP, draw.Src)

	// Rescale intensities to [0, 1].
	var dst vec.Mutable = vec.Slice(feat.Elems)
	var src vec.Const = dst

	if weights == Signed {
		max, _ := vec.Max(vec.Abs(src))
		rescale := func(x float64) float64 {
			return (1 + x/max) / 2
		}
		vec.Copy(dst, vec.Map(src, rescale))
	} else {
		switch weights {
		case Neg:
			src = vec.Scale(-1, src)
		case Abs:
			src = vec.Abs(src)
		default:
		}

		max, _ := vec.Max(src)
		if max <= 0 {
			vec.Copy(dst, vec.Zeros(src.Len()))
		} else {
			rescale := func(x float64) float64 {
				return math.Max(0, x/max)
			}
			vec.Copy(dst, vec.Map(src, rescale))
		}
	}

	gc := draw2d.NewGraphicContext(img)
	gc.SetLineWidth(1)

	// Draw cells.
	for x := 0; x < feat.Width; x++ {
		for y := 0; y < feat.Height; y++ {
			drawCell(feat, x, y, gc, cell)
		}
	}
	return img
}
Esempio n. 2
0
func InfNorm(x Const) float64 {
	y, _ := vec.Max(Abs(x))
	return y
}