代码拉取完成,页面将自动刷新
package triangle
import (
"image"
"math/rand"
"time"
)
// GetPoints retrieves the triangle points after the Sobel threshold has been applied.
func (p *Processor) GetPoints(img *image.NRGBA, threshold, maxPoints int) []Point {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
width, height := img.Bounds().Dx(), img.Bounds().Dy()
var (
sum, total uint8
x, y, sx, sy int
row, col, step int
points []Point
dpoints []Point
)
for y = 0; y < height; y++ {
for x = 0; x < width; x++ {
sum, total = 0, 0
for row = -1; row <= 1; row++ {
sy = y + row
step = sy * width
if sy >= 0 && sy < height {
for col = -1; col <= 1; col++ {
sx = x + col
if sx >= 0 && sx < width {
sum += img.Pix[(sx+step)<<2]
total++
}
}
}
}
if total > 0 {
sum /= total
}
if sum > uint8(threshold) {
points = append(points, Point{X: float64(x), Y: float64(y)})
}
}
}
ilen := len(points)
limit := int(float64(ilen) * p.PointRate)
if limit > maxPoints {
limit = maxPoints
}
for i := 0; i < limit && i < ilen; i++ {
j := int(float64(ilen) * r.Float64())
dpoints = append(dpoints, points[j])
}
return dpoints
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。