当前位置: 首页>>代码示例>>Golang>>正文


Golang rimg64.Multi类代码示例

本文整理汇总了Golang中github.com/jvlmdr/go-cv/rimg64.Multi的典型用法代码示例。如果您正苦于以下问题:Golang Multi类的具体用法?Golang Multi怎么用?Golang Multi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Multi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Apply

func (phi *MaxPool) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	if phi.Field.X <= 0 || phi.Field.Y <= 0 {
		err := fmt.Errorf("invalid field size: %v", phi.Field)
		return nil, err
	}
	if phi.Stride <= 0 {
		err := fmt.Errorf("invalid stride: %d", phi.Stride)
		return nil, err
	}
	size := image.Pt(
		ceilDiv(x.Width-phi.Field.X+1, phi.Stride),
		ceilDiv(x.Height-phi.Field.Y+1, phi.Stride),
	)
	y := rimg64.NewMulti(size.X, size.Y, x.Channels)
	for i := 0; i < y.Width; i++ {
		for j := 0; j < y.Height; j++ {
			for k := 0; k < x.Channels; k++ {
				// Position in original image.
				p := image.Pt(i, j).Mul(phi.Stride)
				max := math.Inf(-1)
				for u := 0; u < phi.Field.X; u++ {
					for v := 0; v < phi.Field.Y; v++ {
						q := p.Add(image.Pt(u, v))
						max = math.Max(max, x.At(q.X, q.Y, k))
					}
				}
				y.Set(i, j, k, max)
			}
		}
	}
	return y, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:32,代码来源:max_pool.go

示例2: copyRealToChannel

// Assumes that f is no smaller than x.
func copyRealToChannel(f *rimg64.Multi, p int, x *fftw.Array2) {
	for u := 0; u < f.Width; u++ {
		for v := 0; v < f.Height; v++ {
			f.Set(u, v, p, real(x.At(u, v)))
		}
	}
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:8,代码来源:util.go

示例3: EvalFunc

// EvalFunc evaluates a function on every window in an image.
// If the input image is M x N and the window size is m x n,
// then the output is (M-m+1) x (N-n+1).
// If the window size is larger than the image size in either dimension,
// a nil image is returned with no error.
func EvalFunc(im *rimg64.Multi, size image.Point, f ScoreFunc) (*rimg64.Image, error) {
	if im.Width < size.X || im.Height < size.Y {
		return nil, nil
	}
	r := rimg64.New(im.Width-size.X+1, im.Height-size.Y+1)
	x := rimg64.NewMulti(size.X, size.Y, im.Channels)
	for i := 0; i < r.Width; i++ {
		for j := 0; j < r.Height; j++ {
			// Copy window into x.
			for u := 0; u < size.X; u++ {
				for v := 0; v < size.Y; v++ {
					for p := 0; p < im.Channels; p++ {
						x.Set(u, v, p, im.At(i+u, j+v, p))
					}
				}
			}
			y, err := f(x)
			if err != nil {
				return nil, err
			}
			r.Set(i, j, y)
		}
	}
	return r, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:30,代码来源:func.go

示例4: Apply

func (phi SumPool) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	if phi.Field.X <= 0 || phi.Field.Y <= 0 {
		err := fmt.Errorf("invalid field size: %v", phi.Field)
		return nil, err
	}
	if phi.Stride <= 0 {
		err := fmt.Errorf("invalid stride: %d", phi.Stride)
		return nil, err
	}
	size := image.Pt(
		ceilDiv(x.Width-phi.Field.X+1, phi.Stride),
		ceilDiv(x.Height-phi.Field.Y+1, phi.Stride),
	)
	y := rimg64.NewMulti(size.X, size.Y, x.Channels)
	for i := 0; i < y.Width; i++ {
		for j := 0; j < y.Height; j++ {
			for k := 0; k < x.Channels; k++ {
				// Position in original image.
				p := image.Pt(i, j).Mul(phi.Stride)
				var t float64
				for u := p.X; u < p.X+phi.Field.X; u++ {
					for v := p.Y; v < p.Y+phi.Field.Y; v++ {
						t += x.At(u, v, k)
					}
				}
				y.Set(i, j, k, t)
			}
		}
	}
	return y, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:31,代码来源:sum_pool.go

示例5: CorrMultiBankStrideBLAS

// CorrMultiBankStrideBLAS computes the strided correlation of
// a multi-channel image with a bank of multi-channel filters.
// 	h_p[u, v] = sum_q (f_q corr g_pq)[stride*u, stride*v]
func CorrMultiBankStrideBLAS(f *rimg64.Multi, g *MultiBank, stride int) (*rimg64.Multi, error) {
	out := ValidSizeStride(f.Size(), g.Size(), stride)
	if out.X <= 0 || out.Y <= 0 {
		return nil, nil
	}
	h := rimg64.NewMulti(out.X, out.Y, len(g.Filters))
	// Size of filters.
	m, n, k := g.Width, g.Height, g.Channels
	// Express as dense matrix multiplication.
	//   h_p[u, v] = sum_q (f_q corr g_pq)[u, v]
	//   h = A(f) X(g)
	// where A is whk by mnk
	// with w = ceil[(M-m+1)/stride],
	//      h = ceil[(N-n+1)/stride].
	a := blas.NewMat(h.Width*h.Height, m*n*k)
	{
		var r int
		for u := 0; u < h.Width; u++ {
			for v := 0; v < h.Height; v++ {
				var s int
				for i := 0; i < g.Width; i++ {
					for j := 0; j < g.Height; j++ {
						for q := 0; q < g.Channels; q++ {
							a.Set(r, s, f.At(stride*u+i, stride*v+j, q))
							s++
						}
					}
				}
				r++
			}
		}
	}
	x := blas.NewMat(m*n*k, h.Channels)
	{
		var r int
		for i := 0; i < g.Width; i++ {
			for j := 0; j < g.Height; j++ {
				for q := 0; q < g.Channels; q++ {
					for p := 0; p < h.Channels; p++ {
						x.Set(r, p, g.Filters[p].At(i, j, q))
					}
					r++
				}
			}
		}
	}
	y := blas.MatMul(1, a, x)
	{
		var r int
		for u := 0; u < h.Width; u++ {
			for v := 0; v < h.Height; v++ {
				for p := 0; p < h.Channels; p++ {
					h.Set(u, v, p, y.At(r, p))
				}
				r++
			}
		}
	}
	return h, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:63,代码来源:multi_bank_stride.go

示例6: CorrMultiStrideFFT

// CorrMultiStrideFFT computes the correlation of
// a multi-channel image with a multi-channel filter.
// 	h[u, v] = sum_q (f_q corr g_q)[u, v]
func CorrMultiStrideFFT(f, g *rimg64.Multi, stride int) (*rimg64.Image, error) {
	if err := errIfChannelsNotEq(f, g); err != nil {
		panic(err)
	}
	out := ValidSizeStride(f.Size(), g.Size(), stride)
	if out.X <= 0 || out.Y <= 0 {
		return nil, nil
	}
	// Compute strided convolution as the sum over
	// a stride x stride grid of small convolutions.
	grid := image.Pt(stride, stride)
	// But do not divide into a larger grid than the size of the filter.
	// If the filter is smaller than the stride,
	// then some pixels in the image will not affect the output.
	grid.X = min(grid.X, g.Width)
	grid.Y = min(grid.Y, g.Height)
	// Determine the size of the sub-sampled filter.
	gsub := image.Pt(ceilDiv(g.Width, grid.X), ceilDiv(g.Height, grid.Y))
	// The sub-sampled size of the image should be such that
	// the output size is attained.
	fsub := image.Pt(out.X+gsub.X-1, out.Y+gsub.Y-1)

	// Determine optimal size for FFT.
	work, _ := FFT2Size(fsub)
	// Cache FFT of each channel of image for convolving with multiple filters.
	// Re-use plan for multiple convolutions too.
	fhat := fftw.NewArray2(work.X, work.Y)
	ffwd := fftw.NewPlan2(fhat, fhat, fftw.Forward, fftw.Estimate)
	defer ffwd.Destroy()
	ghat := fftw.NewArray2(work.X, work.Y)
	gfwd := fftw.NewPlan2(ghat, ghat, fftw.Forward, fftw.Estimate)
	defer gfwd.Destroy()
	// Normalization factor.
	alpha := complex(1/float64(work.X*work.Y), 0)
	// Add the convolutions over channels and strides.
	hhat := fftw.NewArray2(work.X, work.Y)
	for k := 0; k < f.Channels; k++ {
		for i := 0; i < grid.X; i++ {
			for j := 0; j < grid.Y; j++ {
				// Copy each downsampled channel and take its transform.
				copyChannelStrideTo(fhat, f, k, stride, image.Pt(i, j))
				ffwd.Execute()
				copyChannelStrideTo(ghat, g, k, stride, image.Pt(i, j))
				gfwd.Execute()
				addMul(hhat, ghat, fhat)
			}
		}
	}
	// Take the inverse transform.
	h := rimg64.New(out.X, out.Y)
	scale(alpha, hhat)
	fftw.IFFT2To(hhat, hhat)
	copyRealTo(h, hhat)
	return h, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:58,代码来源:multi_stride.go

示例7: FlipMulti

// FlipMulti mirrors a multi-channel image in x and y.
func FlipMulti(f *rimg64.Multi) *rimg64.Multi {
	g := rimg64.NewMulti(f.Width, f.Height, f.Channels)
	for i := 0; i < f.Width; i++ {
		for j := 0; j < f.Height; j++ {
			for k := 0; k < f.Channels; k++ {
				g.Set(f.Width-1-i, f.Height-1-j, k, f.At(i, j, k))
			}
		}
	}
	return g
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:12,代码来源:flip.go

示例8: Apply

func (phi *Scale) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	y := rimg64.NewMulti(x.Width, x.Height, x.Channels)
	for u := 0; u < x.Width; u++ {
		for v := 0; v < x.Height; v++ {
			for p := 0; p < x.Channels; p++ {
				y.Set(u, v, p, float64(*phi)*x.At(u, v, p))
			}
		}
	}
	return y, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:11,代码来源:conv.go

示例9: squareMulti

// Takes the sum over channels.
func squareMulti(f *rimg64.Multi) *rimg64.Image {
	g := rimg64.New(f.Width, f.Height)
	for i := 0; i < f.Width; i++ {
		for j := 0; j < f.Height; j++ {
			for k := 0; k < f.Channels; k++ {
				g.Set(i, j, g.At(i, j)+sqr(f.At(i, j, k)))
			}
		}
	}
	return g
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:12,代码来源:cos.go

示例10: Apply

func (phi *SelectChannels) Apply(f *rimg64.Multi) (*rimg64.Multi, error) {
	g := rimg64.NewMulti(f.Width, f.Height, len(phi.Set))
	for u := 0; u < f.Width; u++ {
		for v := 0; v < f.Height; v++ {
			for i, p := range phi.Set {
				g.Set(u, v, i, f.At(u, v, p))
			}
		}
	}
	return g, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:11,代码来源:subset.go

示例11: dot

func dot(x, y *rimg64.Multi) float64 {
	var d float64
	for i := 0; i < x.Width; i++ {
		for j := 0; j < x.Height; j++ {
			for k := 0; k < x.Channels; k++ {
				d += x.At(i, j, k) * y.At(i, j, k)
			}
		}
	}
	return d
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:11,代码来源:main.go

示例12: Apply

func (phi *PosPart) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	y := rimg64.NewMulti(x.Width, x.Height, x.Channels)
	for i := 0; i < x.Width; i++ {
		for j := 0; j < x.Height; j++ {
			for k := 0; k < x.Channels; k++ {
				y.Set(i, j, k, math.Max(0, x.At(i, j, k)))
			}
		}
	}
	return y, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:11,代码来源:nonlin.go

示例13: DecimateMulti

// DecimateMulti takes every r-th sample starting at (0, 0).
func DecimateMulti(f *rimg64.Multi, r int) *rimg64.Multi {
	out := ceilDivPt(f.Size(), r)
	g := rimg64.NewMulti(out.X, out.Y, f.Channels)
	for i := 0; i < g.Width; i++ {
		for j := 0; j < g.Height; j++ {
			for k := 0; k < g.Channels; k++ {
				g.Set(i, j, k, f.At(r*i, r*j, k))
			}
		}
	}
	return g
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:13,代码来源:dec.go

示例14: copyChannelTo

// Assumes that f is no smaller than x.
// Pads with zeros.
func copyChannelTo(x *fftw.Array2, f *rimg64.Multi, p int) {
	w, h := x.Dims()
	for u := 0; u < w; u++ {
		for v := 0; v < h; v++ {
			if u < f.Width && v < f.Height {
				x.Set(u, v, complex(f.At(u, v, p), 0))
			} else {
				x.Set(u, v, 0)
			}
		}
	}
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:14,代码来源:util.go

示例15: Apply

func (phi *AdjChanNorm) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
	y := rimg64.NewMulti(x.Width, x.Height, x.Channels)
	r := (phi.Num - 1) / 2
	for i := 0; i < x.Width; i++ {
		for j := 0; j < x.Height; j++ {
			k := 0
			// Range over which to compute sum.
			a, b := k-r, k+r+1
			// Take sum excluding leading element.
			var t float64
			for p := 0; p < min(b, x.Channels); p++ {
				t += sqr(x.At(i, j, p))
			}
			for ; k < x.Channels; k++ {
				a, b = k-r, k+r+1
				// Set element.
				norm := math.Pow(phi.K+phi.Alpha*t, phi.Beta)
				y.Set(i, j, k, x.At(i, j, k)/norm)
				// Subtract trailing element.
				if a >= 0 {
					t -= sqr(x.At(i, j, a))
				}
				// Add leading element.
				if b < x.Channels {
					t += sqr(x.At(i, j, b))
				}
			}
		}
	}
	return y, nil
}
开发者ID:jvlmdr,项目名称:go-cv,代码行数:31,代码来源:norm.go


注:本文中的github.com/jvlmdr/go-cv/rimg64.Multi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。