磁共振图像处理中 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
相关推荐
ZZZMMM.zip7 分钟前
数据侦探社-数据趋势分析的HarmonyOS开发实践
人工智能·华为·harmonyos·鸿蒙·鸿蒙系统
2601_955759419 分钟前
code0 gpt-5.5 场景相关:教育平台智能批改与答疑实操
大数据·人工智能·gpt
KaMeidebaby9 分钟前
卡梅德生物技术快报|抗体合成:多肽抗体合成工程化方案:Nsp2 保守肽多抗制备与多维度验证
前端·网络·数据库·人工智能·算法
「QT(C++)开发工程师」15 分钟前
AI Agent(智能体) 教程
人工智能·ai·ai编程
旋律翼218 分钟前
AI Prompt 工程化设计最佳实践(Harness Engineering)
人工智能·prompt
程序猿DD24 分钟前
AI Key 太多?我做了个统一管理工具
人工智能
元岳数字人小元36 分钟前
AI数字人交互系统:多场景落地应用价值解析
人工智能·人机交互·交互
pokemen邪137 分钟前
PyTorch KernelAgent 源码解读 ---(6)--- Composer
人工智能·pytorch·composer
仙人球部落38 分钟前
-python-LangGraph框架(3-31-LangGraph 「合并式状态管理」的原理与实践)
开发语言·javascript·python
陈天伟教授39 分钟前
图解人工智能(90)人工智能前沿-天文学家的助手
人工智能