예제 #1
0
파일: plot.go 프로젝트: penten/sound
func PlotSpectogram(sr Reader, outpath string, from, to int) error {
	d, err := dft(sr, from, to)
	if err != nil {
		return err
	}

	// make image
	height, width := len(d[0]), len(d)
	image := image.NewGray(image.Rect(0, 0, width, height))

	// find maximum value in DFT
	max := maxAmp(d)
	max = math.Log(1 + max)

	// plot each point on image
	for i, col := range d {
		for j, amp := range col {
			// Log(Xk+1) will give us a positive value
			// Using log here allows low amplitudes to be more visible
			bright := uint8(float64(255) * math.Log(1+amp) / max)
			image.Set(i, height-j, color.RGBA{bright, bright, bright, 255})
		}
	}

	of, err := os.Create(outpath)
	if err != nil {
		return err
	}

	return png.Encode(of, image)
}
예제 #2
0
파일: plot.go 프로젝트: penten/sound
func PlotOscillogram(sr Reader, outpath string, from, to int) error {
	// make image
	height, width := 255, to-from
	gray := color.RGBA{255, 0, 0, 255}
	image := image.NewGray(image.Rect(0, 0, width, height*2))

	// plot each point on image + a central gray line at 0
	var amp float64
	for t := from; t < to; t++ {
		amp = float64(height) * (sr.Get(0, t) * 2)
		image.Set(t, int(amp), color.White)

		image.Set(t, height, gray)
	}

	of, err := os.Create(outpath)
	if err != nil {
		return err
	}

	return png.Encode(of, image)
}
예제 #3
0
파일: render.go 프로젝트: jaredly/goflam3
func matrixToImage(mx *[][]int, width, height int, log bool) *image.RGBA {
	if log {
		if !equalize_log(mx, 255, .995, .0005) {
			return nil
		}
	} else {
		equalize(mx, 255, .995, .0005)
	}
	image := image.NewRGBA(image.Rect(0, 0, width, height))
	// now write the values to an image, equalized by the 3rd-brightest point
	for x, row := range *mx {
		for y, v := range row {
			val := uint8(v)
			image.Set(x, y, color.RGBA{val, val * 100 / 255, val, 255})
		}
	}
	return image
}