當前位置: 首頁>>代碼示例>>Golang>>正文


Golang image.NewGray16函數代碼示例

本文整理匯總了Golang中image.NewGray16函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewGray16函數的具體用法?Golang NewGray16怎麽用?Golang NewGray16使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewGray16函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRaytracer

func NewRaytracer(cfg Config) *Raytracer {
	rect := cfg.Images[0].Bounds()
	numCPU := 1

	if cfg.MultiThreaded {
		numCPU = runtime.NumCPU()
		for numCPU%rect.Max.Y != 0 {
			numCPU++
		}
	}

	rt := &Raytracer{
		cfg:        cfg,
		frame:      uint32(cfg.FrameSeed),
		clear:      color.RGBA{0, 0, 0, 255},
		numThreads: numCPU,
		work:       make(chan rtJob, numCPU*2),
	}

	if cfg.Depth {
		rect := cfg.Images[0].Bounds()
		rt.depth = [2]*image.Gray16{image.NewGray16(rect), image.NewGray16(rect)}
	}

	for i := 0; i < numCPU; i++ {
		go rt.workerLoop()
	}

	return rt
}
開發者ID:andreas-jonsson,項目名稱:octatron,代碼行數:30,代碼來源:raytracer.go

示例2: to_img

func to_img(brot *[size][size]uint, max uint) {
	gray := image.NewGray16(image.Rect(0, 0, size, size))
	norm_gray := image.NewGray16(image.Rect(0, 0, size, size))
	for x := 0; x < size; x++ {
		for y := 0; y < size; y++ {
			pix := brot[x][y]
			norm := float64(brot[x][y]*4) / float64(max) * 65534
			if norm > 65534 {
				norm = 65534
			}
			if pix > 65534 {
				pix = 65534
			}
			gray.SetGray16(
				x, y,
				color.Gray16{uint16(pix)})
			norm_gray.SetGray16(
				x, y,
				color.Gray16{uint16(norm)})
		}
	}
	w, _ := os.OpenFile("./brot.png", os.O_CREATE|os.O_WRONLY, 0666)
	png.Encode(w, gray)
	n, _ := os.OpenFile("./brot-norm.png", os.O_CREATE|os.O_WRONLY, 0666)
	png.Encode(n, norm_gray)
}
開發者ID:rciorba,項目名稱:frac,代碼行數:26,代碼來源:buddah.go

示例3: NewDrawableSize

// NewDrawableSize returns a new draw.Image with the same type as p and the given bounds.
// If p is not a draw.Image, another type is used.
func NewDrawableSize(p image.Image, r image.Rectangle) draw.Image {
	switch p := p.(type) {
	case *image.RGBA:
		return image.NewRGBA(r)
	case *image.RGBA64:
		return image.NewRGBA64(r)
	case *image.NRGBA:
		return image.NewNRGBA(r)
	case *image.NRGBA64:
		return image.NewNRGBA64(r)
	case *image.Alpha:
		return image.NewAlpha(r)
	case *image.Alpha16:
		return image.NewAlpha16(r)
	case *image.Gray:
		return image.NewGray(r)
	case *image.Gray16:
		return image.NewGray16(r)
	case *image.Paletted:
		pl := make(color.Palette, len(p.Palette))
		copy(pl, p.Palette)
		return image.NewPaletted(r, pl)
	case *image.CMYK:
		return image.NewCMYK(r)
	default:
		return image.NewRGBA(r)
	}
}
開發者ID:cautio,項目名稱:imageserver,代碼行數:30,代碼來源:util.go

示例4: NewImageOfTypeRect

func NewImageOfTypeRect(src image.Image, bounds image.Rectangle) image.Image {
	switch i := src.(type) {
	case *image.Alpha:
		return image.NewAlpha(bounds)
	case *image.Alpha16:
		return image.NewAlpha16(bounds)
	case *image.Gray:
		return image.NewGray(bounds)
	case *image.Gray16:
		return image.NewGray16(bounds)
	case *image.NRGBA:
		return image.NewNRGBA(bounds)
	case *image.NRGBA64:
		return image.NewNRGBA64(bounds)
	case *image.Paletted:
		return image.NewPaletted(bounds, i.Palette)
	case *image.RGBA:
		return image.NewRGBA(bounds)
	case *image.RGBA64:
		return image.NewRGBA64(bounds)
	case *image.YCbCr:
		return image.NewYCbCr(bounds, i.SubsampleRatio)
	}
	panic("Unknown image type")
}
開發者ID:alexchipliev,項目名稱:go-start,代碼行數:25,代碼來源:functions.go

示例5: Draw

func Draw(f Function, re_from, re_to, im_from, im_to float64, pix_size float64) image.Image {
	w := re_to - re_from
	h := im_to - im_from
	if w < 0 || h < 0 {
		panic("negative width or height")
	}

	if pix_size < 0 {
		panic("negative pixel size")
	}

	c := coords{pix_size, complex(re_from, im_from)}

	resx := int(w / pix_size)
	resy := int(h / pix_size)

	m := image.NewGray16(image.Rect(0, 0, resx, resy))

	bounds := m.Bounds()
	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
		for x := bounds.Min.X; x < bounds.Max.X; x++ {
			z := c.At(x, y)

			o := Orbit(f, z, 2, 500)

			if o < 0 {
				m.Set(x, y, color.Black)
			} else {
				m.Set(x, y, color.Gray16{uint16(o * 0x10000 / 32)})
			}
		}
	}

	return m
}
開發者ID:jshholland,項目名稱:julia,代碼行數:35,代碼來源:draw.go

示例6: ImageWithMargin

// Return an image of the grid, with black blocks for true items and
// white blocks for false items, with the given block size and margin.
func (g *BitGrid) ImageWithMargin(blockSize, margin int) image.Image {
	width := blockSize * (2*margin + g.Width())
	height := blockSize * (2*margin + g.Height())
	i := image.NewGray16(image.Rect(0, 0, width, height))
	for y := 0; y < blockSize*margin; y++ {
		for x := 0; x < width; x++ {
			i.Set(x, y, color.White)
			i.Set(x, height-1-y, color.White)
		}
	}
	for y := blockSize * margin; y < height-blockSize*margin; y++ {
		for x := 0; x < blockSize*margin; x++ {
			i.Set(x, y, color.White)
			i.Set(width-1-x, y, color.White)
		}
	}
	for y, w, h := 0, g.Width(), g.Height(); y < h; y++ {
		for x := 0; x < w; x++ {
			x0 := blockSize * (x + margin)
			y0 := blockSize * (y + margin)
			c := color.White
			if g.Get(x, y) {
				c = color.Black
			}
			for dy := 0; dy < blockSize; dy++ {
				for dx := 0; dx < blockSize; dx++ {
					i.Set(x0+dx, y0+dy, c)
				}
			}
		}
	}
	return i
}
開發者ID:JessonChan,項目名稱:qrencode-go,代碼行數:35,代碼來源:bits.go

示例7: WriteToFile

func (u *UGM) WriteToFile(path string, img image.Image) {
	// create in memory image based on ICM results matrix
	newImg := image.NewGray16(img.Bounds())
	for x := 0; x < u.X(); x++ {
		for y := 0; y < u.Y(); y++ {
			if u.Node(x, y).X() == -1 {
				newImg.SetGray16(x, y, color.Black)
			} else {
				newImg.SetGray16(x, y, color.White)
			}
		}
	}
	// create/overwrite file to write to
	imgFile, err := os.Create(path)
	if err != nil {
		fmt.Printf("%v", err)
		os.Exit(1)
	}
	defer imgFile.Close() // close when exiting..

	// write png to file
	if err := png.Encode(imgFile, newImg); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
開發者ID:paddie,項目名稱:icm,代碼行數:26,代碼來源:icm.go

示例8: EdgesGray16

func EdgesGray16(radius int, img Channel) *image.Gray16 {
	bounds := img.Bounds()
	edgeImage := image.NewGray16(bounds)
	if radius < 1 {
		return edgeImage
	}

	// Compute the horizontal and vertical averages.
	hGA := RowAverageGray16(radius, img)
	vGA := ColumnAverageGray16(radius, img)

	QuickRP(
		AllPointsRP(
			func(pt image.Point) {
				e := float64(hGA.Gray16At(pt.X, pt.Y).Y)
				w := float64(hGA.Gray16At(pt.X-radius+1, pt.Y).Y)
				n := float64(vGA.Gray16At(pt.X, pt.Y).Y)
				s := float64(vGA.Gray16At(pt.X, pt.Y-radius+1).Y)
				edgeImage.Set(pt.X, pt.Y,
					color.Gray16{
						Y: uint16(math.Max(math.Abs(e-w), math.Abs(s-n))), //uint16((math.Abs(e-w) + math.Abs(s-n)) / 2.0),
					},
				)
			},
		),
	)(bounds)

	return edgeImage
}
開發者ID:buth,項目名稱:imageutil,代碼行數:29,代碼來源:filter.go

示例9: BackProjectGray

//BackProjectGray computes back projection of img
// in Gray16 by performing an addition
// of backprojection by line.
// 16Gray avoids white noise.
func BackProjectGray(img image.Gray) (*image.Gray16, error) {
	size := img.Bounds().Size()
	width := size.Y
	nbProj := size.X
	step := 180.0 / float64(nbProj)

	out := image.NewGray16(image.Rect(0, 0, width, width))

	for X := 0; X < nbProj; X++ {
		//Extract a 1D-projection (one row Y of sinogram)
		line := img.SubImage(image.Rect(X, 0, X+1, width)).(*image.Gray)

		// 3- Do the backprojection and rotate accordingly
		wideLine := resize.Resize(uint(width), uint(width), line, resize.Lanczos3).(*image.Gray)

		θ := manipulator.Rad(float64(X)*step) + math.Pi/2
		rotatedWideLine := image.NewGray(image.Rect(0, 0, width, width))
		err := graphics.Rotate(rotatedWideLine, wideLine, &graphics.RotateOptions{Angle: θ})
		if err != nil {
			return out, err
		}

		// 4- Add the rotated backprojection in the output image
		for x := 0; x < width; x++ {
			for y := 0; y < width; y++ {
				point := uint16(out.At(x, y).(color.Gray16).Y) + uint16(rotatedWideLine.At(x, y).(color.Gray).Y)
				out.Set(x, y, color.Gray16{uint16(point)})
			}
		}
	}

	return out, nil
}
開發者ID:verisart,項目名稱:phash,代碼行數:37,代碼來源:radon.go

示例10: createRandomImage

func createRandomImage(maxPaletteSize int) image.Image {
	r := image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{gen.Rand(32) + 1, gen.Rand(32) + 1}}
	var img Image
	switch gen.Rand(10) {
	case 0:
		img = image.NewAlpha(r)
	case 1:
		img = image.NewAlpha16(r)
	case 2:
		img = image.NewCMYK(r)
	case 3:
		img = image.NewGray(r)
	case 4:
		img = image.NewGray16(r)
	case 5:
		img = image.NewNRGBA(r)
	case 6:
		img = image.NewNRGBA64(r)
	case 7:
		img = image.NewPaletted(r, randPalette(maxPaletteSize))
	case 8:
		img = image.NewRGBA(r)
	case 9:
		img = image.NewRGBA64(r)
	default:
		panic("bad")
	}
	fill := gen.Rand(19)
	var palette []color.Color
	if fill == 17 {
		palette = randPalette(maxPaletteSize)
	}
	for y := 0; y < r.Max.Y; y++ {
		for x := 0; x < r.Max.X; x++ {
			switch {
			case fill <= 15:
				img.Set(x, y, color.RGBA64{
					^uint16(0) * uint16((fill>>0)&1),
					^uint16(0) * uint16((fill>>1)&1),
					^uint16(0) * uint16((fill>>2)&1),
					^uint16(0) * uint16((fill>>3)&1),
				})
			case fill == 16:
				img.Set(x, y, randColor())
			case fill == 17:
				img.Set(x, y, palette[gen.Rand(len(palette))])
			case fill == 18:
				if gen.Rand(3) != 0 {
					img.Set(x, y, color.RGBA64{})
				} else {
					img.Set(x, y, randColor())
				}
			default:
				panic("bad")
			}
		}
	}
	return img.(image.Image)
}
開發者ID:sjn1978,項目名稱:go-fuzz,代碼行數:59,代碼來源:main.go

示例11: setup

func setup() {
	w, h := termbox.Size()

	board := image.NewGray16(image.Rect(0, 0, w, h))
	draw.Draw(board, board.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)

	ant = &Ant{X: w / 2, Y: h / 2, W: w, H: h, D: direction, B: board}
}
開發者ID:peterhellberg,項目名稱:langtons-ant,代碼行數:8,代碼來源:main.go

示例12: ConvertToGray16

// ConvertToGray16 returns an *image.Gray16 instance by asserting the given
// ImageReader has that type or, if it does not, using Copy to concurrently
// set the color.Color values of a new *image.Gray16 instance with the same
// bounds.
func ConvertToGray16(src ImageReader) *image.Gray16 {
	if dst, ok := src.(*image.Gray16); ok {
		return dst
	}
	dst := image.NewGray16(src.Bounds())
	Copy(dst, src)
	return dst
}
開發者ID:buth,項目名稱:imageutil,代碼行數:12,代碼來源:imageutil.go

示例13: tToGray16

func tToGray16(m image.Image) *image.Gray16 {
	if p, ok := m.(*image.Gray16); ok {
		return p
	}
	p := image.NewGray16(m.Bounds())
	xdraw.Draw(p, p.Bounds(), m, image.Pt(0, 0), xdraw.Src)
	return p
}
開發者ID:chai2010,項目名稱:bench,代碼行數:8,代碼來源:encode_test.go

示例14: Test_ZeroImg

func Test_ZeroImg(t *testing.T) {
	zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))

	m := Resize(0, 0, zeroImg, NearestNeighbor)
	if m.Bounds() != zeroImg.Bounds() {
		t.Fail()
	}
}
開發者ID:npe9,項目名稱:minimega,代碼行數:8,代碼來源:resize_test.go

示例15: Test_CorrectResize

func Test_CorrectResize(t *testing.T) {
	zeroImg := image.NewGray16(image.Rect(0, 0, 256, 256))

	m := Resize(60, 0, zeroImg, NearestNeighbor)
	if m.Bounds() != image.Rect(0, 0, 60, 60) {
		t.Fail()
	}
}
開發者ID:npe9,項目名稱:minimega,代碼行數:8,代碼來源:resize_test.go


注:本文中的image.NewGray16函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。