Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose rescale_rfft functions #4

Closed
alisterburt opened this issue Jul 11, 2024 · 0 comments · Fixed by #5
Closed

expose rescale_rfft functions #4

alisterburt opened this issue Jul 11, 2024 · 0 comments · Fixed by #5

Comments

@alisterburt
Copy link
Member

over at teamtomo/membrain-seg#76 @LorenzLamm and @JoelVO like torch-fourier-rescale but wants to reweight frequencies prior to fourier pad/crop

We should expose the lower level, currently private _rescale_rfft_2d/3d functions

docs will be required for people to use this well - example below can serve as a template

proposed API:

import torch
import torch.fft
from torch_fourier_rescale import fourier_rescale_rfft_3d
from my_package import reweight

volume = torch.rand((32, 32, 32))

# fftshift so that origin of phases in DFT is in the center of the image
# this maintains the center of the image at the position of DC component pre/post rescaling
volume = torch.fft.fftshift(volume, dim=(-3, -2, -1))
dft = torch.fft.rfftn(image, dim=(-3, -2, -1))
dft = torch.fft.fftshift(dft, dim=(-3, -2))

# do the reweighting
dft = reweight(dft)
dft = rescale_rfft_3d(dft)

# transform back to real space and recenter
dft = torch.fft.ifftshift(dft, dim=(-3, -2))
rescaled_volume = torch.fft.irfftn(dft, dim=(-3, -2, -1))
rescaled_volume = torch.fft.ifftshift(rescaled_image, dim=(-3, -2, -1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant