磁共振图像处理中 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
相关推荐
Narutolxy2 分钟前
Python 单元测试:深入理解与实战应用20240919
python·单元测试·log4j
LLSU134 分钟前
聚星文社AI软件小说推文软件
人工智能
JackieZhengChina7 分钟前
吴泳铭:AI最大的想象力不在手机屏幕,而是改变物理世界
人工智能·智能手机
ShuQiHere8 分钟前
【ShuQiHere】 探索数据挖掘的世界:从概念到应用
人工智能·数据挖掘
嵌入式杂谈8 分钟前
OpenCV计算机视觉:探索图片处理的多种操作
人工智能·opencv·计算机视觉
时光追逐者10 分钟前
分享6个.NET开源的AI和LLM相关项目框架
人工智能·microsoft·ai·c#·.net·.netcore
东隆科技10 分钟前
PicoQuant公司:探索铜铟镓硒(CIGS)太阳能电池技术,引领绿色能源革新
人工智能·能源
红米煮粥11 分钟前
图像处理-掩码
图像处理·opencv·计算机视觉
DisonTangor22 分钟前
上海AI气象大模型提前6天预测“贝碧嘉”台风登陆浦东 今年已多次精准预测
人工智能
Amo Xiang25 分钟前
2024 Python3.10 系统入门+进阶(十五):文件及目录操作
开发语言·python