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

fft1c 和 ifft1c 是 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
相关推荐
灵动的艺术4 分钟前
如一 Agent 架构解读(十二):记忆系统(下)——记忆的生命周期工程
人工智能·agent·如一
保卫大狮兄5 分钟前
简道云 CRM 管理系统:如何做老客户分层经营?新客与老客的策略如何区分?
人工智能·crm·销售
一个处女座的程序猿8 分钟前
Agent之GPT-6:GPT-6.1 Sol 解读—让高阶 AI 能力以更低成本落地
人工智能·agent·gpt-6.1 sol
AI情绪识别开源13 分钟前
检信ALLEMOTION 标定治理与信号质量闸门 · 老年无感认知评估分析器
python
千桐科技15 分钟前
大模型落地不“纸上谈兵”:qKnow专业版用原生MCP为AI装上“手脚”
大数据·人工智能·qknow
2601_9548118216 分钟前
人工智能机器视觉实验箱选型:昇腾算力与工业数据集架构对比
人工智能·架构
小天源19 分钟前
智叟云集系统适用场景与业务实践
大数据·人工智能
七夜zippoe19 分钟前
启元 Q1 腿部运动学逆解:Python 算站立下蹲关节角
开发语言·python·ai·机器人·腿部运动学
Juicedata24 分钟前
面向 EB 级 AI 存储:JuiceFS 企业版架构演进
数据库·人工智能·架构
第404号工位28 分钟前
插上充电宝真能偷光相册?我拆解了一台改装充电宝,实测“恶意充电”的真实攻击链
linux·python·架构