Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Matlab simple spiral example works with the new api. Modified matlab …
…trajectory (fixed shape).
  • Loading branch information
Souheil Inati committed Oct 24, 2014
1 parent ad35b9a commit 1dbaf4b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
24 changes: 14 additions & 10 deletions examples/matlab/simple_spiral_recon.m
Expand Up @@ -8,19 +8,20 @@
% Michael S. Hansen (michael.hansen@nih.gov), 2012
%

header = ismrmrd_header2struct(h5read(ismrmrdfile,'/dataset/xml'));
dset = ismrmrd.Dataset(ismrmrdfile);
header = ismrmrd.xml.deserialize(dset.readxml());

%Is this a spiral acquisition
if (~strcmp(header.ismrmrdHeader.encoding.trajectory.Text,'spiral')),
if (~strcmp(header.encoding.trajectory,'spiral')),
error('This is not a spiral dataset');
end

%Let's get the matrix size
matrix_size = [str2num(header.ismrmrdHeader.encoding.encodedSpace.matrixSize.x.Text), ...
str2num(header.ismrmrdHeader.encoding.encodedSpace.matrixSize.y.Text)];
matrix_size = [header.encoding.encodedSpace.matrixSize.x, ...
header.encoding.encodedSpace.matrixSize.y];

%Let's load the data
raw_data = h5read(ismrmrdfile,'/dataset/data');
raw_data = dset.readAcquisition(); % read all the acquisitions

interleaves = max(raw_data.head.idx.kspace_encode_step_1)+1;
repetitions = max(raw_data.head.idx.repetition)+1;
Expand All @@ -38,20 +39,23 @@
counter = 0;
for p=1:length(raw_data.head.flags),

if (bitget(uint64(raw_data.head.flags(p)),19)), %if this is noise, we will skip it
%if this is noise, we will skip it
if raw_data.head.flagIsSet('ACQ_IS_NOISE_MEASUREMENT',p)
continue;
end

d = reshape(complex(raw_data.data{p}(1:2:end), raw_data.data{p}(2:2:end)), samples, channels);
t = reshape(raw_data.traj{p}, raw_data.head.trajectory_dimensions(p), samples);
d = raw_data.data{p};
t = raw_data.traj{p};
current_interleave = raw_data.head.idx.kspace_encode_step_1(p)+1;
start_sample = samples_to_skip_start+1;
end_sample = samples-samples_to_skip_end;

data(:,current_interleave,:) = reshape(d(start_sample:end_sample,:), net_samples, 1, channels);
trajectory(:,:,current_interleave) = t(:,start_sample:end_sample);

if (bitget(uint64(raw_data.head.flags(p)),8)), %Is this the last in slice? We should make an image

%Is this the last in slice? We should make an image
if raw_data.head.flagIsSet('ACQ_LAST_IN_SLICE',p)

fprintf('Reconstructing image %d....', counter+1);
co = permute(trajectory(:,:),[2 1]);

Expand Down
12 changes: 6 additions & 6 deletions examples/matlab/test_create_dataset.m
Expand Up @@ -71,13 +71,13 @@
% Set the flags
acqblock.head.flagClearAll(acqno);
if acqno == 1
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_FIRST_IN_ENCODE_STEP1, acqno);
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_FIRST_IN_SLICE, acqno);
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_FIRST_IN_REPETITION, acqno);
acqblock.head.flagSet('ACQ_FIRST_IN_ENCODE_STEP1', acqno);
acqblock.head.flagSet('ACQ_FIRST_IN_SLICE', acqno);
acqblock.head.flagSet('ACQ_FIRST_IN_REPETITION', acqno);
elseif acqno==size(K,2)
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_LAST_IN_ENCODE_STEP1, acqno);
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_LAST_IN_SLICE, acqno);
acqblock.head.flagSet(acqblock.head.FLAGS.ACQ_LAST_IN_REPETITION, acqno);
acqblock.head.flagSet('ACQ_LAST_IN_ENCODE_STEP1', acqno);
acqblock.head.flagSet('ACQ_LAST_IN_SLICE', acqno);
acqblock.head.flagSet('ACQ_LAST_IN_REPETITION', acqno);
end

% fill the data
Expand Down
2 changes: 1 addition & 1 deletion examples/matlab/test_recon_dataset.m
Expand Up @@ -104,7 +104,7 @@
% TODO add a pre-whitening example
% Find the first non-noise scan
% This is how to check if a flag is set in the acquisition header
isNoise = D.head.flagIsSet(D.head.FLAGS.ACQ_IS_NOISE_MEASUREMENT);
isNoise = D.head.flagIsSet('ACQ_IS_NOISE_MEASUREMENT');
firstScan = find(isNoise==0,1,'first');
if firstScan > 1
noise = D.select(1:firstScan-1);
Expand Down
15 changes: 13 additions & 2 deletions matlab/+ismrmrd/Acquisition.m
Expand Up @@ -36,7 +36,7 @@
if isempty(traj)
obj.traj{M} = [];
else
obj.traj = traj;
trajFromFloat(obj,traj);
end
if isempty(data)
obj.data{M} = [];
Expand Down Expand Up @@ -122,13 +122,24 @@ function dataFromFloat(obj,v)
end
end

function trajFromFloat(obj,v)
if (isempty(obj.head) || (length(v) ~= length(obj.head.version)))
error('Mismatch between size of head and trajectory. Please set head first.');
end
obj.traj = cell(1,length(v));
for p = 1:length(v)
dims = [obj.head.trajectory_dimensions(p), ...
obj.head.number_of_samples(p)];
obj.traj{p} = reshape(v{p}, dims);
end
end

function v = trajToFloat(obj)
v = cell(1,length(obj.traj));
for p = 1:length(obj.traj)
v{p} = single(obj.traj{p});
end
end

end

end

0 comments on commit 1dbaf4b

Please sign in to comment.