func main() {
	// (A file with this name is output by the Go solution to the task
	// "Bitmap/Read an image through a pipe," but of course any 8-bit
	// P6 PPM file should work.)
	b, err := raster.ReadPpmFile("pipein.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	g := b.Grmap()
	h := g.Histogram(0)
	// compute median
	lb, ub := 0, len(h)-1
	var lSum, uSum int
	for lb <= ub {
		if lSum+h[lb] < uSum+h[ub] {
			lSum += h[lb]
			lb++
		} else {
			uSum += h[ub]
			ub--
		}
	}
	// apply threshold and write output file
	g.Threshold(uint16(ub * math.MaxUint16 / len(h)))
	err = g.Bitmap().WritePpmFile("threshold.ppm")
	if err != nil {
		fmt.Println(err)
	}
}
예제 #2
0
func main() {
	// Example file used here is Lenna50.jpg from the task "Percentage
	// difference between images" converted with with the command
	// convert Lenna50.jpg -colorspace gray Lenna50.ppm
	// It shows very obvious compression artifacts when viewed at higher
	// zoom factors.
	b, err := raster.ReadPpmFile("Lenna50.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	g0 = b.Grmap()
	w, h := g0.Extent()
	g1 = raster.NewGrmap(w, h)
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			g1.SetPx(x, y, median(x, y))
		}
	}
	// side by side comparison with input file shows compression artifacts
	// greatly smoothed over, although at some loss of contrast.
	err = g1.Bitmap().WritePpmFile("median.ppm")
	if err != nil {
		fmt.Println(err)
	}
}
func main() {
	b, err := raster.ReadPpmFile("Unfilledcirc.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	b.Flood(200, 200, raster.Pixel{127, 0, 0})
	err = b.WritePpmFile("flood.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
}
func main() {
	// (A file with this name is output by the Go solution to the task
	// "Bitmap/Read an image through a pipe," but of course any 8-bit
	//  P6 PPM file should work.)
	b, err := raster.ReadPpmFile("pipein.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	b = b.Grmap().Bitmap()
	err = b.WritePpmFile("grayscale.ppm")
	if err != nil {
		fmt.Println(err)
	}
}
func main() {
	// Example file used here is Lenna100.jpg from the task "Percentage
	// difference between images" converted with with the command
	// convert Lenna100.jpg -colorspace gray Lenna100.ppm
	b, err := raster.ReadPpmFile("Lenna100.ppm")
	if err != nil {
		fmt.Println(err)
		return
	}
	g0 := b.Grmap()
	g1 := g0.KernelFilter3(blur)
	err = g1.Bitmap().WritePpmFile("blur.ppm")
	if err != nil {
		fmt.Println(err)
	}
}