Files
sjy01-image-proc/pkg/producer/edge_phase_correlation.go
2024-11-01 09:19:42 +08:00

42 lines
1.3 KiB
Go

package producer
import (
"gocv.io/x/gocv"
)
// https://medium.com/radix-ai-blog/banishing-the-jitters-stabilizing-satellite-imagery-with-opencvs-phase-correlation-3ba2dc6ac096
// tackle the brightness and contrast problem
// by performing phase correlation on detected
// edges instead of the raw image
// SKIP: 多光谱各个波段的边缘检测结果不佳
func CV_Canny(img0 gocv.Mat) gocv.Mat {
dst8 := gocv.NewMatWithSize(img0.Rows(), img0.Cols(), gocv.MatTypeCV8U)
defer dst8.Close()
gocv.Normalize(img0, &dst8, 0, 255, gocv.NormMinMax)
dst8.ConvertTo(&dst8, gocv.MatTypeCV8U)
dstEdge := gocv.NewMat()
gocv.Canny(dst8, &dstEdge, 10, 100)
dstEdge.ConvertTo(&dstEdge, img0.Type())
return dstEdge
}
func CV_Sobel(img0 gocv.Mat) gocv.Mat {
matType := img0.Type()
// x 方向
sobelX := gocv.NewMat()
gocv.Sobel(img0, &sobelX, gocv.MatTypeCV32FC1, 1, 0, 5, 1.5, 0, gocv.BorderDefault)
sobelX.ConvertTo(&sobelX, matType)
// y 方向
sobelY := gocv.NewMat()
gocv.Sobel(img0, &sobelY, gocv.MatTypeCV32FC1, 0, 1, 5, 1.5, 0, gocv.BorderIsolated)
sobelY.ConvertTo(&sobelY, matType)
// 合并
sobelXY := gocv.NewMat()
gocv.Sobel(img0, &sobelXY, gocv.MatTypeCV32FC1, 1, 1, 5, 1.5, 0, gocv.BorderDefault)
sobelXY.ConvertTo(&sobelXY, matType)
return sobelY
}