-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathismrm_transform_image_to_kspace.m
56 lines (45 loc) · 1.28 KB
/
ismrm_transform_image_to_kspace.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [k] = ismrm_transform_image_to_kspace2(img, dim, k_shape)
%
% [k] = ismrm_transform_image_to_kspace(img, dim)
%
% Fourier transform from image space to k-space space along a given or all
% dimensions
%
% INPUT:
% - img [x,y,..] : image space data
% - dim vector : Vector with dimensions to transform
% - k_shape vector : Set shape of output k-space matrix
%
% OUPUT:
% - k [kx,ky,...] : Data in k-space (along transformed dimensions)
%
% Code made available for the ISMRM 2013 Sunrise Educational Course
%
% Michael S. Hansen ([email protected])
% Philip J. Beatty ([email protected])
%
if nargin < 2,
dim = [];
end
if nargin < 3,
k_shape = [];
end
if isempty(dim),
dim = ndims(img):-1:1;
end
if isempty(k_shape)
k_shape = size(img);
end
k = img;
for d=1:length(dim),
k = transform_one_dim(k, d, k_shape(d));
end
return
function k = transform_one_dim(img, dim, k_extent)
k_shape = size(img);
k_shape(dim) = k_extent;
k_indices = repmat({':'},1, ndims(img));
k_indices{dim} = (1:k_extent)+bitshift(size(img, dim)-k_extent+1,-1);
k = fftshift(fft(ifftshift(img, dim), [], dim), dim) ./ sqrt(size(img,dim));
k = k(k_indices{:});
return