磁共振图像处理中 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
相关推荐
fīɡЙtīиɡ ℡32 分钟前
AI 应用系统设计
java·开发语言·人工智能
小淮AI40 分钟前
国际教育课程的本土化探索:以枫叶教育三十年为观察样本
大数据·人工智能
又折桃枝换酒钱1 小时前
VisCoder2:构建多语言可视化编码智能体(翻译与解读)
人工智能·信息可视化
AI绘画哇哒哒1 小时前
【建议收藏!】35岁后端血泪忠告,这3类人别硬转Agent(过来人亲述)
java·人工智能·后端·ai·程序员·大模型·agent
Chengbei111 小时前
DSH渗透测试插件dsh-pentest全新升级!适配DeepSeek Harness,可视化探索链路,一键搭建轻量化AI渗透测试环境。
人工智能·web安全·网络安全·微信·小程序·系统安全·安全架构
QN1幻化引擎1 小时前
DalinX Phi 性能突破:跨层秩保持对齐与意识涌现度量的实证研究
人工智能·ai·架构·agi·asi
NeilCarmack1 小时前
Deepseek-harness增加桌面版端序列:第 1 讲 · 命令解析:`pnpm dsh desktop` 的第一步
人工智能·agent·ai agent
聪明蛋子哟1 小时前
Stagehand v3多语言SDK:Python/Go/Rust/Java下的浏览器自动化统一方案
python·golang·rust
龙兵AI增长破局圈.赵老师讲成交1 小时前
只有把过程管好,结果才会出来。
大数据·人工智能·ai·创业创新
最强小杰2 小时前
gpt-5.6-sol 频繁报 503 怎么办?区分容量熔断和限速 429 的排查方法 + 可复用 retry wrapper
java·人工智能·gpt·ai