[ismrmrd] 46/281: continuing to work on matlab implementation
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:00:54 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag ismrmrd0.5
in repository ismrmrd.
commit d72c928f2049dd4a25140610f2e22e4c42f2b17b
Author: Souheil Inati <souheil.inati at nih.gov>
Date: Thu Sep 13 10:03:28 2012 -0400
continuing to work on matlab implementation
---
matlab/+ismrmrd/Acquisition.m | 24 +++----
matlab/+ismrmrd/FlagBit.m | 8 +--
matlab/+ismrmrd/file.m | 142 ++++++++++++++++++++++++++++++++++++++++++
matlab/testread.m | 134 ++++++++++++++++++++-------------------
matlab/testrecon.m | 10 +++
5 files changed, 234 insertions(+), 84 deletions(-)
diff --git a/matlab/+ismrmrd/Acquisition.m b/matlab/+ismrmrd/Acquisition.m
index 3a26fb8..5d15dc7 100644
--- a/matlab/+ismrmrd/Acquisition.m
+++ b/matlab/+ismrmrd/Acquisition.m
@@ -4,39 +4,39 @@ classdef Acquisition
% Properties
properties
- head_ = ismrmrd.AcquisitionHeader;
- traj_ = [];
- data_ = [];
+ head = ismrmrd.AcquisitionHeader;
+ traj = [];
+ data = [];
end % Properties
% Methods
methods
- function obj = set.head_(obj,v)
- obj.head_ = v;
+ function obj = set.head(obj,v)
+ obj.head = v;
end
- function obj = set.traj_(obj,v)
- obj.traj_ = single(v);
+ function obj = set.traj(obj,v)
+ obj.traj = single(v);
end
- function obj = set.data_(obj,v)
+ function obj = set.data(obj,v)
if isreal(v)
- obj.data_ = single(v(1:2:end) + 1j*v(2:2:end));
+ obj.data = single(v(1:2:end) + 1j*v(2:2:end));
else
- obj.data_ = single(v);
+ obj.data = single(v);
end
end
function b = isFlagSet(obj,flag)
bitflag = ismrmrd.FlagBit(flag);
- b = bitflag.isSet(obj.head_.flag);
+ b = bitflag.isSet(obj.head.flag);
end
function obj = setFlag(obj,flag)
bitflag = ismrmrd.FlagBit(flag);
- obj.head_.flag = bitor(obj.head_.flag, bitflag.bitmask_);
+ obj.head.flag = bitor(obj.head.flag, bitflag.bitmask);
end
end % Methods
diff --git a/matlab/+ismrmrd/FlagBit.m b/matlab/+ismrmrd/FlagBit.m
index 4ef263f..1432238 100644
--- a/matlab/+ismrmrd/FlagBit.m
+++ b/matlab/+ismrmrd/FlagBit.m
@@ -1,7 +1,7 @@
classdef FlagBit
properties
- bitmask_ = uint64(0);
+ bitmask = uint64(0);
end
methods
@@ -16,12 +16,12 @@ classdef FlagBit
methods
- function obj = set.bitmask_(obj,b)
- obj.bitmask_ = uint64(b);
+ function obj = set.bitmask(obj,b)
+ obj.bitmask = uint64(b);
end % bitmask_ set function
function b = isSet(obj,m)
- if (bitand(obj.bitmask_, uint64(m))>0)
+ if (bitand(obj.bitmask, uint64(m))>0)
b = true;
else
b = false;
diff --git a/matlab/+ismrmrd/file.m b/matlab/+ismrmrd/file.m
new file mode 100644
index 0000000..fb4aa5e
--- /dev/null
+++ b/matlab/+ismrmrd/file.m
@@ -0,0 +1,142 @@
+% Acquisition
+classdef file
+
+ properties
+ fid = -1;
+ filename = '';
+ xml = ''; % remove this and replace with a get method
+ datapath = '';
+ xmlpath = '';
+ end
+
+ methods
+
+ function obj = file(filename,groupname)
+
+ % If the file exists, open it for read/write
+ % otherwise, create it
+ if exist(filename,'file')
+ obj.fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT');
+ else
+ fcpl = H5P.create('H5P_FILE_CREATE');
+ obj.fid = H5F.create(filename,'H5F_ACC_TRUNC',fcpl,'H5P_DEFAULT');
+ H5P.close(fcpl);
+ end
+
+ % Set the group name
+ % default is dataset
+ if nargin == 1
+ groupname = 'dataset';
+ end
+ % Set the paths
+ grouppath = ['/' groupname];
+ obj.xmlpath = ['/' groupname '/xml'];
+ obj.datapath = ['/' groupname '/data'];
+
+ % Check if the group exists
+ % if it does not exist, create it
+ lapl_id=H5P.create('H5P_LINK_ACCESS');
+ if (H5L.exists(obj.fid,grouppath,lapl_id) == 0)
+ group_id = H5G.create(obj.fid, grouppath, 0);
+ H5G.close(group_id);
+ end
+ H5P.close(lapl_id);
+
+ % Read the XML
+ obj.readxml();
+
+ % Check if the Data exists
+ % if it does not exist, create it
+ lapl_id=H5P.create('H5P_LINK_ACCESS');
+ if (H5L.exists(obj.fid, obj.datapath, lapl_id) == 0)
+ % Data does not exist
+ % create with rank 2, unlimited, and set the chunk size
+ dims = [1 1];
+ maxdims = [H5ML.get_constant_value('H5S_UNLIMITED') 1];
+ chunk = [1 1];
+ space = H5S.create_simple(2, dims, maxdims);
+ dcpl = H5P.create('H5P_DATASET_CREATE');
+ H5P.set_chunk (dcpl, chunk);
+ data_id = H5D.create(obj.fid, obj.datapath, ...
+ ismrmrd.hdf5_datatypes.getType_Acquisition, ...
+ space, dcpl);
+ H5D.close(data_id);
+ end
+ H5P.close(lapl_id);
+
+ end
+
+ % destructor
+ % is this necessary?
+ %function delete(obj)
+ % obj.close();
+ %end
+
+ function obj = close(obj)
+ H5F.close(obj.fid);
+ end
+
+ function obj = readxml(obj)
+
+ % Set variable length string type
+ xml_dtype = H5T.copy('H5T_C_S1');
+ H5T.set_size(xml_dtype,'H5T_VARIABLE');
+
+ % Check if the XML header exists
+ % if it does not exist, create it
+ % TODO: set it's value to the default
+ lapl_id=H5P.create('H5P_LINK_ACCESS');
+ if (H5L.exists(obj.fid,obj.xmlpath,lapl_id) == 0)
+ xml_dtype = H5T.copy('H5T_C_S1');
+ H5T.set_size(xml_dtype,'H5T_VARIABLE');
+ xml_space_id = H5S.create_simple (1, 1, []);
+ xml_id = H5D.create (obj.fid, obj.xmlpath, xml_dtype, xml_space_id, 'H5P_DEFAULT');
+ H5D.close(xml_id);
+ end
+ H5P.close(lapl_id);
+
+ % Open
+ xml_id = H5D.open(obj.fid, obj.xmlpath);
+
+ % Read the data
+ hdr = H5D.read(xml_id, xml_dtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');
+ obj.xml = hdr{1};
+
+ % Close the XML
+ H5D.close (xml_id);
+ end
+
+ function obj = writexml(obj,xmlstring)
+ % No validation is performed. You're on your own.
+
+ % Set variable length string type
+ xml_dtype = H5T.copy('H5T_C_S1');
+ H5T.set_size(xml_dtype,'H5T_VARIABLE');
+
+ % Check if the XML header exists
+ % if it does not exist, create it
+ lapl_id=H5P.create('H5P_LINK_ACCESS');
+ if (H5L.exists(obj.fid,obj.xmlpath,lapl_id) == 0)
+ xml_space_id = H5S.create_simple (1, 1, []);
+ xml_id = H5D.create (obj.fid, obj.xmlpath, xml_dtype, xml_space_id, 'H5P_DEFAULT');
+ H5S.close(xml_space_id);
+ H5D.close(xml_id);
+ end
+ H5P.close(lapl_id);
+
+ % Open the data set and get the space
+ xml_id = H5D.open(obj.fid, obj.xmlpath);
+ xml_space_id = H5D.get_space(xml_id);
+ %H5S.select_all(space);
+
+ % Write the data
+ H5D.write(xml_id, xml_dtype, 'H5S_ALL', xml_space_id, 'H5P_DEFAULT', xmlstring);
+
+ % Close the XML
+ H5S.close(xml_space_id);
+ H5D.close(xml_id);
+
+ end
+ end
+
+end
diff --git a/matlab/testread.m b/matlab/testread.m
index 39c997a..08e78bd 100644
--- a/matlab/testread.m
+++ b/matlab/testread.m
@@ -1,68 +1,66 @@
-%filename = '~/temp/testdata.h5';
-filename = '~/gadgetron/ismrmrd_data/testdata.h5';
-
-% Open the HDF5 File
-file = H5F.open(filename, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
-
-% Open the xml
-dset_id = H5D.open(file, '/dataset/xml');
-
-% Get the dataspace
-file_space_id = H5D.get_space(dset_id);
-
-% Set variable length string type
-ismrm.datatypes.xmlhead = H5T.copy('H5T_C_S1');
-H5T.set_size(ismrm.datatypes.xmlhead,'H5T_VARIABLE');
-
-% Read the data
-xmldata = H5D.read(dset_id, ismrm.datatypes.xmlhead, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');
-
-% Close the XML Header
-H5D.close (dset_id);
-H5S.close (file_space_id);
-
-% Open the data
-dset_id = H5D.open(file, '/dataset/data');
-
-% Get the number of acquisitions
-file_space_id = H5D.get_space(dset_id);
-H5S.get_simple_extent_dims(file_space_id);
-[~,dims,~] = H5S.get_simple_extent_dims(file_space_id);
-nacq = dims(1);
-
-% Read the first acquisition
-dims = [1 1];
-mem_space_id = H5S.create_simple(2,dims,[]);
-offset = [0 0];
-block = [1 1];
-H5S.select_hyperslab(file_space_id,'H5S_SELECT_SET',offset,[],[],block);
-data = H5D.read(dset_id, ismrmrd.hdf5_datatypes.getType_Acquisition, ...
- mem_space_id, file_space_id, 'H5P_DEFAULT');
-acq1 = ismrmrd.Acquisition;
-acq1.head_ = data.head(1);
-acq1.traj_ = data.traj{1};
-acq1.data_ = data.data{1};
-
-% Read the 70th acquisition
-offset = [69 0];
-H5S.select_hyperslab(file_space_id,'H5S_SELECT_SET',offset,[],[],block);
-data = H5D.read(dset_id, ismrmrd.hdf5_datatypes.getType_Acquisition, ...
- mem_space_id, file_space_id, 'H5P_DEFAULT');
-acq70 = ismrmrd.Acquisition;
-acq70.head_ = data.head(1);
-acq70.traj_ = data.traj{1};
-acq70.data_ = data.data{1};
-
-% Read all of the acquisitions at once
-%data = H5D.read(dset_id, ismrmrd.hdf5_datatypes.getType_Acquisition, 'H5S_ALL','H5S_ALL','H5P_DEFAULT');
-
-
-
-% Close the data
-%H5D.close (dset);
-%H5S.close (space);
-
-% Close the file
-%H5F.close (file)
-
-%H5T.close (memtype);
+function [xmlhdr data nacq] = testread(filename)
+
+ % Open the HDF5 File
+ file = H5F.open(filename, 'H5F_ACC_RDONLY', 'H5P_DEFAULT');
+
+ % Open the xml
+ dset_id = H5D.open(file, '/dataset/xml');
+
+ % Get the dataspace
+ file_space_id = H5D.get_space(dset_id);
+
+ % Set variable length string type
+ ismrm.datatypes.xmlhead = H5T.copy('H5T_C_S1');
+ H5T.set_size(ismrm.datatypes.xmlhead,'H5T_VARIABLE');
+
+ % Read the data
+ hdr = H5D.read(dset_id, ismrm.datatypes.xmlhead, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT');
+ xmlhdr = hdr{1};
+
+ % Close the XML Header
+ H5D.close (dset_id);
+ H5S.close (file_space_id);
+
+ % Open the data
+ dset_id = H5D.open(file, '/dataset/data');
+
+ % Get the number of acquisitions
+ file_space_id = H5D.get_space(dset_id);
+ H5S.get_simple_extent_dims(file_space_id);
+ [~,dims,~] = H5S.get_simple_extent_dims(file_space_id);
+ nacq = dims(1);
+
+ % Initialize the return array of structs
+ data(nacq) = ismrmrd.Acquisition;
+
+ % Loop over the acquisitions and read them in
+ dims = [1 1];
+ mem_space_id = H5S.create_simple(2,dims,[]);
+
+ for p = 1:nacq
+
+ offset = [p-1 0];
+ H5S.select_hyperslab(file_space_id,'H5S_SELECT_SET',offset,[1 1],[1 1],[1 1]);
+ d = H5D.read(dset_id, ismrmrd.hdf5_datatypes.getType_Acquisition, ...
+ mem_space_id, file_space_id, 'H5P_DEFAULT');
+
+ data(p).head = d.head(1);
+ data(p).traj = d.traj{1};
+ data(p).data = d.data{1};
+
+ end
+
+ % Close the data
+ H5S.close (file_space_id);
+ H5D.close (dset_id);
+
+ % Close the file
+ H5F.close (file)
+
+end
+
+ % Read all of the acquisitions at once
+ %data = H5D.read(dset_id, ismrmrd.hdf5_datatypes.getType_Acquisition, 'H5S_ALL','H5S_ALL','H5P_DEFAULT');
+
+
+
\ No newline at end of file
diff --git a/matlab/testrecon.m b/matlab/testrecon.m
new file mode 100644
index 0000000..f3bcfe8
--- /dev/null
+++ b/matlab/testrecon.m
@@ -0,0 +1,10 @@
+[xmlhdr data] = testread('~/Projects/ismrmrd_data/testdata.h5');
+
+nacq = size(data,2);
+k = zeros([data(1).head.number_of_samples nacq]);
+for p = 1:nacq;
+ k(:,p) = data(p).data;
+end
+
+imagesc(abs(fftshift(ifft2(fftshift(k)))))
+axis image; axis off;
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git
More information about the debian-science-commits
mailing list