磁共振图像处理中 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
相关推荐
陈奕昆4 分钟前
deepseek生成PPT 提示词模板
人工智能·powerpoint
L_cl24 分钟前
【NLP 56、实践 ⑬ LoRA完成NER任务】
人工智能·自然语言处理
Chaos_Wang_27 分钟前
NLP简介及其发展历史
人工智能·自然语言处理
云卓SKYDROID31 分钟前
无人机飞行术语科普!
人工智能·无人机·科普·高科技·云卓科技
路野yue32 分钟前
自回归(Autoregression)是什么?在大语言模型中自回归的应用
人工智能·语言模型·自然语言处理·数据挖掘·回归
9命怪猫33 分钟前
AI大模型底层技术——结合 Prompt Engineering 的 LoRA
人工智能·深度学习·ai·大模型
LeeZhao@1 小时前
【AGI】Llama4:大模型与多模态领域的里程碑,通往AGI的阶梯
人工智能·yolo·计算机视觉·aigc·agi
菜只因C1 小时前
深入剖析嵌入式系统:从基础到实践的全面指南
大数据·网络·人工智能
Yawesh_best1 小时前
开源AI模型落地教程:如何在个人电脑安装并运行QwQ-32B大模型
人工智能·开源
明明跟你说过1 小时前
【LangChain Agent 】详解,构建自主决策的 LLM 应用
人工智能·ai·语言模型·自然语言处理·chatgpt