-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathismrm_transform_kspace_to_image.m
64 lines (47 loc) · 1.39 KB
/
ismrm_transform_kspace_to_image.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
57
58
59
60
61
62
63
64
function [img] = ismrm_transform_kspace_to_image(k, dim, img_shape)
%
% [img] = ismrm_transform_kspace_to_image(k, dim)
%
% Fourier transform from k-space to image space along a given or all
% dimensions
%
% INPUT:
% - k [kx,ky,..] : k-space data
% - dim vector : Vector with dimensions to transform
% - img_shape vector : Set shape of output image
%
% OUPUT:
% - img [x,y,...] : Data in image 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,
img_shape = [];
end
if isempty(dim),
dim = ndims(k):-1:1;
end
if isempty(img_shape)
img_shape = size(k);
end
img = k;
for d=1:length(dim),
img = transform_one_dim(img, d, img_shape(d));
end
return
function img = transform_one_dim(k, dim, img_extent)
img_shape = size(k);
img_shape(dim) = img_extent;
k_indices = repmat({':'},1, ndims(k));
k_indices{dim} = (1:size(k,dim))+bitshift(img_extent-size(k,dim)+1,-1);
img = zeros(img_shape);
img(k_indices{:}) = k;
img = fftshift(ifft(ifftshift(img, dim), [], dim), dim) .* sqrt(size(img,dim));
return