本文整理匯總了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
}
示例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
}
示例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()))
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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)))})
}
}
}
示例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})
}