DFT 带阻滤波器

This commit is contained in:
nuknal
2024-06-21 12:47:14 +08:00
parent e13038474a
commit d99b8a9740
16 changed files with 292 additions and 309 deletions

21
pkg/utils/memory.go Normal file
View File

@@ -0,0 +1,21 @@
package utils
import (
"log"
"runtime"
"github.com/dustin/go-humanize"
)
var lastTotalFreed uint64
func PrintMemStats() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
log.Printf("[Memory] Alloc = %v TotalAlloc=%v Just Freed = %v Sys = %v NumGc=%v",
humanize.Bytes(m.Alloc),
humanize.Bytes(m.TotalAlloc),
humanize.Bytes(((m.TotalAlloc - m.Alloc) - lastTotalFreed)),
humanize.Bytes(m.Sys), m.NumGC)
lastTotalFreed = m.TotalAlloc - m.Alloc
}

View File

@@ -47,7 +47,64 @@ func SavePanToGDALGTiff(pan gocv.Mat, topLeftX, topLeftY float64, tiffFile strin
return err
}
log.Info("Saved pan image to ", tiffFile)
log.Info("Saved image to ", tiffFile)
return nil
}
func SaveBGRToGDALGTiff(bgr gocv.Mat,
bands int,
topLeftX, topLeftY float64,
resolution float64,
colorInterps []godal.ColorInterp, tiffFile string) error {
width := bgr.Cols()
height := bgr.Rows()
// 创建一个二维切片来存储图像数据
data := make([][]uint16, bands)
for i := range data {
data[i] = make([]uint16, width*height)
}
// 从gocv.Mat中提取数据
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
for b := 0; b < bands; b++ {
data[b][y*width+x] = uint16(bgr.GetShortAt(y, x*bands+b))
}
}
}
ds, err := godal.Create(godal.GTiff,
tiffFile,
bands,
godal.UInt16,
width, height)
if err != nil {
log.Error("Error creating TIFF file: ", err)
return err
}
defer ds.Close()
// ds.SetMetadata("NBITS", "16")
setGeoTransform(ds, topLeftX, topLeftY, resolution)
for b := 0; b < bands; b++ {
band := ds.Bands()[b]
band.SetColorInterp(colorInterps[b])
err := band.IO(godal.IOWrite,
0, 0,
data[b],
width, height,
godal.PixelSpacing(2),
godal.LineSpacing(width*2))
if err != nil {
log.Error("Failed to write data to band:", err)
return err
}
}
log.Info("Saved BGR MSS to ", tiffFile)
return nil
}