磁共振图像处理中 fft1c 和 ifft1c 函数的 Python 实现

fft1cifft1c 是 MRI 图像处理的常用函数。通常使用如下的 Matlab 实现 (Michael Lustig,2005)

matlab 复制代码
function res = ifft1c(x,dim)

% res = fft1c(x)
% 
% orthonormal forward 1D FFT
%


n=size(x,dim);
shft=zeros(1,5);
shft(dim)=ceil(n/2);

x=circshift(x,shft);

fx=ifft(x,[],dim);

fx=circshift(fx,shft);

res = sqrt(n)*fx;

function res = fft1c(x,dim)

% res = fft1c(x,dim)
% 
% orthonormal forward 1D FFT
%
% (c) Michael Lustig 2005

n=size(x,dim);
shft=zeros(1,4);
shft(dim)=-ceil(n/2);

x=circshift(x,shft);

fx=fft(x,[],dim);

fx=circshift(fx,shft);

res = 1/sqrt(n)*fx;

但笔者在尝试将一个需要使用 ifft1c 函数移植到 Python 中时发现,无论是现有库还是其他现有开源代码很少有 ifft1c 的 Python 实现,Github 中少数的几个实现也和 Matlab 版不同,这给 debug 带来了不便。因此此处给出笔者的 ifft1c Python 版实现,与 Matlab 版最大程度的保持了一致

ifft1c

py 复制代码
import numpy as np
import math
import scipy


def iff1c(x, dim):
    n = np.size(x, dim)

    shft = np.zeros(5, dtype=int)

    shft[dim] = math.ceil(n / 2)

    shft = tuple(shft)

    x = np.roll(x, shift=shft, axis=dim)  # how to deal with more than 2?

    fx = scipy.fft.ifft(x, axis=dim)

    fx = np.roll(fx, shft, axis=dim)

    return math.sqrt(n) * fx

fft1c

py 复制代码
import numpy as np
import math
import scipy


def ff1c(x, dim):
    n = np.size(x, dim)

    shft = np.zeros(4, dtype=int)

    shft[dim] = -math.ceil(n / 2)

    shft = tuple(shft)

    x = np.roll(x, shift=shft, axis=dim)  # how to deal with more than 2?

    fx = scipy.fft.fft(x, axis=dim)

    fx = np.roll(fx, shft, axis=dim)

    return math.sqrt(n) * fx
相关推荐
Christo32 分钟前
TKDE-2026《Efficient Co-Clustering via Bipartite Graph Factorization》
人工智能·算法·机器学习·数据挖掘
jackylzh2 分钟前
PyTorch 2.x 中 `torch.load` 的 `FutureWarning` 与 `weights_only=False` 参数分析
人工智能·pytorch·python
大学生小郑6 分钟前
亮度噪声和色度噪声
图像处理·音视频·视频
叶庭云9 分钟前
AI Agent KernelCAT:深耕算子开发和模型迁移的 “计算加速专家”
人工智能·运筹优化·算子·ai agent·kernelcat·模型迁移适配·生态壁垒
码农三叔12 分钟前
(8-2)传感器系统与信息获取:外部环境传感
人工智能·嵌入式硬件·数码相机·机器人·人形机器人
MACKEI13 分钟前
服务器流式传输接口问题排查与解决方案
python·nginx·流式
小宇的天下13 分钟前
innovus/virtuoso/ICC2 三大工具的工艺文件有什么区别?
人工智能
产品经理邹继强13 分钟前
VTC营销与增长篇④:增长战略全景图——构建自驱进化的VTC增长飞轮
人工智能
2401_8322981015 分钟前
阿里云倚天ECS实例,Arm架构重构算力性价比范式
人工智能
Jiede122 分钟前
LSTM详细介绍(基于股票收盘价预测场景)
人工智能·rnn·lstm