Gtiff
This commit is contained in:
@@ -20,7 +20,7 @@ type Block struct {
|
||||
coord image.Point // top-left corner of the block in the original image
|
||||
}
|
||||
|
||||
func (r *Registrator) processBlock(panBlock, mssBlock gocv.Mat) (gocv.Mat, gocv.Point2f) {
|
||||
func (r *Registrator) calculateBlockPhaseShift(panBlock, mssBlock gocv.Mat) gocv.Point2f {
|
||||
pan := gocv.NewMat()
|
||||
mss := gocv.NewMat()
|
||||
|
||||
@@ -30,37 +30,15 @@ func (r *Registrator) processBlock(panBlock, mssBlock gocv.Mat) (gocv.Mat, gocv.
|
||||
defer mss.Close()
|
||||
|
||||
hann := gocv.NewMat()
|
||||
defer hann.Close()
|
||||
|
||||
shift, response := gocv.PhaseCorrelate(pan, mss, hann)
|
||||
hann.Close()
|
||||
|
||||
dx := shift.X
|
||||
dy := shift.Y
|
||||
log.Printf("Block shift: dx = %f, dy = %f. response = %f \n", dx, dy, response)
|
||||
|
||||
if math.IsNaN(float64(dx)) {
|
||||
dx = 0.0
|
||||
}
|
||||
|
||||
if math.IsNaN(float64(dy)) {
|
||||
dy = 0.0
|
||||
}
|
||||
|
||||
// cv::Mat translationMatrix = (cv::Mat_<double>(2, 3) << 1, 0, shift.x, 0, 1, shift.y);
|
||||
translationMat := gocv.NewMatWithSize(2, 3, gocv.MatTypeCV32F)
|
||||
translationMat.SetFloatAt(0, 0, 1)
|
||||
translationMat.SetFloatAt(0, 1, 0)
|
||||
translationMat.SetFloatAt(0, 2, dx)
|
||||
translationMat.SetFloatAt(1, 0, 0)
|
||||
translationMat.SetFloatAt(1, 1, 1)
|
||||
translationMat.SetFloatAt(1, 2, dy)
|
||||
defer translationMat.Close()
|
||||
|
||||
alignedBlock := gocv.NewMat()
|
||||
gocv.WarpAffine(mss, &alignedBlock, translationMat, image.Pt(mss.Size()[1], mss.Size()[0]))
|
||||
|
||||
alignedBlock.ConvertTo(&alignedBlock, gocv.MatTypeCV16U)
|
||||
|
||||
return alignedBlock, shift
|
||||
return shift
|
||||
}
|
||||
|
||||
func (r *Registrator) DoMssPhaseShift() ([][]byte, error) {
|
||||
@@ -82,6 +60,8 @@ func (r *Registrator) DoMssPhaseShift() ([][]byte, error) {
|
||||
log.Println("Band", band+1, "average shift:", dx, dy, "efficientShiftM:", efficientShiftM)
|
||||
|
||||
translationMat := gocv.NewMatWithSize(2, 3, gocv.MatTypeCV32F)
|
||||
defer translationMat.Close()
|
||||
|
||||
translationMat.SetFloatAt(0, 0, 1)
|
||||
translationMat.SetFloatAt(0, 1, 0)
|
||||
translationMat.SetFloatAt(0, 2, dx)
|
||||
@@ -90,7 +70,11 @@ func (r *Registrator) DoMssPhaseShift() ([][]byte, error) {
|
||||
translationMat.SetFloatAt(1, 2, dy)
|
||||
|
||||
alignedMss := gocv.NewMatWithSize(r.MssHeight, r.MssWidth, gocv.MatTypeCV32FC1)
|
||||
defer alignedMss.Close()
|
||||
|
||||
cvtMss := gocv.NewMat()
|
||||
defer cvtMss.Close()
|
||||
|
||||
r.MssImages[band].ConvertTo(&cvtMss, gocv.MatTypeCV32FC1)
|
||||
// 手动平移像素
|
||||
outY := math.MaxInt
|
||||
@@ -115,12 +99,12 @@ func (r *Registrator) DoMssPhaseShift() ([][]byte, error) {
|
||||
}
|
||||
|
||||
// gocv.WarpAffine(cvtMss, &alignedMss, translationMat, image.Pt(cvtMss.Size()[1], cvtMss.Size()[0]))
|
||||
alignedMss.ConvertTo(&alignedMss, gocv.MatTypeCV16U)
|
||||
alignedMssData[band] = append(alignedMssData[band], alignedMss.ToBytes()...)
|
||||
r.registeredMssImages[band] = gocv.NewMat()
|
||||
alignedMss.ConvertTo(&r.registeredMssImages[band], gocv.MatTypeCV16U)
|
||||
|
||||
translationMat.Close()
|
||||
cvtMss.Close()
|
||||
alignedMss.Close()
|
||||
log.Println("Band", band+1, "registeredMssImages size:", r.registeredMssImages[band].Size())
|
||||
|
||||
alignedMssData[band] = append(alignedMssData[band], r.registeredMssImages[band].ToBytes()...)
|
||||
}
|
||||
|
||||
return alignedMssData, nil
|
||||
|
||||
Reference in New Issue
Block a user