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


Golang Gray.At方法代碼示例

本文整理匯總了Golang中image.Gray.At方法的典型用法代碼示例。如果您正苦於以下問題:Golang Gray.At方法的具體用法?Golang Gray.At怎麽用?Golang Gray.At使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在image.Gray的用法示例。


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

示例1: Contrast

func Contrast(picture *image.Gray, contrast uint8) *image.Gray {
	bounds := picture.Bounds()
	newPic := image.NewGray(bounds)
	average := getAverage(picture)
	for x := 0; x < bounds.Dx(); x++ {
		for y := 0; y < bounds.Dy(); y++ {
			pixel := picture.At(x, y).(color.Gray).Y
			if pixel > average {
				if pixel+contrast < pixel {
					pixel = 0xff
				} else {
					pixel += contrast
				}
			} else if pixel < average {
				if pixel-contrast > pixel {
					pixel = 0x00
				} else {
					pixel -= contrast
				}
			}
			newPic.Set(x, y, color.Gray{pixel})
		}
	}
	return newPic
}
開發者ID:bjh83,項目名稱:makeascii,代碼行數:25,代碼來源:contrastor.go

示例2: valueAt

func valueAt(img *image.Gray, x, y float32) float32 {
	dx, dy := x/float32(screenWidth), y/float32(screenHeight)
	b := img.Bounds().Max
	px, py := int(dx*float32(b.X)), int(dy*float32(b.Y))
	v := float32(img.At(px, py).(color.Gray).Y) / 255
	return v
}
開發者ID:mfpi,項目名稱:lecture-hall-games,代碼行數:7,代碼來源:racer.go

示例3: getAverage

func getAverage(picture *image.Gray) uint8 {
	var sum uint64 = 0
	bounds := picture.Bounds()
	for x := 0; x < bounds.Dx(); x++ {
		for y := 0; y < bounds.Dy(); y++ {
			sum += uint64(picture.At(x, y).(color.Gray).Y)
		}
	}
	return uint8(sum / uint64(bounds.Dx()*bounds.Dy()))
}
開發者ID:bjh83,項目名稱:makeascii,代碼行數:10,代碼來源:contrastor.go

示例4: GrayImageToMatrix

func GrayImageToMatrix(src image.Gray) (*matrix.Dense, error) {
	bounds := src.Bounds()
	mtx := make([][]float64, bounds.Max.X)
	for x := 0; x < bounds.Max.X; x++ {
		mtx[x] = make([]float64, bounds.Max.Y)
		for y := 0; y < bounds.Max.Y; y++ {
			_, _, b, _ := src.At(x, y).RGBA()
			mtx[x][y] = float64(b)
		}
	}
	return matrix.NewDense(mtx)
}
開發者ID:postfix,項目名稱:phash-1,代碼行數:12,代碼來源:transformer.go

示例5: GrayImageToMatrix

func GrayImageToMatrix(src image.Gray) (*mat64.Dense, error) {
	bounds := src.Bounds()
	rows := bounds.Max.Y
	cols := bounds.Max.X

	mtx := make([]float64, rows*cols)
	for x := 0; x < cols; x++ {
		for y := 0; y < rows; y++ {
			_, _, b, _ := src.At(x, y).RGBA()
			mtx[y*cols+x] = float64(b)
		}
	}
	return mat64.NewDense(rows, cols, mtx), nil
}
開發者ID:verisart,項目名稱:phash,代碼行數:14,代碼來源:transformer.go

示例6: deviation

func (entity *Entity) deviation(model *image.Gray) float64 {
	deviation := 0.0
	actual := entity.render()

	for x := 0; x < entity.width; x++ {
		for y := 0; y < entity.height; y++ {
			actualColor := float64(actual.At(x, y).(color.Gray).Y)
			modelColor := float64(model.At(x, y).(color.Gray).Y)
			dev := actualColor - modelColor
			deviation += dev * dev
		}
	}

	return deviation
}
開發者ID:BranLwyd,項目名稱:misc,代碼行數:15,代碼來源:imgcube.go

示例7: dctPoint

func dctPoint(img image.Gray, u, v, N, M int) float64 {
	sum := 0.0
	for i := 0; i < N; i++ {
		for j := 0; j < M; j++ {
			_, _, b, _ := img.At(i, j).RGBA()
			// sum += math.Cos( ( float64(2*i+1)/float64(2*N) ) * float64( u ) * math.Pi ) *
			//        math.Cos( ( float64(2*j+1)/float64(2*M) ) * float64( v ) * math.Pi ) *
			//        float64(b)

			sum += math.Cos(math.Pi/(float64(N))*(float64(i)+1/2)*float64(u)) *
				math.Cos(math.Pi/(float64(M))*(float64(j)+1/2)*float64(v)) *
				float64(b)
		}
	}
	return sum * ((coefficient(u) * coefficient(v)) / 4.0)
}
開發者ID:verisart,項目名稱:phash,代碼行數:16,代碼來源:dct.go

示例8: average

func average(oldPic *image.Gray) *Picture {
	bounds := oldPic.Bounds()
	newWidth := charWidth * (bounds.Dx() / charWidth)
	newHeight := charHeight * (bounds.Dy() / charHeight)
	newPic := New(newWidth/charWidth, newHeight/charHeight)
	for x := 0; x < newWidth-charWidth; x += charWidth {
		for y := 0; y < newHeight-charHeight; y += charHeight {
			sum := 0
			for i := x; i < x+charWidth; i++ {
				for j := y; j < y+charHeight; j++ {
					sum += int(oldPic.At(i, j).(color.Gray).Y)
				}
			}
			newPic.Set(x/charWidth, y/charHeight, uint8(sum/(charWidth*charHeight)))
		}
	}
	return newPic
}
開發者ID:bjh83,項目名稱:makeascii,代碼行數:18,代碼來源:grayscaler.go

示例9: kf3

// kf3 is a generic convolution 3x3 kernel filter that operatates on
// images of type image.Gray from the Go standard image library.
func kf3(k *[9]float64, src, dst *image.Gray) {
	for y := src.Rect.Min.Y; y < src.Rect.Max.Y; y++ {
		for x := src.Rect.Min.X; x < src.Rect.Max.X; x++ {
			var sum float64
			var i int
			for yo := y - 1; yo <= y+1; yo++ {
				for xo := x - 1; xo <= x+1; xo++ {
					if (image.Point{xo, yo}).In(src.Rect) {
						sum += k[i] * float64(src.At(xo, yo).(color.Gray).Y)
					} else {
						sum += k[i] * float64(src.At(x, y).(color.Gray).Y)
					}
					i++
				}
			}
			dst.SetGray(x, y,
				color.Gray{uint8(math.Min(255, math.Max(0, sum)))})
		}
	}
}
開發者ID:travis1230,項目名稱:RosettaCodeData,代碼行數:22,代碼來源:image-convolution-1.go

示例10: addPixelsToGray

func addPixelsToGray(src image.Image, sx, sy int, dst image.Gray, dx, dy int) {
	clr := src.At(sx, sy)
	greyColor, _ := color.GrayModel.Convert(clr).(color.Gray)
	dst.Set(dx, dy, color.Gray{dst.At(dx, dy).(color.Gray).Y + greyColor.Y})
}
開發者ID:verisart,項目名稱:phash,代碼行數:5,代碼來源:radon.go


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