GithubHelp home page GithubHelp logo

Comments (6)

chenli199 avatar chenli199 commented on July 4, 2024

截屏2022-07-26 11 44 18
截屏2022-07-26 11 44 39

from dcls-sr.

Algolzw avatar Algolzw commented on July 4, 2024

@chenli199

  • 在我们代码里因为是对每个通道单独做的,所以2或3维应该都可以。

  • 我也没有转到过新版本的rfft实验过代码,不过ifft2出来的应该是复数,不知道你取实部没有(deblur_f.real)。具体的转化我可能要花点时间测一下。

from dcls-sr.

RC-Qiao avatar RC-Qiao commented on July 4, 2024

请问这个问题解决了么, 我想用3090的跑但pytorch新版本的rfft和旧版有问题

from dcls-sr.

LeoChen12 avatar LeoChen12 commented on July 4, 2024

您好 请问这个rfft的版本问题解决了吗 新旧版本无法匹配

from dcls-sr.

Algolzw avatar Algolzw commented on July 4, 2024

@LeoChen12 @hdcxqrc 可以尝试以下代码

def normkernel_to_downkernel(rescaled_blur_hr, rescaled_hr, ksize, eps=1e-10):
    blur_img = torch.fft.fftn(rescaled_blur_hr, dim=(-3, -2, -1))
    blur_img = torch.stack((blur_img.real, blur_img.imag), -1)
    img = torch.fft.fftn(rescaled_hr, dim=(-3, -2, -1))
    img = torch.stack((img.real, img.imag), -1)

    denominator = img[:, :, :, :, 0] * img[:, :, :, :, 0] \
                  + img[:, :, :, :, 1] * img[:, :, :, :, 1] + eps

    inv_denominator = torch.zeros_like(img)
    inv_denominator[:, :, :, :, 0] = img[:, :, :, :, 0] / denominator
    inv_denominator[:, :, :, :, 1] = -img[:, :, :, :, 1] / denominator

    kernel = torch.zeros_like(blur_img).cuda()
    kernel[:, :, :, :, 0] = inv_denominator[:, :, :, :, 0] * blur_img[:, :, :, :, 0] \
                            - inv_denominator[:, :, :, :, 1] * blur_img[:, :, :, :, 1]
    kernel[:, :, :, :, 1] = inv_denominator[:, :, :, :, 0] * blur_img[:, :, :, :, 1] \
                            + inv_denominator[:, :, :, :, 1] * blur_img[:, :, :, :, 0]
    ker = convert_otf2psf(kernel, ksize)
    return ker

def convert_otf2psf(otf, size):
    ker = torch.zeros(size)
    psf = torch.fft.ifft2(torch.complex(otf[..., 0], otf[..., 1]), dim=(-3, -2, -1))
    # circularly shift
    ksize = size[-1]
    centre = ksize//2 + 1

    ker[:, :, (centre-1):, (centre-1):] = psf[:, :, :centre, :centre]#.mean(dim=1, keepdim=True)
    ker[:, :, (centre-1):, :(centre-1)] = psf[:, :, :centre, -(centre-1):]#.mean(dim=1, keepdim=True)
    ker[:, :, :(centre-1), (centre-1):] = psf[:, :, -(centre-1):, :centre]#.mean(dim=1, keepdim=True)
    ker[:, :, :(centre-1), :(centre-1)] = psf[:, :, -(centre-1):, -(centre-1):]#.mean(dim=1, keepdim=True)

    return ker

from dcls-sr.

LeoChen12 avatar LeoChen12 commented on July 4, 2024

感谢您的帮助!

from dcls-sr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.