| 1 |
classdef AcquisitionHeader < handle |
| 2 |
|
| 3 |
properties |
| 4 |
|
| 5 |
version = uint16([]); % First unsigned int indicates the version % |
| 6 |
flags = uint64([]); % bit field with flags % |
| 7 |
measurement_uid = uint32([]); % Unique ID for the measurement % |
| 8 |
scan_counter = uint32([]); % Current acquisition number in the measurement % |
| 9 |
acquisition_time_stamp = uint32([]); % Acquisition clock % |
| 10 |
physiology_time_stamp = uint32([]); % Physiology time stamps, e.g. ecg, breating, etc. % |
| 11 |
number_of_samples = uint16([]); % Number of samples acquired % |
| 12 |
available_channels = uint16([]); % Available coils % |
| 13 |
active_channels = uint16([]); % Active coils on current acquisiton % |
| 14 |
channel_mask = uint64([]); % Mask to indicate which channels are active. Support for 1024 channels % |
| 15 |
discard_pre = uint16([]); % Samples to be discarded at the beginning of acquisition % |
| 16 |
discard_post = uint16([]); % Samples to be discarded at the end of acquisition % |
| 17 |
center_sample = uint16([]); % Sample at the center of k-space % |
| 18 |
encoding_space_ref = uint16([]); % Reference to an encoding space, typically only one per acquisition % |
| 19 |
trajectory_dimensions = uint16([]); % Indicates the dimensionality of the trajectory vector (0 means no trajectory) % |
| 20 |
sample_time_us = single([]); % Time between samples in micro seconds, sampling BW % |
| 21 |
position = single([]); % Three-dimensional spatial offsets from isocenter % |
| 22 |
read_dir = single([]); % Directional cosines of the readout/frequency encoding % |
| 23 |
phase_dir = single([]); % Directional cosines of the phase encoding % |
| 24 |
slice_dir = single([]); % Directional cosines of the slice % |
| 25 |
patient_table_position = single([]); % Patient table off-center % |
| 26 |
idx = struct( ... % Encoding loop counters, see above % |
| 27 |
'kspace_encode_step_1', uint16([]), ... |
| 28 |
'kspace_encode_step_2', uint16([]), ... |
| 29 |
'average', uint16([]), ... |
| 30 |
'slice', uint16([]), ... |
| 31 |
'contrast', uint16([]), ... |
| 32 |
'phase', uint16([]), ... |
| 33 |
'repetition', uint16([]), ... |
| 34 |
'set', uint16([]), ... |
| 35 |
'segment', uint16([]), ... |
| 36 |
'user', uint16([])); |
| 37 |
user_int = int32([]); % Free user parameters % |
| 38 |
user_float = single([]); % Free user parameters % |
| 39 |
|
| 40 |
end |
| 41 |
|
| 42 |
properties(Constant) |
| 43 |
FLAGS = struct( ... |
| 44 |
'ACQ_FIRST_IN_ENCODE_STEP1', 1, ... |
| 45 |
'ACQ_LAST_IN_ENCODE_STEP1', 2, ... |
| 46 |
'ACQ_FIRST_IN_ENCODE_STEP2', 3, ... |
| 47 |
'ACQ_LAST_IN_ENCODE_STEP2', 4, ... |
| 48 |
'ACQ_FIRST_IN_AVERAGE', 5, ... |
| 49 |
'ACQ_LAST_IN_AVERAGE', 6, ... |
| 50 |
'ACQ_FIRST_IN_SLICE', 7, ... |
| 51 |
'ACQ_LAST_IN_SLICE', 8, ... |
| 52 |
'ACQ_FIRST_IN_CONTRAST', 9, ... |
| 53 |
'ACQ_LAST_IN_CONTRAST', 10, ... |
| 54 |
'ACQ_FIRST_IN_PHASE', 11, ... |
| 55 |
'ACQ_LAST_IN_PHASE', 12, ... |
| 56 |
'ACQ_FIRST_IN_REPETITION', 13, ... |
| 57 |
'ACQ_LAST_IN_REPETITION', 14, ... |
| 58 |
'ACQ_FIRST_IN_SET', 15, ... |
| 59 |
'ACQ_LAST_IN_SET', 16, ... |
| 60 |
'ACQ_FIRST_IN_SEGMENT', 17, ... |
| 61 |
'ACQ_LAST_IN_SEGMENT', 18, ... |
| 62 |
'ACQ_IS_NOISE_MEASUREMENT', 19, ... |
| 63 |
'ACQ_IS_PARALLEL_CALIBRATION', 20, ... |
| 64 |
'ACQ_IS_PARALLEL_CALIBRATION_AND_IMAGING', 21, ... |
| 65 |
'ACQ_IS_REVERSE', 22, ... |
| 66 |
'ACQ_IS_NAVIGATION_DATA', 23, ... |
| 67 |
'ACQ_IS_PHASECORR_DATA', 24, ... |
| 68 |
'ACQ_LAST_IN_MEASUREMENT', 25, ... |
| 69 |
'ACQ_IS_HPFEEDBACK_DATA', 26, ... |
| 70 |
'ACQ_IS_DUMMYSCAN_DATA', 27, ... |
| 71 |
'ACQ_IS_RTFEEDBACK_DATA', 28, ... |
| 72 |
'ACQ_IS_SURFACECOILCORRECTIONSCAN_DATA', 29, ... |
| 73 |
'ACQ_COMPRESSION1', 53, ... |
| 74 |
'ACQ_COMPRESSION2', 54, ... |
| 75 |
'ACQ_COMPRESSION3', 55, ... |
| 76 |
'ACQ_COMPRESSION4', 56, ... |
| 77 |
'ACQ_USER1', 57, ... |
| 78 |
'ACQ_USER2', 58, ... |
| 79 |
'ACQ_USER3', 59, ... |
| 80 |
'ACQ_USER4', 60, ... |
| 81 |
'ACQ_USER5', 61, ... |
| 82 |
'ACQ_USER6', 62, ... |
| 83 |
'ACQ_USER7', 63, ... |
| 84 |
'ACQ_USER8', 64); |
| 85 |
end |
| 86 |
|
| 87 |
methods |
| 88 |
|
| 89 |
function obj = AcquisitionHeader(arg) |
| 90 |
% Constructor |
| 91 |
|
| 92 |
switch nargin |
| 93 |
case 0 |
| 94 |
% No argument constructor |
| 95 |
% initialize to a single acquisition header |
| 96 |
extend(obj,1); |
| 97 |
|
| 98 |
case 1 |
| 99 |
% One argument constructor |
| 100 |
if isstruct(arg) |
| 101 |
% plain struct |
| 102 |
fromStruct(obj,arg); |
| 103 |
elseif (length(arg)==1 && ismrmrd.util.isInt(arg)) == 1 |
| 104 |
% number |
| 105 |
extend(obj,arg); |
| 106 |
elseif isa(arg,'uint8') |
| 107 |
% Byte array |
| 108 |
fromBytes(obj,arg); |
| 109 |
else |
| 110 |
% Unknown type |
| 111 |
error('Unknown argument type.') |
| 112 |
end |
| 113 |
|
| 114 |
otherwise |
| 115 |
error('Wrong number of arguments.') |
| 116 |
|
| 117 |
end |
| 118 |
end |
| 119 |
|
| 120 |
function nacq = getNumber(obj) |
| 121 |
% Return the number of headers |
| 122 |
|
| 123 |
nacq = length(obj.version); |
| 124 |
|
| 125 |
end |
| 126 |
|
| 127 |
function hdr = select(obj, range) |
| 128 |
% Return a copy of a range of acquisition headers |
| 129 |
|
| 130 |
% create an empty acquisition header |
| 131 |
M = length(range); |
| 132 |
hdr = ismrmrd.AcquisitionHeader(M); |
| 133 |
|
| 134 |
% Fill |
| 135 |
hdr.version = obj.version(range); |
| 136 |
hdr.flags = obj.flags(range); |
| 137 |
hdr.measurement_uid = obj.measurement_uid(range); |
| 138 |
hdr.scan_counter = obj.scan_counter(range); |
| 139 |
hdr.acquisition_time_stamp = obj.acquisition_time_stamp(range); |
| 140 |
hdr.physiology_time_stamp = obj.physiology_time_stamp(:,range); |
| 141 |
hdr.number_of_samples = obj.number_of_samples(range); |
| 142 |
hdr.available_channels = obj.available_channels(range); |
| 143 |
hdr.active_channels = obj.active_channels(range); |
| 144 |
hdr.channel_mask = obj.channel_mask(:,range); |
| 145 |
hdr.discard_pre = obj.discard_pre(range); |
| 146 |
hdr.discard_post = obj.discard_post(range); |
| 147 |
hdr.center_sample = obj.center_sample(range); |
| 148 |
hdr.encoding_space_ref = obj.encoding_space_ref(range); |
| 149 |
hdr.trajectory_dimensions = obj.trajectory_dimensions(range); |
| 150 |
hdr.sample_time_us = obj.sample_time_us(range); |
| 151 |
hdr.position = obj.position(:,range); |
| 152 |
hdr.read_dir = obj.read_dir(:,range); |
| 153 |
hdr.phase_dir = obj.phase_dir(:,range); |
| 154 |
hdr.slice_dir = obj.slice_dir(:,range); |
| 155 |
hdr.patient_table_position = obj.patient_table_position(:,range); |
| 156 |
hdr.idx.kspace_encode_step_1 = obj.idx.kspace_encode_step_1(range); |
| 157 |
hdr.idx.kspace_encode_step_2 = obj.idx.kspace_encode_step_2(range); |
| 158 |
hdr.idx.average = obj.idx.average(range); |
| 159 |
hdr.idx.slice = obj.idx.slice(range); |
| 160 |
hdr.idx.contrast = obj.idx.contrast(range); |
| 161 |
hdr.idx.phase = obj.idx.phase(range); |
| 162 |
hdr.idx.repetition = obj.idx.repetition(range); |
| 163 |
hdr.idx.set = obj.idx.set(range); |
| 164 |
hdr.idx.segment = obj.idx.segment(range); |
| 165 |
hdr.idx.user = obj.idx.user(:,range); |
| 166 |
hdr.user_int = obj.user_int(:,range); |
| 167 |
hdr.user_float = obj.user_float(:,range); |
| 168 |
|
| 169 |
end |
| 170 |
|
| 171 |
function extend(obj,N) |
| 172 |
% Extend with blank header |
| 173 |
|
| 174 |
range = obj.getNumber + (1:N); |
| 175 |
obj.version(1,range) = zeros(1,N,'uint16'); |
| 176 |
obj.flags(1,range) = zeros(1,N,'uint64'); |
| 177 |
obj.measurement_uid(1,range) = zeros(1,N,'uint32'); |
| 178 |
obj.scan_counter(1,range) = zeros(1,N,'uint32'); |
| 179 |
obj.acquisition_time_stamp(1,range) = zeros(1,N,'uint32'); |
| 180 |
obj.physiology_time_stamp(1:3,range) = zeros(3,N,'uint32'); |
| 181 |
obj.number_of_samples(1,range) = zeros(1,N,'uint16'); |
| 182 |
obj.available_channels(1,range) = zeros(1,N,'uint16'); |
| 183 |
obj.active_channels(1,range) = zeros(1,N,'uint16'); |
| 184 |
obj.channel_mask(1:16,range) = zeros(16,N,'uint64'); |
| 185 |
obj.discard_pre(1,range) = zeros(1,N,'uint16'); |
| 186 |
obj.discard_post(1,range) = zeros(1,N,'uint16'); |
| 187 |
obj.center_sample(1,range) = zeros(1,N,'uint16'); |
| 188 |
obj.encoding_space_ref(1,range) = zeros(1,N,'uint16'); |
| 189 |
obj.trajectory_dimensions(1,range) = zeros(1,N,'uint16'); |
| 190 |
obj.sample_time_us(1,range) = zeros(1,N,'uint16'); |
| 191 |
obj.position(1:3,range) = zeros(3,N,'single'); |
| 192 |
obj.read_dir(1:3,range) = zeros(3,N,'single'); |
| 193 |
obj.phase_dir(1:3,range) = zeros(3,N,'single'); |
| 194 |
obj.slice_dir(1:3,range) = zeros(3,N,'single'); |
| 195 |
obj.patient_table_position(1:3,range) = zeros(3,N,'single'); |
| 196 |
obj.idx.kspace_encode_step_1(1,range) = zeros(1,N,'uint16'); |
| 197 |
obj.idx.kspace_encode_step_2(1,range) = zeros(1,N,'uint16'); |
| 198 |
obj.idx.average(1,range) = zeros(1,N,'uint16'); |
| 199 |
obj.idx.slice(1,range) = zeros(1,N,'uint16'); |
| 200 |
obj.idx.contrast(1,range) = zeros(1,N,'uint16'); |
| 201 |
obj.idx.phase(1,range) = zeros(1,N,'uint16'); |
| 202 |
obj.idx.repetition(1,range) = zeros(1,N,'uint16'); |
| 203 |
obj.idx.set(1,range) = zeros(1,N,'uint16'); |
| 204 |
obj.idx.segment(1,range) = zeros(1,N,'uint16'); |
| 205 |
obj.idx.user(1:8,range) = zeros(8,N,'uint16'); |
| 206 |
obj.user_int(1:8,range) = zeros(8,N,'int32'); |
| 207 |
obj.user_float(1:8,range) = zeros(8,N,'single'); |
| 208 |
end |
| 209 |
|
| 210 |
function append(obj, hdr) |
| 211 |
% Append a header |
| 212 |
|
| 213 |
Nstart = obj.getNumber + 1; |
| 214 |
Nend = obj.getNumber + length(hdr.version); |
| 215 |
Nrange = Nstart:Nend; |
| 216 |
obj.version(1,Nrange) = hdr.version(:); |
| 217 |
obj.flags(1,Nrange) = hdr.flags(:); |
| 218 |
obj.measurement_uid(1,Nrange) = hdr.measurement_uid(:); |
| 219 |
obj.scan_counter(1,Nrange) = hdr.scan_counter(:); |
| 220 |
obj.acquisition_time_stamp(1,Nrange) = hdr.acquisition_time_stamp(:); |
| 221 |
obj.physiology_time_stamp(:,Nrange) = hdr.physiology_time_stamp(:); |
| 222 |
obj.number_of_samples(1,Nrange) = hdr.number_of_samples(:); |
| 223 |
obj.available_channels(1,Nrange) = hdr.available_channels(:); |
| 224 |
obj.active_channels(1,Nrange) = hdr.active_channels(:); |
| 225 |
obj.channel_mask(:,Nrange) = hdr.channel_mask(:); |
| 226 |
obj.discard_pre(1,Nrange) = hdr.discard_pre(:); |
| 227 |
obj.discard_post(1,Nrange) = hdr.discard_post(:); |
| 228 |
obj.center_sample(1,Nrange) = hdr.center_sample(:); |
| 229 |
obj.encoding_space_ref(1,Nrange) = hdr.encoding_space_ref(:); |
| 230 |
obj.trajectory_dimensions(1,Nrange) = hdr.trajectory_dimensions(:); |
| 231 |
obj.sample_time_us(1,Nrange) = hdr.sample_time_us(:); |
| 232 |
obj.position(:,Nrange) = hdr.position(:); |
| 233 |
obj.read_dir(:,Nrange) = hdr.read_dir(:); |
| 234 |
obj.phase_dir(:,Nrange) = hdr.phase_dir(:); |
| 235 |
obj.slice_dir(:,Nrange) = hdr.slice_dir(:); |
| 236 |
obj.patient_table_position(:,Nrange) = hdr.patient_table_position(:); |
| 237 |
obj.idx.kspace_encode_step_1(1,Nrange) = hdr.idx.kspace_encode_step_1(:); |
| 238 |
obj.idx.kspace_encode_step_2(1,Nrange) = hdr.idx.kspace_encode_step_2(:); |
| 239 |
obj.idx.average(1,Nrange) = hdr.idx.average(:); |
| 240 |
obj.idx.slice(1,Nrange) = hdr.idx.slice(:); |
| 241 |
obj.idx.contrast(1,Nrange) = hdr.idx.contrast(:); |
| 242 |
obj.idx.phase(1,Nrange) = hdr.idx.phase(:); |
| 243 |
obj.idx.repetition(1,Nrange) = hdr.idx.repetition(:); |
| 244 |
obj.idx.set(1,Nrange) = hdr.idx.set(:); |
| 245 |
obj.idx.segment(1,Nrange) = hdr.idx.segment(:); |
| 246 |
obj.idx.user(:,Nrange) = hdr.idx.user(:); |
| 247 |
obj.user_int(:,Nrange) = hdr.user_int(:); |
| 248 |
obj.user_float(:,Nrange) = hdr.user_float(:); |
| 249 |
end |
| 250 |
|
| 251 |
function fromStruct(obj, hdr) |
| 252 |
% Convert a struct to the object |
| 253 |
N = length(hdr.version); |
| 254 |
%warning! no error checking |
| 255 |
obj.version = reshape(hdr.version,[1,N]); |
| 256 |
obj.flags = reshape(hdr.flags,[1,N]); |
| 257 |
obj.measurement_uid = reshape(hdr.measurement_uid,[1,N]); |
| 258 |
obj.scan_counter = reshape(hdr.scan_counter,[1,N]); |
| 259 |
obj.acquisition_time_stamp = reshape(hdr.acquisition_time_stamp,[1,N]); |
| 260 |
obj.physiology_time_stamp = reshape(hdr.physiology_time_stamp,[3,N]); |
| 261 |
obj.number_of_samples = reshape(hdr.number_of_samples,[1,N]); |
| 262 |
obj.available_channels = reshape(hdr.available_channels,[1,N]); |
| 263 |
obj.active_channels = reshape(hdr.active_channels,[1,N]); |
| 264 |
obj.channel_mask = reshape(hdr.channel_mask,[16,N]); |
| 265 |
obj.discard_pre = reshape(hdr.discard_pre,[1,N]); |
| 266 |
obj.discard_post = reshape(hdr.discard_post,[1,N]); |
| 267 |
obj.center_sample = reshape(hdr.center_sample,[1,N]); |
| 268 |
obj.encoding_space_ref = reshape(hdr.encoding_space_ref,[1,N]); |
| 269 |
obj.trajectory_dimensions = reshape(hdr.trajectory_dimensions,[1,N]); |
| 270 |
obj.sample_time_us = reshape(hdr.sample_time_us,[1,N]); |
| 271 |
obj.position = reshape(hdr.position,[3,N]); |
| 272 |
obj.read_dir = reshape(hdr.read_dir,[3,N]); |
| 273 |
obj.phase_dir = reshape(hdr.phase_dir,[3,N]); |
| 274 |
obj.slice_dir = reshape(hdr.slice_dir,[3,N]); |
| 275 |
obj.patient_table_position = reshape(hdr.patient_table_position,[3,N]); |
| 276 |
obj.idx.kspace_encode_step_1 = reshape(hdr.idx.kspace_encode_step_1,[1,N]); |
| 277 |
obj.idx.kspace_encode_step_2 = reshape(hdr.idx.kspace_encode_step_2,[1,N]); |
| 278 |
obj.idx.average = reshape(hdr.idx.average,[1,N]); |
| 279 |
obj.idx.slice = reshape(hdr.idx.slice,[1,N]); |
| 280 |
obj.idx.contrast = reshape(hdr.idx.contrast,[1,N]); |
| 281 |
obj.idx.phase = reshape(hdr.idx.phase,[1,N]); |
| 282 |
obj.idx.repetition = reshape(hdr.idx.repetition,[1,N]); |
| 283 |
obj.idx.set = reshape(hdr.idx.set,[1,N]); |
| 284 |
obj.idx.segment = reshape(hdr.idx.segment,[1,N]); |
| 285 |
obj.idx.user = reshape(hdr.idx.user,[8,N]); |
| 286 |
obj.user_int = reshape(hdr.user_int,[8,N]); |
| 287 |
obj.user_float = reshape(hdr.user_float,[8,N]); |
| 288 |
end |
| 289 |
|
| 290 |
function hdr = toStruct(obj) |
| 291 |
% Convert the object to a plain struct |
| 292 |
|
| 293 |
%warning! no error checking |
| 294 |
hdr = struct(); |
| 295 |
hdr.version = obj.version; |
| 296 |
hdr.flags = obj.flags; |
| 297 |
hdr.measurement_uid = obj.measurement_uid; |
| 298 |
hdr.scan_counter = obj.scan_counter; |
| 299 |
hdr.acquisition_time_stamp = obj.acquisition_time_stamp; |
| 300 |
hdr.physiology_time_stamp = obj.physiology_time_stamp; |
| 301 |
hdr.number_of_samples = obj.number_of_samples; |
| 302 |
hdr.available_channels = obj.available_channels; |
| 303 |
hdr.active_channels = obj.active_channels; |
| 304 |
hdr.channel_mask = obj.channel_mask; |
| 305 |
hdr.discard_pre = obj.discard_pre; |
| 306 |
hdr.discard_post = obj.discard_post; |
| 307 |
hdr.center_sample = obj.center_sample; |
| 308 |
hdr.encoding_space_ref = obj.encoding_space_ref; |
| 309 |
hdr.trajectory_dimensions = obj.trajectory_dimensions; |
| 310 |
hdr.sample_time_us = obj.sample_time_us; |
| 311 |
hdr.position = obj.position; |
| 312 |
hdr.read_dir = obj.read_dir; |
| 313 |
hdr.phase_dir = obj.phase_dir; |
| 314 |
hdr.slice_dir = obj.slice_dir; |
| 315 |
hdr.patient_table_position = obj.patient_table_position; |
| 316 |
hdr.idx.kspace_encode_step_1 = obj.idx.kspace_encode_step_1; |
| 317 |
hdr.idx.kspace_encode_step_2 = obj.idx.kspace_encode_step_2; |
| 318 |
hdr.idx.average = obj.idx.average; |
| 319 |
hdr.idx.slice = obj.idx.slice; |
| 320 |
hdr.idx.contrast = obj.idx.contrast; |
| 321 |
hdr.idx.phase = obj.idx.phase; |
| 322 |
hdr.idx.repetition = obj.idx.repetition; |
| 323 |
hdr.idx.set = obj.idx.set; |
| 324 |
hdr.idx.segment = obj.idx.segment; |
| 325 |
hdr.idx.user = obj.idx.user; |
| 326 |
hdr.user_int = obj.user_int; |
| 327 |
hdr.user_float = obj.user_float; |
| 328 |
end |
| 329 |
|
| 330 |
function fromBytes(obj, bytearray) |
| 331 |
% Convert from a byte array to an ISMRMRD AcquisitionHeader |
| 332 |
% This conforms to the memory layout of the C-struct |
| 333 |
|
| 334 |
if size(bytearray,1) ~= 340 |
| 335 |
error('Wrong number of bytes for AcquisitionHeader.') |
| 336 |
end |
| 337 |
N = size(bytearray,2); |
| 338 |
|
| 339 |
obj.version = reshape(typecast(reshape(bytearray( 1: 2, :), 1, 2 * N), 'uint16'), 1, N); % First unsigned int indicates the version % |
| 340 |
obj.flags = reshape(typecast(reshape(bytearray( 3: 10, :), 1, 8 * N), 'uint64'), 1, N); % bit field with flags % |
| 341 |
obj.measurement_uid = reshape(typecast(reshape(bytearray( 11: 14, :), 1, 4 * N), 'uint32'), 1, N); % Unique ID for the measurement % |
| 342 |
obj.scan_counter = reshape(typecast(reshape(bytearray( 15: 18, :), 1, 4 * N), 'uint32'), 1, N); % Current acquisition number in the measurement % |
| 343 |
obj.acquisition_time_stamp = reshape(typecast(reshape(bytearray( 19: 22, :), 1, 4 * N), 'uint32'), 1, N); % Acquisition clock % |
| 344 |
obj.physiology_time_stamp = reshape(typecast(reshape(bytearray( 23: 34, :), 1, 4 * 3 * N), 'uint32'), 3, N); % Physiology time stamps, e.g. ecg, breating, etc. % |
| 345 |
obj.number_of_samples = reshape(typecast(reshape(bytearray( 35: 36, :), 1, 2 * N), 'uint16'), 1, N); % Number of samples acquired % |
| 346 |
obj.available_channels = reshape(typecast(reshape(bytearray( 37: 38, :), 1, 2 * N), 'uint16'), 1, N); % Available coils % |
| 347 |
obj.active_channels = reshape(typecast(reshape(bytearray( 39: 40, :), 1, 2 * N), 'uint16'), 1, N); % Active coils on current acquisiton % |
| 348 |
obj.channel_mask = reshape(typecast(reshape(bytearray( 41:168, :), 1, 8 * 16 * N), 'uint64'), 16, N); % Mask to indicate which channels are active. Support for 1024 channels % |
| 349 |
obj.discard_pre = reshape(typecast(reshape(bytearray( 169:170, :), 1, 2 * N), 'uint16'), 1, N); % Samples to be discarded at the beginning of acquisition % |
| 350 |
obj.discard_post = reshape(typecast(reshape(bytearray( 171:172, :), 1, 2 * N), 'uint16'), 1, N); % Samples to be discarded at the end of acquisition % |
| 351 |
obj.center_sample = reshape(typecast(reshape(bytearray( 173:174, :), 1, 2 * N), 'uint16'), 1, N); % Sample at the center of k-space % |
| 352 |
obj.encoding_space_ref = reshape(typecast(reshape(bytearray( 175:176, :), 1, 2 * N), 'uint16'), 1, N); % Reference to an encoding space, typically only one per acquisition % |
| 353 |
obj.trajectory_dimensions = reshape(typecast(reshape(bytearray( 177:178, :), 1, 2 * N), 'uint16'), 1, N); % Indicates the dimensionality of the trajectory vector (0 means no trajectory) % |
| 354 |
obj.sample_time_us = reshape(typecast(reshape(bytearray( 179:182, :), 1, 4 * N), 'single'), 1, N); % Time between samples in micro seconds, sampling BW % |
| 355 |
obj.position = reshape(typecast(reshape(bytearray( 183:194, :), 1, 4 * 3 * N), 'single'), 3, N); % Three-dimensional spatial offsets from isocenter % |
| 356 |
obj.read_dir = reshape(typecast(reshape(bytearray( 195:206, :), 1, 4 * 3 * N), 'single'), 3, N); % Directional cosines of the readout/frequency encoding % |
| 357 |
obj.phase_dir = reshape(typecast(reshape(bytearray( 207:218, :), 1, 4 * 3 * N), 'single'), 3, N); % Directional cosines of the phase encoding % |
| 358 |
obj.slice_dir = reshape(typecast(reshape(bytearray( 219:230, :), 1, 4 * 3 * N), 'single'), 3, N); % Directional cosines of the slice % |
| 359 |
obj.patient_table_position = reshape(typecast(reshape(bytearray( 231:242, :), 1, 4 * 3 * N), 'single'), 3, N); % Patient table off-center % |
| 360 |
obj.idx.kspace_encode_step_1 = reshape(typecast(reshape(bytearray( 243:244, :), 1, 2 * N), 'uint16'), 1, N); % phase encoding line number % |
| 361 |
obj.idx.kspace_encode_step_2 = reshape(typecast(reshape(bytearray( 245:246, :), 1, 2 * N), 'uint16'), 1, N); % partition encodning number % |
| 362 |
obj.idx.average = reshape(typecast(reshape(bytearray( 247:248, :), 1, 2 * N), 'uint16'), 1, N); % signal average number % |
| 363 |
obj.idx.slice = reshape(typecast(reshape(bytearray( 249:250, :), 1, 2 * N), 'uint16'), 1, N); % imaging slice number % |
| 364 |
obj.idx.contrast = reshape(typecast(reshape(bytearray( 251:252, :), 1, 2 * N), 'uint16'), 1, N); % echo number in multi-echo % |
| 365 |
obj.idx.phase = reshape(typecast(reshape(bytearray( 253:254, :), 1, 2 * N), 'uint16'), 1, N); % cardiac phase number % |
| 366 |
obj.idx.repetition = reshape(typecast(reshape(bytearray( 255:256, :), 1, 2 * N), 'uint16'), 1, N); % dynamic number for dynamic scanning % |
| 367 |
obj.idx.set = reshape(typecast(reshape(bytearray( 257:258, :), 1, 2 * N), 'uint16'), 1, N); % flow encoding set % |
| 368 |
obj.idx.segment = reshape(typecast(reshape(bytearray( 259:260, :), 1, 2 * N), 'uint16'), 1, N); % segment number for segmented acquisition % |
| 369 |
obj.idx.user = reshape(typecast(reshape(bytearray( 261:276, :), 1, 2 * 8 * N), 'uint16'), 8, N); % Free user parameters % |
| 370 |
obj.user_int = reshape(typecast(reshape(bytearray( 277:308, :), 1, 4 * 8 * N), 'int32' ), 8, N); % Free user parameters % |
| 371 |
obj.user_float = reshape(typecast(reshape(bytearray( 309:340, :), 1, 4 * 8 * N), 'single'), 8, N); % Free user parameters % |
| 372 |
|
| 373 |
end |
| 374 |
|
| 375 |
function bytes = toBytes(obj) |
| 376 |
% Convert to an ISMRMRD AcquisitionHeader to a byte array |
| 377 |
% This conforms to the memory layout of the C-struct |
| 378 |
|
| 379 |
N = obj.getNumber; |
| 380 |
bytes = zeros(340,N,'uint8'); |
| 381 |
for p = 1:N |
| 382 |
off = 1; |
| 383 |
bytes(off:off+1,p) = typecast(obj.version(p) ,'uint8'); off=off+2; |
| 384 |
bytes(off:off+7,p) = typecast(obj.flags(p) ,'uint8'); off=off+8; |
| 385 |
bytes(off:off+3,p) = typecast(obj.measurement_uid(p) ,'uint8'); off=off+4; |
| 386 |
bytes(off:off+3,p) = typecast(obj.scan_counter(p) ,'uint8'); off=off+4; |
| 387 |
bytes(off:off+3,p) = typecast(obj.acquisition_time_stamp(p),'uint8'); off=off+4; |
| 388 |
bytes(off:off+11,p) = typecast(obj.physiology_time_stamp(:,p) ,'uint8'); off=off+12; |
| 389 |
bytes(off:off+1,p) = typecast(obj.number_of_samples(p) ,'uint8'); off=off+2; |
| 390 |
bytes(off:off+1,p) = typecast(obj.available_channels(p) ,'uint8'); off=off+2; |
| 391 |
bytes(off:off+1,p) = typecast(obj.active_channels(p) ,'uint8'); off=off+2; |
| 392 |
bytes(off:off+127,p) = typecast(obj.channel_mask(:,p) ,'uint8'); off=off+128; |
| 393 |
bytes(off:off+1,p) = typecast(obj.discard_pre(p) ,'uint8'); off=off+2; |
| 394 |
bytes(off:off+1,p) = typecast(obj.discard_post(p) ,'uint8'); off=off+2; |
| 395 |
bytes(off:off+1,p) = typecast(obj.center_sample(p) ,'uint8'); off=off+2; |
| 396 |
bytes(off:off+1,p) = typecast(obj.encoding_space_ref(p) ,'uint8'); off=off+2; |
| 397 |
bytes(off:off+1,p) = typecast(obj.trajectory_dimensions(p) ,'uint8'); off=off+2; |
| 398 |
bytes(off:off+3,p) = typecast(obj.sample_time_us(p) ,'uint8'); off=off+4; |
| 399 |
bytes(off:off+11,p) = typecast(obj.position(:,p) ,'uint8'); off=off+12; |
| 400 |
bytes(off:off+11,p) = typecast(obj.read_dir(:,p) ,'uint8'); off=off+12; |
| 401 |
bytes(off:off+11,p) = typecast(obj.phase_dir(:,p) ,'uint8'); off=off+12; |
| 402 |
bytes(off:off+11,p) = typecast(obj.slice_dir(:,p) ,'uint8'); off=off+12; |
| 403 |
bytes(off:off+11,p) = typecast(obj.patient_table_position(:,p),'uint8'); off=off+12; |
| 404 |
bytes(off:off+1,p) = typecast(obj.idx.kspace_encode_step_1(p),'uint8'); off=off+2; |
| 405 |
bytes(off:off+1,p) = typecast(obj.idx.kspace_encode_step_2(p),'uint8'); off=off+2; |
| 406 |
bytes(off:off+1,p) = typecast(obj.idx.average(p) ,'uint8'); off=off+2; |
| 407 |
bytes(off:off+1,p) = typecast(obj.idx.slice(p) ,'uint8'); off=off+2; |
| 408 |
bytes(off:off+1,p) = typecast(obj.idx.contrast(p) ,'uint8'); off=off+2; |
| 409 |
bytes(off:off+1,p) = typecast(obj.idx.phase(p) ,'uint8'); off=off+2; |
| 410 |
bytes(off:off+1,p) = typecast(obj.idx.repetition(p) ,'uint8'); off=off+2; |
| 411 |
bytes(off:off+1,p) = typecast(obj.idx.set(p) ,'uint8'); off=off+2; |
| 412 |
bytes(off:off+1,p) = typecast(obj.idx.segment(p) ,'uint8'); off=off+2; |
| 413 |
bytes(off:off+15,p) = typecast(obj.idx.user(:,p) ,'uint8'); off=off+16; |
| 414 |
bytes(off:off+31,p) = typecast(obj.user_int(:,p) ,'uint8'); off=off+32; |
| 415 |
bytes(off:off+31,p) = typecast(obj.user_float(:,p) ,'uint8'); |
| 416 |
end |
| 417 |
end |
| 418 |
|
| 419 |
function obj = check(obj) |
| 420 |
% Check and fix the obj types |
| 421 |
|
| 422 |
% Check the number of elements for each entry |
| 423 |
N = obj.getNumber(); |
| 424 |
if (size(obj.flags) ~= N) |
| 425 |
error('Size of flags is not correct.'); |
| 426 |
end |
| 427 |
if ((size(obj.measurement_uid,1) ~= 1) || ... |
| 428 |
(size(obj.measurement_uid,2) ~= N)) |
| 429 |
error('Size of measurement_uid is not correct.'); |
| 430 |
end |
| 431 |
if ((size(obj.scan_counter,1) ~= 1) || ... |
| 432 |
(size(obj.scan_counter,2) ~= N)) |
| 433 |
error('Size of scan_counter is not correct.'); |
| 434 |
end |
| 435 |
if ((size(obj.acquisition_time_stamp,1) ~= 1) || ... |
| 436 |
(size(obj.acquisition_time_stamp,2) ~= N)) |
| 437 |
error('Size of acquisition_time_stamp is not correct.'); |
| 438 |
end |
| 439 |
if ((size(obj.physiology_time_stamp,1) ~= 3) || ... |
| 440 |
(size(obj.physiology_time_stamp,2) ~= N)) |
| 441 |
error('Size of physiology_time_stamp is not correct.'); |
| 442 |
end |
| 443 |
if ((size(obj.number_of_samples,1) ~= 1) || ... |
| 444 |
(size(obj.number_of_samples,2) ~= N)) |
| 445 |
error('Size of number_of_samples is not correct.'); |
| 446 |
end |
| 447 |
|
| 448 |
if ((size(obj.available_channels,1) ~= 1) || ... |
| 449 |
(size(obj.available_channels,2) ~= N)) |
| 450 |
error('Size of available_channels is not correct.'); |
| 451 |
end |
| 452 |
if ((size(obj.active_channels,1) ~= 1) || ... |
| 453 |
(size(obj.active_channels,2) ~= N)) |
| 454 |
error('Size of active_channels is not correct.'); |
| 455 |
end |
| 456 |
if ((size(obj.channel_mask,1) ~= 16) || ... |
| 457 |
(size(obj.channel_mask,2) ~= N)) |
| 458 |
error('Size of channel_mask is not correct.'); |
| 459 |
end |
| 460 |
if ((size(obj.discard_pre,1) ~= 1) || ... |
| 461 |
(size(obj.discard_pre,2) ~= N)) |
| 462 |
error('Size of discard_pre is not correct.'); |
| 463 |
end |
| 464 |
if ((size(obj.discard_post,1) ~= 1) || ... |
| 465 |
(size(obj.discard_post,2) ~= N)) |
| 466 |
error('Size of discard_post is not correct.'); |
| 467 |
end |
| 468 |
if ((size(obj.center_sample,1) ~= 1) || ... |
| 469 |
(size(obj.center_sample,2) ~= N)) |
| 470 |
error('Size of center_sample is not correct.'); |
| 471 |
end |
| 472 |
if ((size(obj.encoding_space_ref,1) ~= 1) || ... |
| 473 |
(size(obj.encoding_space_ref,2) ~= N)) |
| 474 |
error('Size of encoding_space_ref is not correct.'); |
| 475 |
end |
| 476 |
if ((size(obj.trajectory_dimensions,1) ~= 1) || ... |
| 477 |
(size(obj.trajectory_dimensions,2) ~= N)) |
| 478 |
error('Size of trajectory_dimensions is not correct.'); |
| 479 |
end |
| 480 |
if ((size(obj.sample_time_us,1) ~= 1) || ... |
| 481 |
(size(obj.sample_time_us,2) ~= N)) |
| 482 |
error('Size of sample_time_us is not correct.'); |
| 483 |
end |
| 484 |
if ((size(obj.position,1) ~= 3) || ... |
| 485 |
(size(obj.position,2) ~= N)) |
| 486 |
error('Size of position is not correct.'); |
| 487 |
end |
| 488 |
if ((size(obj.read_dir,1) ~= 3) || ... |
| 489 |
(size(obj.read_dir,2) ~= N)) |
| 490 |
error('Size of read_dir is not correct.'); |
| 491 |
end |
| 492 |
if ((size(obj.phase_dir,1) ~= 3) || ... |
| 493 |
(size(obj.phase_dir,2) ~= N)) |
| 494 |
error('Size of phase_dir is not correct.'); |
| 495 |
end |
| 496 |
if ((size(obj.slice_dir,1) ~= 3) || ... |
| 497 |
(size(obj.slice_dir,2) ~= N)) |
| 498 |
error('Size of slice_dir is not correct.'); |
| 499 |
end |
| 500 |
if ((size(obj.patient_table_position,1) ~= 3) || ... |
| 501 |
(size(obj.patient_table_position,2) ~= N)) |
| 502 |
error('Size of patient_table_position is not correct.'); |
| 503 |
end |
| 504 |
if ((size(obj.idx.kspace_encode_step_1,1) ~= 1) || ... |
| 505 |
(size(obj.idx.kspace_encode_step_1,2) ~= N)) |
| 506 |
error('Size of kspace_encode_step_1 is not correct.'); |
| 507 |
end |
| 508 |
if ((size(obj.idx.kspace_encode_step_2,1) ~= 1) || ... |
| 509 |
(size(obj.idx.kspace_encode_step_2,2) ~= N)) |
| 510 |
error('Size of kspace_encode_step_2 is not correct.'); |
| 511 |
end |
| 512 |
if ((size(obj.idx.average,1) ~= 1) || ... |
| 513 |
(size(obj.idx.average,2) ~= N)) |
| 514 |
error('Size of idx.average is not correct.'); |
| 515 |
end |
| 516 |
if ((size(obj.idx.slice,1) ~= 1) || ... |
| 517 |
(size(obj.idx.slice,2) ~= N)) |
| 518 |
error('Size of idx.slice is not correct.'); |
| 519 |
end |
| 520 |
if ((size(obj.idx.contrast,1) ~= 1) || ... |
| 521 |
(size(obj.idx.contrast,2) ~= N)) |
| 522 |
error('Size of idx.contrast is not correct.'); |
| 523 |
end |
| 524 |
if ((size(obj.idx.phase,1) ~= 1) || ... |
| 525 |
(size(obj.idx.phase,2) ~= N)) |
| 526 |
error('Size of idx.phase is not correct.'); |
| 527 |
end |
| 528 |
if ((size(obj.idx.repetition,1) ~= 1) || ... |
| 529 |
(size(obj.idx.repetition,2) ~= N)) |
| 530 |
error('Size of idx.repetition is not correct.'); |
| 531 |
end |
| 532 |
if ((size(obj.idx.set,1) ~= 1) || ... |
| 533 |
(size(obj.idx.set,2) ~= N)) |
| 534 |
error('Size of idx.set is not correct.'); |
| 535 |
end |
| 536 |
if ((size(obj.idx.segment,1) ~= 1) || ... |
| 537 |
(size(obj.idx.segment,2) ~= N)) |
| 538 |
error('Size of idx.segment is not correct.'); |
| 539 |
end |
| 540 |
if ((size(obj.idx.user,1) ~= 8) || ... |
| 541 |
(size(obj.idx.user,2) ~= N)) |
| 542 |
error('Size of idx.user is not correct.'); |
| 543 |
end |
| 544 |
if ((size(obj.user_int,1) ~= 8) || ... |
| 545 |
(size(obj.user_int,2) ~= N)) |
| 546 |
error('Size of user_int is not correct.'); |
| 547 |
end |
| 548 |
if ((size(obj.user_float,1) ~= 8) || ... |
| 549 |
(size(obj.user_float,2) ~= N)) |
| 550 |
error('Size of user_float is not correct.'); |
| 551 |
end |
| 552 |
|
| 553 |
% Fix the type of all the elements |
| 554 |
obj.version = uint16(obj.version); |
| 555 |
obj.flags = uint64(obj.flags); |
| 556 |
obj.measurement_uid = uint32(obj.measurement_uid); |
| 557 |
obj.scan_counter = uint32(obj.scan_counter); |
| 558 |
obj.acquisition_time_stamp = uint32(obj.acquisition_time_stamp); |
| 559 |
obj.physiology_time_stamp = uint32(obj.physiology_time_stamp); |
| 560 |
obj.number_of_samples = uint16(obj.number_of_samples); |
| 561 |
obj.available_channels = uint16(obj.available_channels); |
| 562 |
obj.active_channels = uint16(obj.active_channels); |
| 563 |
obj.channel_mask = uint64(obj.channel_mask); |
| 564 |
obj.discard_pre = uint16(obj.discard_pre); |
| 565 |
obj.discard_post = uint16(obj.discard_post); |
| 566 |
obj.center_sample = uint16(obj.center_sample); |
| 567 |
obj.encoding_space_ref = uint16(obj.encoding_space_ref); |
| 568 |
obj.trajectory_dimensions = uint16(obj.trajectory_dimensions); |
| 569 |
obj.sample_time_us = single(obj.sample_time_us); |
| 570 |
obj.position = single(obj.position); |
| 571 |
obj.read_dir = single(obj.read_dir); |
| 572 |
obj.phase_dir = single(obj.phase_dir); |
| 573 |
obj.slice_dir = single(obj.slice_dir); |
| 574 |
obj.patient_table_position = single(obj.patient_table_position); |
| 575 |
obj.idx.kspace_encode_step_1 = uint16(obj.idx.kspace_encode_step_1); |
| 576 |
obj.idx.kspace_encode_step_2 = uint16(obj.idx.kspace_encode_step_2); |
| 577 |
obj.idx.average = uint16(obj.idx.average); |
| 578 |
obj.idx.slice = uint16(obj.idx.slice); |
| 579 |
obj.idx.contrast = uint16(obj.idx.contrast); |
| 580 |
obj.idx.phase = uint16(obj.idx.phase); |
| 581 |
obj.idx.repetition = uint16(obj.idx.repetition); |
| 582 |
obj.idx.set = uint16(obj.idx.set); |
| 583 |
obj.idx.segment = uint16(obj.idx.segment); |
| 584 |
obj.idx.user = uint16(obj.idx.user); |
| 585 |
obj.user_int = int32(obj.user_int); |
| 586 |
obj.user_float = single(obj.user_float); |
| 587 |
|
| 588 |
end |
| 589 |
|
| 590 |
function ret = flagIsSet(obj, flag, range) |
| 591 |
% bool = obj.flagIsSet(flag, range) |
| 592 |
|
| 593 |
if nargin < 3 |
| 594 |
range = 1:obj.getNumber; |
| 595 |
end |
| 596 |
if isa(flag, 'char') |
| 597 |
b = obj.FLAGS.(flag); |
| 598 |
elseif (flag>0) |
| 599 |
b = uint64(flag); |
| 600 |
else |
| 601 |
error('Flag is of the wrong type.'); |
| 602 |
end |
| 603 |
bitmask = bitshift(uint64(1),(b-1)); |
| 604 |
ret = zeros(size(range)); |
| 605 |
for p = 1:length(range) |
| 606 |
ret(p) = (bitand(obj.flags(range(p)), bitmask)>0); |
| 607 |
end |
| 608 |
end |
| 609 |
|
| 610 |
function flagSet(obj, flag, range) |
| 611 |
if nargin < 3 |
| 612 |
range = 1:obj.getNumber; |
| 613 |
end |
| 614 |
if isa(flag, 'char') |
| 615 |
b = obj.FLAGS.(flag); |
| 616 |
elseif (flag>0) |
| 617 |
b = uint64(flag); |
| 618 |
else |
| 619 |
error('Flag is of the wrong type.'); |
| 620 |
end |
| 621 |
bitmask = bitshift(uint64(1),(b-1)); |
| 622 |
|
| 623 |
alreadyset = obj.flagIsSet(flag,range); |
| 624 |
for p = 1:length(range) |
| 625 |
if ~alreadyset(p) |
| 626 |
obj.flags(range(p)) = obj.flags(range(p)) + bitmask; |
| 627 |
end |
| 628 |
end |
| 629 |
end |
| 630 |
|
| 631 |
function flagClear(obj, flag, range) |
| 632 |
if nargin < 3 |
| 633 |
range = 1:obj.getNumber; |
| 634 |
end |
| 635 |
|
| 636 |
if isa(flag, 'char') |
| 637 |
b = obj.FLAGS.(flag); |
| 638 |
elseif (flag>0) |
| 639 |
b = uint64(flag); |
| 640 |
else |
| 641 |
error('Flag is of the wrong type.'); |
| 642 |
end |
| 643 |
bitmask = bitshift(uint64(1),(b-1)); |
| 644 |
|
| 645 |
alreadyset = obj.flagIsSet(flag,range); |
| 646 |
for p = 1:length(range) |
| 647 |
if alreadyset(p) |
| 648 |
obj.flags(range(p)) = obj.flags(range(p)) - bitmask; |
| 649 |
end |
| 650 |
end |
| 651 |
end |
| 652 |
|
| 653 |
function flagClearAll(obj, range) |
| 654 |
if nargin < 2 |
| 655 |
range = 1:obj.getNumber; |
| 656 |
end |
| 657 |
obj.flags(range) = zeros(1,length(range),'uint64'); |
| 658 |
end |
| 659 |
|
| 660 |
end |
| 661 |
|
| 662 |
end |