Пример #1
0
func Draw(ind *node.Node, img *imgut.Image) {
	// We have to compile the nodes
	exec := node.CompileTree(ind).(*binary.Primitive)
	// Apply the function
	//	exec(0 0, float64(img.W), float64(img.H), img)
	var call imgut.PixelFunc = func(x, y float64) float64 {
		return float64(exec.Eval(binary.NumericIn(x), binary.NumericIn(y)))
	}
	img.FillMathBounds(call)
}
Пример #2
0
func MakeFitSSIM(targetImage *imgut.Image) func(*imgut.Image) float64 {
	return func(indImage *imgut.Image) float64 {
		// Create temporary files
		tarTemp, _ := ioutil.TempFile(".", "tarImg")
		indTemp, _ := ioutil.TempFile(".", "indImg")
		// Schedule for cleaning
		defer os.Remove(tarTemp.Name())
		defer os.Remove(indTemp.Name())
		tarTemp.Close()
		indTemp.Close()
		// Save images to those files
		targetImage.WritePNG(tarTemp.Name())
		indImage.WritePNG(indTemp.Name())

		// Compute the DSSIM value (dissimilarity)
		cmd := exec.Command("./dssim.exe", tarTemp.Name(), indTemp.Name())
		var out, stderr bytes.Buffer
		cmd.Stdout = &out
		cmd.Stderr = &stderr
		err := cmd.Run()
		if err != nil {
			print("ERRORE CON LA CALL", stderr.String())
			ooo, _ := cmd.CombinedOutput()
			print("Output ")
			print(ooo)
			panic(err)
		}
		res := strings.Split(out.String(), "\t")[0]
		fit, err := strconv.ParseFloat(res, 64)
		if err != nil {
			print("ERROR CON CONVERT")
			panic(err)
		}
		return fit
	}
}