磁共振图像处理中 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
相关推荐
盲盒Q10 分钟前
《频率之光:归途之光》
人工智能·硬件架构·量子计算
guozhetao12 分钟前
【ST表、倍增】P7167 [eJOI 2020] Fountain (Day1)
java·c++·python·算法·leetcode·深度优先·图论
墨染点香18 分钟前
第七章 Pytorch构建模型详解【构建CIFAR10模型结构】
人工智能·pytorch·python
go546315846519 分钟前
基于分组规则的Excel数据分组优化系统设计与实现
人工智能·学习·生成对抗网络·数学建模·语音识别
茫茫人海一粒沙25 分钟前
vLLM 的“投机取巧”:Speculative Decoding 如何加速大语言模型推理
人工智能·语言模型·自然语言处理
诗酒当趁年华27 分钟前
【NLP实践】二、自训练数据实现中文文本分类并提供RestfulAPI服务
人工智能·自然语言处理·分类
阿什么名字不会重复呢41 分钟前
在线工具+网页平台来学习和操作Python与Excel相关技能
python·数据分析
静心问道1 小时前
Idefics3:构建和更好地理解视觉-语言模型:洞察与未来方向
人工智能·多模态·ai技术应用
sheep88881 小时前
AI与区块链Web3技术融合:重塑数字经济的未来格局
人工智能·区块链
奋进的孤狼1 小时前
【Spring AI】阿里云DashScope灵积模型
人工智能·spring·阿里云·ai·云计算