| 1 |
classdef ImageHeader < handle |
| 2 |
|
| 3 |
properties |
| 4 |
|
| 5 |
version = uint16([]); % First unsigned int indicates the version % |
| 6 |
data_type = uint16([]); % e.g. unsigned short, float, complex float, etc. */ |
| 7 |
flags = uint64([]); % bit field with flags % |
| 8 |
measurement_uid = uint32([]); % Unique ID for the measurement % |
| 9 |
matrix_size = uint16([]); % Pixels in the 3 spatial dimensions |
| 10 |
field_of_view = single([]); % Size (in mm) of the 3 spatial dimensions % |
| 11 |
channels = uint16([]); % Number of receive channels % |
| 12 |
position = single([]); % Three-dimensional spatial offsets from isocenter % |
| 13 |
read_dir = single([]); % Directional cosines of the readout/frequency encoding % |
| 14 |
phase_dir = single([]); % Directional cosines of the phase encoding % |
| 15 |
slice_dir = single([]); % Directional cosines of the slice % |
| 16 |
patient_table_position = single([]); % Patient table off-center % |
| 17 |
average = uint16([]); % e.g. signal average number % |
| 18 |
slice = uint16([]); % e.g. imaging slice number % |
| 19 |
contrast = uint16([]); % e.g. echo number in multi-echo % |
| 20 |
phase = uint16([]); % e.g. cardiac phase number % |
| 21 |
repetition = uint16([]); % e.g. dynamic number for dynamic scanning % |
| 22 |
set = uint16([]); % e.g. flow encodning set % |
| 23 |
acquisition_time_stamp = uint32([]); % Acquisition clock % |
| 24 |
physiology_time_stamp = uint32([]); % Physiology time stamps, e.g. ecg, breating, etc. % |
| 25 |
image_type = uint16([]); % e.g. magnitude, phase, complex, real, imag, etc. % |
| 26 |
image_index = uint16([]); % e.g. image number in series of images % |
| 27 |
image_series_index = uint16([]); % e.g. series number % |
| 28 |
user_int = int32([]); % Free user parameters % |
| 29 |
user_float = single([]); % Free user parameters % |
| 30 |
attribute_string_len = uint32([]); |
| 31 |
|
| 32 |
end |
| 33 |
|
| 34 |
properties(Constant) |
| 35 |
FLAGS = struct( ... |
| 36 |
'IMAGE_IS_NAVIGATION_DATA', 1, ... |
| 37 |
'IMAGE_FIRST_IN_AVERAGE', 5, ... |
| 38 |
'IMAGE_LAST_IN_AVERAGE', 6, ... |
| 39 |
'IMAGE_FIRST_IN_SLICE', 7, ... |
| 40 |
'IMAGE_LAST_IN_SLICE', 8, ... |
| 41 |
'IMAGE_FIRST_IN_CONTRAST', 9, ... |
| 42 |
'IMAGE_LAST_IN_CONTRAST', 10, ... |
| 43 |
'IMAGE_FIRST_IN_PHASE', 11, ... |
| 44 |
'IMAGE_LAST_IN_PHASE', 12, ... |
| 45 |
'IMAGE_FIRST_IN_REPETITION', 13, ... |
| 46 |
'IMAGE_LAST_IN_REPETITION', 14, ... |
| 47 |
'IMAGE_FIRST_IN_SET', 15, ... |
| 48 |
'IMAGE_LAST_IN_SET', 16, ... |
| 49 |
'IMAGE_USER1', 57, ... |
| 50 |
'IMAGE_USER2', 58, ... |
| 51 |
'IMAGE_USER3', 59, ... |
| 52 |
'IMAGE_USER4', 60, ... |
| 53 |
'IMAGE_USER5', 61, ... |
| 54 |
'IMAGE_USER6', 62, ... |
| 55 |
'IMAGE_USER7', 63, ... |
| 56 |
'IMAGE_USER8', 64); |
| 57 |
|
| 58 |
DATA_TYPE = struct( ... |
| 59 |
'USHORT', uint16(1), ... |
| 60 |
'SHORT', uint16(2), ... |
| 61 |
'UINT', uint16(3), ... |
| 62 |
'INT', uint16(4), ... |
| 63 |
'FLOAT', uint16(5), ... |
| 64 |
'DOUBLE', uint16(6), ... |
| 65 |
'CXFLOAT', uint16(7), ... |
| 66 |
'CXDOUBLE', uint16(8)); |
| 67 |
|
| 68 |
IMAGE_TYPE = struct( ... |
| 69 |
'MAGNITUDE', uint16(1), ... |
| 70 |
'PHASE', uint16(2), ... |
| 71 |
'REAL', uint16(3), ... |
| 72 |
'IMAG', uint16(4), ... |
| 73 |
'COMPLEX', uint16(5)); |
| 74 |
|
| 75 |
end |
| 76 |
|
| 77 |
methods |
| 78 |
|
| 79 |
function obj = ImageHeader(arg) |
| 80 |
switch nargin |
| 81 |
case 0 |
| 82 |
% No argument constructor |
| 83 |
% initialize to a single image header |
| 84 |
extend(obj,1); |
| 85 |
|
| 86 |
case 1 |
| 87 |
% One argument constructor |
| 88 |
if isstruct(arg) |
| 89 |
% plain struct |
| 90 |
fromStruct(obj,arg); |
| 91 |
elseif (length(arg)==1 && ismrmrd.util.isInt(arg)) == 1 |
| 92 |
% number |
| 93 |
extend(obj,arg); |
| 94 |
elseif isa(arg,'uint8') |
| 95 |
% Byte array |
| 96 |
fromBytes(obj,arg); |
| 97 |
else |
| 98 |
% Unknown type |
| 99 |
error('Unknown argument type.') |
| 100 |
end |
| 101 |
|
| 102 |
otherwise |
| 103 |
error('Wrong number of arguments.') |
| 104 |
|
| 105 |
end |
| 106 |
end |
| 107 |
|
| 108 |
function nacq = getNumber(obj) |
| 109 |
nacq = length(obj.version); |
| 110 |
end |
| 111 |
|
| 112 |
function hdr = select(obj, range) |
| 113 |
% Return a copy of a range of image headers |
| 114 |
|
| 115 |
% create an empty image header |
| 116 |
M = length(range); |
| 117 |
hdr = ismrmrd.ImageHeader(M); |
| 118 |
|
| 119 |
% Fill |
| 120 |
hdr.version = obj.version(range); |
| 121 |
hdr.flags = obj.flags(range); |
| 122 |
hdr.measurement_uid = obj.measurement_uid(range); |
| 123 |
hdr.matrix_size = obj.matrix_size(:,range); |
| 124 |
hdr.field_of_view = obj.field_of_view(:,range); |
| 125 |
hdr.channels = obj.channels(:,range); |
| 126 |
hdr.position = obj.position(:,range); |
| 127 |
hdr.read_dir = obj.read_dir(:,range); |
| 128 |
hdr.phase_dir = obj.phase_dir(:,range); |
| 129 |
hdr.slice_dir = obj.slice_dir(:,range); |
| 130 |
hdr.patient_table_position = obj.patient_table_position(:,range); |
| 131 |
hdr.average = obj.average(range); |
| 132 |
hdr.slice = obj.slice(range); |
| 133 |
hdr.contrast = obj.contrast(range); |
| 134 |
hdr.phase = obj.phase(range); |
| 135 |
hdr.repetition = obj.repetition(range); |
| 136 |
hdr.set = obj.set(range); |
| 137 |
hdr.acquisition_time_stamp = obj.acquisition_time_stamp(range); |
| 138 |
hdr.physiology_time_stamp = obj.physiology_time_stamp(:,range); |
| 139 |
hdr.data_type = obj.data_type(range); |
| 140 |
hdr.image_type = obj.image_type(range); |
| 141 |
hdr.image_index = obj.image_index(range); |
| 142 |
hdr.image_series_index = obj.image_series_index(range); |
| 143 |
hdr.user_int = obj.user_int(:,range); |
| 144 |
hdr.user_float = obj.user_float(:,range); |
| 145 |
hdr.attribute_string_len = obj.attribute_string_len(:,range); |
| 146 |
|
| 147 |
end |
| 148 |
|
| 149 |
function extend(obj,N) |
| 150 |
% Extend with blank header |
| 151 |
|
| 152 |
range = obj.getNumber + (1:N); |
| 153 |
obj.version(1,range) = zeros(1,N,'uint16'); |
| 154 |
obj.flags(1,range) = zeros(1,N,'uint64'); |
| 155 |
obj.measurement_uid(1,range) = zeros(1,N,'uint32'); |
| 156 |
obj.matrix_size(1:3,range) = zeros(3,N,'uint16'); |
| 157 |
obj.field_of_view(1:3,range) = zeros(3,N,'single'); |
| 158 |
obj.channels(1,range) = zeros(1,N,'uint16'); |
| 159 |
obj.position(1:3,range) = zeros(3,N,'single'); |
| 160 |
obj.read_dir(1:3,range) = zeros(3,N,'single'); |
| 161 |
obj.phase_dir(1:3,range) = zeros(3,N,'single'); |
| 162 |
obj.slice_dir(1:3,range) = zeros(3,N,'single'); |
| 163 |
obj.patient_table_position(1:3,range) = zeros(3,N,'single'); |
| 164 |
obj.average(1,range) = zeros(1,N,'uint16'); |
| 165 |
obj.slice(1,range) = zeros(1,N,'uint16'); |
| 166 |
obj.contrast(1,range) = zeros(1,N,'uint16'); |
| 167 |
obj.phase(1,range) = zeros(1,N,'uint16'); |
| 168 |
obj.repetition(1,range) = zeros(1,N,'uint16'); |
| 169 |
obj.set(1,range) = zeros(1,N,'uint16'); |
| 170 |
obj.acquisition_time_stamp(1,range) = zeros(1,N,'uint32'); |
| 171 |
obj.physiology_time_stamp(1:3,range) = zeros(3,N,'uint32'); |
| 172 |
obj.data_type(1,range) = zeros(1,N,'uint16'); |
| 173 |
obj.image_type(1,range) = zeros(1,N,'uint16'); |
| 174 |
obj.image_index(1,range) = zeros(1,N,'uint16'); |
| 175 |
obj.image_series_index(1,range) = zeros(1,N,'uint16'); |
| 176 |
obj.user_int(1:8,range) = zeros(8,N,'int32'); |
| 177 |
obj.user_float(1:8,range) = zeros(8,N,'single'); |
| 178 |
obj.attribute_string_len = zeros(1,N,'uint32'); |
| 179 |
end |
| 180 |
|
| 181 |
function append(obj, head) |
| 182 |
Nstart = obj.getNumber + 1; |
| 183 |
Nend = obj.getNumber + length(head.version); |
| 184 |
Nrange = Nstart:Nend; |
| 185 |
obj.version(Nrange) = hdr.version; |
| 186 |
obj.flags(Nrange) = hdr.flags; |
| 187 |
obj.measurement_uid(Nrange) = hdr.measurement_uid; |
| 188 |
obj.matrix_size(:,Nrange) = hdr.matrix_size; |
| 189 |
obj.field_of_view(:,Nrange) = hdr.field_of_view; |
| 190 |
obj.channels(Nrange) = hdr.channels; |
| 191 |
obj.position(:,Nrange) = hdr.position; |
| 192 |
obj.read_dir(:,Nrange) = hdr.read_dir; |
| 193 |
obj.phase_dir(:,Nrange) = hdr.phase_dir; |
| 194 |
obj.slice_dir(:,Nrange) = hdr.slice_dir; |
| 195 |
obj.patient_table_position(:,Nrange) = hdr.patient_table_position; |
| 196 |
obj.average(Nrange) = hdr.average; |
| 197 |
obj.slice(Nrange) = hdr.slice; |
| 198 |
obj.contrast(Nrange) = hdr.contrast; |
| 199 |
obj.phase(Nrange) = hdr.phase; |
| 200 |
obj.repetition(Nrange) = hdr.repetition; |
| 201 |
obj.set(Nrange) = hdr.set; |
| 202 |
obj.acquisition_time_stamp(Nrange) = hdr.acquisition_time_stamp; |
| 203 |
obj.physiology_time_stamp(:,Nrange) = hdr.physiology_time_stamp; |
| 204 |
obj.data_type(Nrange) = hdr.data_type; |
| 205 |
obj.image_type(Nrange) = hdr.image_type; |
| 206 |
obj.image_index(Nrange) = hdr.image_index; |
| 207 |
obj.image_series_index(Nrange) = hdr.image_series_index; |
| 208 |
obj.user_int(:,Nrange) = hdr.user_int; |
| 209 |
obj.user_float(:,Nrange) = hdr.user_float; |
| 210 |
obj.attribute_string_len(Nrange) = hdr.attribute_string_len; |
| 211 |
|
| 212 |
end |
| 213 |
|
| 214 |
function fromStruct(obj, hdr) |
| 215 |
%warning! no error checking |
| 216 |
obj.version = hdr.version; |
| 217 |
obj.flags = hdr.flags; |
| 218 |
obj.measurement_uid = hdr.measurement_uid; |
| 219 |
obj.matrix_size = hdr.matrix_size; |
| 220 |
obj.field_of_view = hdr.field_of_view; |
| 221 |
obj.channels = hdr.channels; |
| 222 |
obj.position = hdr.position; |
| 223 |
obj.read_dir = hdr.read_dir; |
| 224 |
obj.phase_dir = hdr.phase_dir; |
| 225 |
obj.slice_dir = hdr.slice_dir; |
| 226 |
obj.patient_table_position = hdr.patient_table_position; |
| 227 |
obj.average = hdr.average; |
| 228 |
obj.slice = hdr.slice; |
| 229 |
obj.contrast = hdr.contrast; |
| 230 |
obj.phase = hdr.phase; |
| 231 |
obj.repetition = hdr.repetition; |
| 232 |
obj.set = hdr.set; |
| 233 |
obj.acquisition_time_stamp = hdr.acquisition_time_stamp; |
| 234 |
obj.physiology_time_stamp = hdr.physiology_time_stamp; |
| 235 |
obj.data_type = hdr.data_type; |
| 236 |
obj.image_type = hdr.image_type; |
| 237 |
obj.image_index = hdr.image_index; |
| 238 |
obj.image_series_index = hdr.image_series_index; |
| 239 |
obj.user_int = hdr.user_int; |
| 240 |
obj.user_float = hdr.user_float; |
| 241 |
obj.attribute_string_len = hdr.attribute_string_len; |
| 242 |
end |
| 243 |
|
| 244 |
function hdr = toStruct(obj) |
| 245 |
%warning! no error checking |
| 246 |
hdr = struct(); |
| 247 |
hdr.version = obj.version; |
| 248 |
hdr.flags = obj.flags; |
| 249 |
hdr.measurement_uid = obj.measurement_uid; |
| 250 |
hdr.matrix_size = obj.matrix_size; |
| 251 |
hdr.field_of_view = obj.field_of_view; |
| 252 |
hdr.channels = obj.channels; |
| 253 |
hdr.position = obj.position; |
| 254 |
hdr.read_dir = obj.read_dir; |
| 255 |
hdr.phase_dir = obj.phase_dir; |
| 256 |
hdr.slice_dir = obj.slice_dir; |
| 257 |
hdr.patient_table_position = obj.patient_table_position; |
| 258 |
hdr.average = obj.average; |
| 259 |
hdr.slice = obj.slice; |
| 260 |
hdr.contrast = obj.contrast; |
| 261 |
hdr.phase = obj.phase; |
| 262 |
hdr.repetition = obj.repetition; |
| 263 |
hdr.set = obj.set; |
| 264 |
hdr.acquisition_time_stamp = obj.acquisition_time_stamp; |
| 265 |
hdr.physiology_time_stamp = obj.physiology_time_stamp; |
| 266 |
hdr.data_type = obj.data_type; |
| 267 |
hdr.image_type = obj.image_type; |
| 268 |
hdr.image_index = obj.image_index; |
| 269 |
hdr.image_series_index = obj.image_series_index; |
| 270 |
hdr.user_int = obj.user_int; |
| 271 |
hdr.user_float = obj.user_float; |
| 272 |
hdr.attribute_string_len = obj.attribute_string_len; |
| 273 |
end |
| 274 |
|
| 275 |
function fromBytes(obj, bytearray) |
| 276 |
% Convert from a byte array to an ISMRMRD ImageHeader |
| 277 |
% This conforms to the memory layout of the C-struct |
| 278 |
if size(bytearray,1) ~= 198 |
| 279 |
error('Wrong number of bytes for ImageHeader.') |
| 280 |
end |
| 281 |
N = size(bytearray,2); |
| 282 |
for p = 1:N |
| 283 |
obj.version(p) = typecast(bytearray(1:2,p), 'uint16'); |
| 284 |
obj.data_type(p) = typecast(bytearray(3:4,p), 'uint16'); |
| 285 |
obj.flags(p) = typecast(bytearray(5:12,p), 'uint64'); |
| 286 |
obj.measurement_uid(p) = typecast(bytearray(13:16,p), 'uint32'); |
| 287 |
obj.matrix_size(:,p) = typecast(bytearray(17:22,p), 'uint16'); |
| 288 |
obj.field_of_view(:,p) = typecast(bytearray(23:34,p), 'single'); |
| 289 |
obj.channels(p) = typecast(bytearray(35:36,p), 'uint16'); |
| 290 |
obj.position(:,p) = typecast(bytearray(37:48,p), 'single'); |
| 291 |
obj.read_dir(:,p) = typecast(bytearray(49:60,p), 'single'); |
| 292 |
obj.phase_dir(:,p) = typecast(bytearray(61:72,p), 'single'); |
| 293 |
obj.slice_dir(:,p) = typecast(bytearray(73:84,p), 'single'); |
| 294 |
obj.patient_table_position(:,p) = typecast(bytearray(85:96,p), 'single'); |
| 295 |
obj.average(p) = typecast(bytearray(97:98,p), 'uint16'); |
| 296 |
obj.slice(p) = typecast(bytearray(99:100,p), 'uint16'); |
| 297 |
obj.contrast(p) = typecast(bytearray(101:102,p), 'uint16'); |
| 298 |
obj.phase(p) = typecast(bytearray(103:104,p), 'uint16'); |
| 299 |
obj.repetition(p) = typecast(bytearray(105:106,p), 'uint16'); |
| 300 |
obj.set(p) = typecast(bytearray(107:108,p), 'uint16'); |
| 301 |
obj.acquisition_time_stamp(p) = typecast(bytearray(109:112,p), 'uint32'); |
| 302 |
obj.physiology_time_stamp(:,p) = typecast(bytearray(113:124,p), 'uint32'); |
| 303 |
obj.image_type(p) = typecast(bytearray(125:126,p), 'uint16'); |
| 304 |
obj.image_index(p) = typecast(bytearray(127:128,p), 'uint16'); |
| 305 |
obj.image_series_index(p) = typecast(bytearray(129:130,p), 'uint16'); |
| 306 |
obj.user_int(:,p) = typecast(bytearray(131:162,p), 'uint32'); |
| 307 |
obj.user_float(:,p) = typecast(bytearray(163:194,p), 'single'); |
| 308 |
obj.attribute_string_len = typecast(bytearray(195:198,p), 'uint32'); |
| 309 |
|
| 310 |
end |
| 311 |
end |
| 312 |
|
| 313 |
function bytes = toBytes(obj) |
| 314 |
% Convert an ISMRMRD AcquisitionHeader to a byte array |
| 315 |
% This conforms to the memory layout of the C-struct |
| 316 |
|
| 317 |
N = obj.getNumber; |
| 318 |
bytes = zeros(198,N,'uint8'); |
| 319 |
for p = 1:N |
| 320 |
off = 1; |
| 321 |
bytes(off:off+1,p) = typecast(obj.version(p) ,'uint8'); off=off+2; |
| 322 |
bytes(off:off+1,p) = typecast(obj.data_type(p) ,'uint8'); off=off+2; |
| 323 |
bytes(off:off+7,p) = typecast(obj.flags(p) ,'uint8'); off=off+8; |
| 324 |
bytes(off:off+3,p) = typecast(obj.measurement_uid(p) ,'uint8'); off=off+4; |
| 325 |
bytes(off:off+5,p) = typecast(obj.matrix_size(:,p) ,'uint8'); off=off+6; |
| 326 |
bytes(off:off+11,p) = typecast(obj.field_of_view(:,p) ,'uint8'); off=off+12; |
| 327 |
bytes(off:off+1,p) = typecast(obj.channels(p) ,'uint8'); off=off+2; |
| 328 |
bytes(off:off+11,p) = typecast(obj.position(:,p) ,'uint8'); off=off+12; |
| 329 |
bytes(off:off+11,p) = typecast(obj.read_dir(:,p) ,'uint8'); off=off+12; |
| 330 |
bytes(off:off+11,p) = typecast(obj.phase_dir(:,p) ,'uint8'); off=off+12; |
| 331 |
bytes(off:off+11,p) = typecast(obj.slice_dir(:,p) ,'uint8'); off=off+12; |
| 332 |
bytes(off:off+11,p) = typecast(obj.patient_table_position(:,p),'uint8'); off=off+12; |
| 333 |
bytes(off:off+1,p) = typecast(obj.average(p) ,'uint8'); off=off+2; |
| 334 |
bytes(off:off+1,p) = typecast(obj.slice(p) ,'uint8'); off=off+2; |
| 335 |
bytes(off:off+1,p) = typecast(obj.contrast(p) ,'uint8'); off=off+2; |
| 336 |
bytes(off:off+1,p) = typecast(obj.phase(p) ,'uint8'); off=off+2; |
| 337 |
bytes(off:off+1,p) = typecast(obj.repetition(p) ,'uint8'); off=off+2; |
| 338 |
bytes(off:off+1,p) = typecast(obj.set(p) ,'uint8'); off=off+2; |
| 339 |
bytes(off:off+3,p) = typecast(obj.acquisition_time_stamp(p) ,'uint8'); off=off+4; |
| 340 |
|
| 341 |
bytes(off:off+11,p) = typecast(obj.physiology_time_stamp(:,p) ,'uint8'); off=off+12; |
| 342 |
|
| 343 |
bytes(off:off+1,p) = typecast(obj.image_type(p) ,'uint8'); off=off+2; |
| 344 |
bytes(off:off+1,p) = typecast(obj.image_index(p) ,'uint8'); off=off+2; |
| 345 |
bytes(off:off+1,p) = typecast(obj.image_series_index(p) ,'uint8'); off=off+2; |
| 346 |
bytes(off:off+31,p) = typecast(obj.user_int(:,p) ,'uint8'); off=off+32; |
| 347 |
bytes(off:off+31,p) = typecast(obj.user_float(:,p) ,'uint8'); off=off+32; |
| 348 |
bytes(off:off+3,p) = typecast(obj.attribute_string_len(:,p) ,'uint8'); |
| 349 |
|
| 350 |
end |
| 351 |
end |
| 352 |
|
| 353 |
function obj = check(obj) |
| 354 |
% Check and fix the obj types |
| 355 |
|
| 356 |
% Check the number of elements for each entry |
| 357 |
N = obj.getNumber(); |
| 358 |
if (size(obj.flags) ~= N) |
| 359 |
error('Size of flags is not correct.'); |
| 360 |
end |
| 361 |
if ((size(obj.measurement_uid,1) ~= 1) || ... |
| 362 |
(size(obj.measurement_uid,2) ~= N)) |
| 363 |
error('Size of measurement_uid is not correct.'); |
| 364 |
end |
| 365 |
if ((size(obj.matrix_size,1) ~= 3) || ... |
| 366 |
(size(obj.matrix_size,2) ~= N)) |
| 367 |
error('Size of matrix_size is not correct.'); |
| 368 |
end |
| 369 |
if ((size(obj.field_of_view,1) ~= 3) || ... |
| 370 |
(size(obj.field_of_view,2) ~= N)) |
| 371 |
error('Size of field_of_view is not correct.'); |
| 372 |
end |
| 373 |
if ((size(obj.channels,1) ~= 1) || ... |
| 374 |
(size(obj.channels,2) ~= N)) |
| 375 |
error('Size of field_of_view is not correct.'); |
| 376 |
end |
| 377 |
if ((size(obj.position,1) ~= 3) || ... |
| 378 |
(size(obj.position,2) ~= N)) |
| 379 |
error('Size of position is not correct.'); |
| 380 |
end |
| 381 |
if ((size(obj.read_dir,1) ~= 3) || ... |
| 382 |
(size(obj.read_dir,2) ~= N)) |
| 383 |
error('Size of read_dir is not correct.'); |
| 384 |
end |
| 385 |
if ((size(obj.phase_dir,1) ~= 3) || ... |
| 386 |
(size(obj.phase_dir,2) ~= N)) |
| 387 |
error('Size of phase_dir is not correct.'); |
| 388 |
end |
| 389 |
if ((size(obj.slice_dir,1) ~= 3) || ... |
| 390 |
(size(obj.slice_dir,2) ~= N)) |
| 391 |
error('Size of slice_dir is not correct.'); |
| 392 |
end |
| 393 |
if ((size(obj.patient_table_position,1) ~= 3) || ... |
| 394 |
(size(obj.patient_table_position,2) ~= N)) |
| 395 |
error('Size of patient_table_position is not correct.'); |
| 396 |
end |
| 397 |
if ((size(obj.average,1) ~= 1) || ... |
| 398 |
(size(obj.average,2) ~= N)) |
| 399 |
error('Size of average is not correct.'); |
| 400 |
end |
| 401 |
if ((size(obj.slice,1) ~= 1) || ... |
| 402 |
(size(obj.slice,2) ~= N)) |
| 403 |
error('Size of slice is not correct.'); |
| 404 |
end |
| 405 |
if ((size(obj.contrast,1) ~= 1) || ... |
| 406 |
(size(obj.contrast,2) ~= N)) |
| 407 |
error('Size of contrast is not correct.'); |
| 408 |
end |
| 409 |
if ((size(obj.phase,1) ~= 1) || ... |
| 410 |
(size(obj.phase,2) ~= N)) |
| 411 |
error('Size of phase is not correct.'); |
| 412 |
end |
| 413 |
if ((size(obj.repetition,1) ~= 1) || ... |
| 414 |
(size(obj.repetition,2) ~= N)) |
| 415 |
error('Size of repetition is not correct.'); |
| 416 |
end |
| 417 |
if ((size(obj.set,1) ~= 1) || ... |
| 418 |
(size(obj.set,2) ~= N)) |
| 419 |
error('Size of set is not correct.'); |
| 420 |
end |
| 421 |
if ((size(obj.acquisition_time_stamp,1) ~= 1) || ... |
| 422 |
(size(obj.acquisition_time_stamp,2) ~= N)) |
| 423 |
error('Size of acquisition_time_stamp is not correct.'); |
| 424 |
end |
| 425 |
if ((size(obj.physiology_time_stamp,1) ~= 3) || ... |
| 426 |
(size(obj.physiology_time_stamp,2) ~= N)) |
| 427 |
error('Size of physiology_time_stamp is not correct.'); |
| 428 |
end |
| 429 |
if ((size(obj.data_type,1) ~= 1) || ... |
| 430 |
(size(obj.data_type,2) ~= N)) |
| 431 |
error('Size of image_data_type is not correct.'); |
| 432 |
end |
| 433 |
if ((size(obj.image_type,1) ~= 1) || ... |
| 434 |
(size(obj.image_type,2) ~= N)) |
| 435 |
error('Size of image_type is not correct.'); |
| 436 |
end |
| 437 |
if ((size(obj.image_index,1) ~= 1) || ... |
| 438 |
(size(obj.image_index,2) ~= N)) |
| 439 |
error('Size of image_index is not correct.'); |
| 440 |
end |
| 441 |
if ((size(obj.image_series_index,1) ~= 1) || ... |
| 442 |
(size(obj.image_series_index,2) ~= N)) |
| 443 |
error('Size of image_series_index is not correct.'); |
| 444 |
end |
| 445 |
if ((size(obj.user_int,1) ~= 8) || ... |
| 446 |
(size(obj.user_int,2) ~= N)) |
| 447 |
error('Size of user_int is not correct.'); |
| 448 |
end |
| 449 |
if ((size(obj.user_float,1) ~= 8) || ... |
| 450 |
(size(obj.user_float,2) ~= N)) |
| 451 |
error('Size of user_float is not correct.'); |
| 452 |
end |
| 453 |
|
| 454 |
% Fix the type of all the elements |
| 455 |
obj.version = uint16(obj.version); |
| 456 |
obj.flags = uint64(obj.flags); |
| 457 |
obj.measurement_uid = uint32(obj.measurement_uid); |
| 458 |
obj.matrix_size = uint16(obj.matrix_size); |
| 459 |
obj.field_of_view = single(obj.field_of_view); |
| 460 |
obj.channels = uint16(obj.channels); |
| 461 |
obj.position = single(obj.position); |
| 462 |
obj.read_dir = single(obj.read_dir); |
| 463 |
obj.phase_dir = single(obj.phase_dir); |
| 464 |
obj.slice_dir = single(obj.slice_dir); |
| 465 |
obj.patient_table_position = single(obj.patient_table_position); |
| 466 |
obj.average = uint16(obj.average); |
| 467 |
obj.slice = uint16(obj.slice); |
| 468 |
obj.contrast = uint16(obj.contrast); |
| 469 |
obj.phase = uint16(obj.phase); |
| 470 |
obj.repetition = uint16(obj.repetition); |
| 471 |
obj.set = uint16(obj.set); |
| 472 |
obj.acquisition_time_stamp = uint32(obj.acquisition_time_stamp); |
| 473 |
obj.physiology_time_stamp = uint32(obj.physiology_time_stamp); |
| 474 |
obj.data_type = uint16(obj.data_type); |
| 475 |
obj.image_type = uint16(obj.image_type); |
| 476 |
obj.image_index = uint16(obj.image_index); |
| 477 |
obj.image_series_index = uint16(obj.image_series_index); |
| 478 |
obj.user_int = int32(obj.user_int); |
| 479 |
obj.user_float = single(obj.user_float); |
| 480 |
obj.attribute_string_len = uint32(obj.attribute_string_len); |
| 481 |
|
| 482 |
end |
| 483 |
|
| 484 |
function ret = flagIsSet(obj, flag, range) |
| 485 |
if nargin < 3 |
| 486 |
range = 1:obj.getNumber; |
| 487 |
end |
| 488 |
if isa(flag, 'char') |
| 489 |
b = obj.FLAGS.(flag); |
| 490 |
elseif (flag>0) |
| 491 |
b = uint64(flag); |
| 492 |
else |
| 493 |
error('Flag is of the wrong type.'); |
| 494 |
end |
| 495 |
bitmask = bitshift(uint64(1),(b-1)); |
| 496 |
ret = zeros(size(range)); |
| 497 |
for p = 1:length(range) |
| 498 |
ret(p) = (bitand(obj.flags(range(p)), bitmask)>0); |
| 499 |
end |
| 500 |
end |
| 501 |
|
| 502 |
function flagSet(obj, flag, range) |
| 503 |
if nargin < 3 |
| 504 |
range = 1:obj.getNumber; |
| 505 |
end |
| 506 |
if isa(flag, 'char') |
| 507 |
b = obj.FLAGS.(flag); |
| 508 |
elseif (flag>0) |
| 509 |
b = uint64(flag); |
| 510 |
else |
| 511 |
error('Flag is of the wrong type.'); |
| 512 |
end |
| 513 |
bitmask = bitshift(uint64(1),(b-1)); |
| 514 |
|
| 515 |
alreadyset = obj.flagIsSet(flag,range); |
| 516 |
for p = 1:length(range) |
| 517 |
if ~alreadyset(p) |
| 518 |
obj.flags(range(p)) = obj.flags(range(p)) + bitmask; |
| 519 |
end |
| 520 |
end |
| 521 |
end |
| 522 |
|
| 523 |
function flagClear(obj, flag, range) |
| 524 |
if nargin < 3 |
| 525 |
range = 1:obj.getNumber; |
| 526 |
end |
| 527 |
|
| 528 |
if isa(flag, 'char') |
| 529 |
b = obj.FLAGS.(flag); |
| 530 |
elseif (flag>0) |
| 531 |
b = uint64(flag); |
| 532 |
else |
| 533 |
error('Flag is of the wrong type.'); |
| 534 |
end |
| 535 |
bitmask = bitshift(uint64(1),(b-1)); |
| 536 |
|
| 537 |
alreadyset = obj.flagIsSet(flag,range); |
| 538 |
for p = 1:length(range) |
| 539 |
if alreadyset(p) |
| 540 |
obj.flags(range(p)) = obj.flags(range(p)) - bitmask; |
| 541 |
end |
| 542 |
end |
| 543 |
|
| 544 |
|
| 545 |
end |
| 546 |
|
| 547 |
end |
| 548 |
|
| 549 |
end |