func Main() { file, err := os.Open("in.ppm") if err != nil { log.Fatal(err) } img, format, err := image.Decode(file) log.Println("Format: ", format) if err != nil { log.Fatal(err) } outFile, err := os.Create("out.ppm") if err != nil { log.Fatal(err) } err = pnm.Encode(outFile, img, pnm.PPM) if err != nil { log.Fatal(err) } }
func Example() { file, err := os.Open("in.ppm") if err != nil { log.Fatal(err) } img, err := image.Decode(file) if err != nil { log.Fatal(err) } outFile, err := os.Create("out.ppm") if err != nil { log.Fatal(err) } err = pnm.Encode(outFile, img, pnm.PPM) if err != nil { log.Fatal(err) } }
func main() { flag.Parse() fmt.Printf("Computing optical flow betwen %s and %s, result will be saved in %s and %s\n", finame1, finame2, magImageName, dirImageName) fin1, err := os.Open(finame1) if err != nil { log.Fatal(err) } defer fin1.Close() img1, _, err := image.Decode(fin1) if err != nil { log.Fatal(err) } fin2, err := os.Open(finame2) if err != nil { log.Fatal(err) } defer fin2.Close() img2, _, err := image.Decode(fin2) if err != nil { log.Fatal(err) } if !img1.Bounds().Eq(img2.Bounds()) { log.Fatal("The image bounds need to match") } // Create Gray float based images with overlap for mirroring boundaries f1 := floatimage.GrayFloatWithDummiesFromImage(img1) f2 := floatimage.GrayFloatWithDummiesFromImage(img2) min1, max1, mean1, var1 := analyse(f1) min2, max2, mean2, var2 := analyse(f2) fmt.Printf("min1 = %f, max1 = %f, mean1 = %f, var1 = %f\n", min1, max1, mean1, var1) fmt.Printf("min2 = %f, max2 = %f, mean2 = %f, var2 = %f\n", min2, max2, mean2, var2) uv := algorithms.OpticFlowHornSchunk(f1, f2, float32(alpha), iterations) magImg := algorithms.MagImage(uv) fout, err := os.Create(magImageName) if err != nil { log.Fatal(err) } defer fout.Close() magImg.ScaleToUnsignedByte() mag := magImg.Dedummify() err = pnm.Encode(fout, mag, pnm.PGM) if err != nil { log.Fatal(err) } uv.ColorFunc = func(x, y int, d []float32) color.Color { const mult = 100.0 g := magImg.AtF(x, y)[0] return color.YCbCr{floatimage.Tu8c(g), floatimage.Tu8c(d[0]*mult + 127.5), floatimage.Tu8c(d[1]*mult + 127.5)} } uv.ColorModelFunc = func() color.Model { return color.YCbCrModel } fout2, err := os.Create(dirImageName) if err != nil { log.Fatal(err) } defer fout2.Close() err = pnm.Encode(fout2, uv.Dedummify(), pnm.PPM) if err != nil { log.Fatal(err) } }