在 Golang 中使用 Lanczos 重采樣的粗糙邊緣11我一直在寫一些在 Golang 中調整圖像大小的基本方法。我看過幾篇關于調整圖像大小的帖子,但對于我的生活,我無法弄清楚我錯過了什么......本質上,我的問題是在 Golang 中調整圖像大小時,我的結果似乎有很多鋸齒。我已經嘗試迭代地對圖像進行下采樣,但這并沒有帶來太大的改進。這是我的代碼:func resize(original image.Image, edgeSize int, filterSize int) image.Image { oldBounds := original.Bounds() if oldBounds.Dx() < edgeSize && oldBounds.Dy() < edgeSize { // No resize necessary return original } threshold := edgeSize * 4 / 3 if oldBounds.Dx() > threshold || oldBounds.Dy() > threshold { fmt.Println("Upstream") original = customResizeImageToFitBounds(original, threshold, filterSize) oldBounds = original.Bounds() } newBounds := getNewBounds(oldBounds, edgeSize) resized := image.NewRGBA(newBounds) var ratioX = float64(oldBounds.Dx()) / float64(newBounds.Dx()) var ratioY = float64(oldBounds.Dy()) / float64(newBounds.Dy()) for x := 0; x < newBounds.Dx(); x++ { for y := 0; y < newBounds.Dy(); y++ { sourceX := ratioX * float64(x) minX := int(math.Floor(sourceX)) sourceY := ratioY * float64(y) minY := int(math.Floor(sourceY)) sampleSize := filterSize<<1 + 1 var xCoeffs = make([]float64, sampleSize) var yCoeffs = make([]float64, sampleSize) var sumX = 0.0 var sumY = 0.0 for i := 0; i < sampleSize; i++ { xCoeffs[i] = lanczos(filterSize, sourceX-float64(minX+i-filterSize)) yCoeffs[i] = lanczos(filterSize, sourceY-float64(minY+i-filterSize)) sumX += xCoeffs[i] sumY += yCoeffs[i] } for i := 0; i < sampleSize; i++ { xCoeffs[i] /= sumX yCoeffs[i] /= sumY }能不是特別好,因為我想在查看優化之前獲得高質量的結果。有圖像重采樣經驗的人有沒有看到任何潛在的問題?
1 回答

jeck貓
TA貢獻1909條經驗 獲得超7個贊
好吧,我想我找到了一種解決混疊問題的方法。我沒有使用 lanczos3,而是使用雙線性插值對源圖像重新采樣,其尺寸略高于我想要的尺寸(edgeSize = 1080),高斯模糊圖像,然后將圖像縮小到目標尺寸(edgeSize = 600) ,這次是雙三次插值。這給我的結果與 RMagick 給我的結果幾乎相同。
- 1 回答
- 0 關注
- 268 瀏覽
添加回答
舉報
0/150
提交
取消