亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Golang 中使用 Lanczos 重采樣的粗糙邊緣

在 Golang 中使用 Lanczos 重采樣的粗糙邊緣

Go
墨色風雨 2022-03-02 13:08:40
在 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 給我的結果幾乎相同。


查看完整回答
反對 回復 2022-03-02
  • 1 回答
  • 0 關注
  • 268 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號