| classdef us_image < handle |
|
|
| |
| |
| |
| |
|
|
| properties (SetAccess = public) |
| |
| |
| name |
| author |
| affiliation |
| algorithm |
| creation_date |
| |
| |
| scan |
| |
| |
| number_plane_waves |
| data |
| |
| |
| transmit_f_number |
| transmit_apodization_window |
| receive_f_number |
| receive_apodization_window |
| |
| end |
|
|
| |
| properties (SetAccess = private) |
| version |
| end |
| |
| |
| methods (Access = public) |
| |
| function h = us_image(name) |
| |
| |
| |
| |
| |
|
|
| h.creation_date = sprintf('%d/%02d/%d %02d:%02d:%02.2f',clock); |
| h.version = 'v0.10'; |
| |
| if exist('name') |
| h.name=name; |
| else |
| h.name=''; |
| end |
| author = ''; |
| affiliation = ''; |
| algorithm = ''; |
| creation_date = ''; |
| number_plane_waves = NaN; |
| transmit_f_number = NaN; |
| transmit_apodization_window = ''; |
| receive_f_number = NaN; |
| receive_apodization_window = ''; |
| |
| end |
| |
| end |
| |
| |
| methods |
| |
| |
| function set.name(h,input) |
| assert(isstr(input), 'Wrong format of the beamformed data name. It should be a string.'); |
| h.name = input; |
| end |
| |
| |
| function set.author(h,input) |
| assert(isstr(input), 'Wrong format of the author. It should be a string.'); |
| h.author = input; |
| end |
| |
| |
| function set.affiliation(h,input) |
| assert(isstr(input), 'Wrong format of the affiliation. It should be a string.'); |
| h.affiliation = input; |
| end |
| |
| |
| function set.algorithm(h,input) |
| assert(isstr(input), 'Wrong format of the algorithm name. It should be a string.'); |
| h.algorithm = input; |
| end |
| |
| |
| function set.creation_date(h,input_date) |
| assert(isstr(input_date), 'Wrong format of the creation date. It should be a string.'); |
| h.creation_date = input_date; |
| end |
| |
| |
| function set.scan(h,input) |
| assert(isa(input,'linear_scan'), 'Wrong format of the scan. It should be a LINEAR_SCAN class.'); |
| h.scan = input; |
| end |
| |
| |
| function set.data(h,input_data) |
| assert(isnumeric(input_data)&&ndims(input_data)>1&&ndims(input_data)<4, 'Wrong format of the data. It should be a numeric array of dimensions [z_axis, x_axis, frames].'); |
| |
| if(~isempty(h.scan)) |
| if(size(input_data,1)~=length(h.scan.z_axis)) error('The data size in the z-axis does not match the size of the scan area');end |
| if(size(input_data,2)~=length(h.scan.x_axis)) error('The data size in the x-axis does not match the size of the scan area');end |
| end |
| |
| assert(~any(isnan(h.number_plane_waves)),'The number of plane waves must be set before assigning the data'); |
| if(size(input_data,3)~=length(h.number_plane_waves)) error('The number of images size(data,3) should match the number of elements in the vector number_plane_waves');end |
| |
| h.data = input_data; |
| |
| assert(isreal(h.data)&~any(h.data(:)<0),'Data provided must be the envelope of the beamformed signal, i.e. the magnitude of the beamformed IQ signal or the magnitude of the Hilbert transform of a RF beamformed signal. Do not apply compression to the signal envelope.'); |
| end |
| |
| end |
| |
| |
| |
| methods (Access = public) |
| |
| function im = show(h,dynamic_range,frame_list) |
| |
| |
| |
| |
| |
| |
| |
| |
| if ~exist('dynamic_range') dynamic_range=60; end |
| |
| |
| x_lim = [min(h.scan.x_matrix(:)) max(h.scan.x_matrix(:))]*1e3; |
| z_lim = [min(h.scan.z_matrix(:)) max(h.scan.z_matrix(:))]*1e3; |
| |
| |
| figure; set(gca,'fontsize',16); |
| if ~exist('frame_list') || isempty(frame_list) |
| frame_list = 1:size(h.data,3); |
| end |
| for f=frame_list |
| |
| |
| env = h.data(:,:,f); |
| im = 20*log10(env./max(env(:))); |
| vrange = [-dynamic_range 0]; |
|
|
| |
| imagesc((h.scan.x_axis)*1e3,(h.scan.z_axis)*1e3,im); |
| shading flat; colormap gray; caxis(vrange); colorbar; hold on; |
| axis equal manual; |
| xlabel('x [mm]'); |
| ylabel('z [mm]'); |
| set(gca,'YDir','reverse'); |
| set(gca,'fontsize',16); |
| axis([x_lim z_lim]); |
| title(sprintf('%s\n %d plane waves',char(h.name),h.number_plane_waves(f))); |
| drawnow; hold off; |
| pause(0.5); |
| |
| end |
| |
| end |
| |
| end |
| |
| |
| methods (Access = public) |
|
|
| |
| function read_file(h,filename) |
| |
| |
| |
| |
| |
| |
| [pathstr, name, ext] = fileparts(filename); |
| switch ext |
| case '.mat' |
| h.read_file_mat(filename); |
| case '.hdf5' |
| h.read_file_hdf5(filename); |
| otherwise |
| error('Unknown signal format!'); |
| end |
| |
| end |
| |
| |
| function write_file(h,filename) |
| |
| |
| |
| |
| |
| |
| [pathstr, name, ext] = fileparts(filename); |
| switch ext |
| case '.mat' |
| h.write_file_mat(filename); |
| case '.hdf5' |
| h.write_file_hdf5(filename); |
| otherwise |
| error('Unknown signal format!'); |
| end |
| |
| end |
| |
| |
| function write_file_hdf5(h,filename) |
| |
| |
| |
| |
| |
| |
| |
| |
| attr_details.Name = 'version'; |
| attr_details.AttachedTo = '/'; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, 'v.0.0.41'); |
| |
| |
| try |
| h5info(filename,'/US') |
| catch |
| fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| gid = H5G.create(fid,'US','H5P_DEFAULT','H5P_DEFAULT','H5P_DEFAULT'); |
| H5G.close(gid); |
| H5F.close(fid); |
| end |
| |
| |
| group_name = 'US_DATASET0000'; |
| fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| gid = H5G.open(fid,'/US'); |
| s_gid = H5G.create(gid,group_name,'H5P_DEFAULT','H5P_DEFAULT','H5P_DEFAULT'); |
| H5G.close(s_gid); |
| H5G.close(gid); |
| H5F.close(fid); |
| location = ['/US/' group_name]; |
| |
| |
| |
| file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| filetype = H5T.enum_create ('H5T_NATIVE_INT'); |
| H5T.enum_insert (filetype, 'US', 0); |
| H5T.enum_insert (filetype, 'SR', 1); |
| gid = H5G.open(file,location); |
| space = H5S.create_simple (1,1,[]); |
|
|
| attr = H5A.create (gid, 'type', filetype, space, 'H5P_DEFAULT'); |
| H5A.write (attr, filetype, uint32(1)); |
| H5A.close (attr); |
| H5G.close(gid); |
| H5S.close (space); |
| H5T.close (filetype); |
| H5F.close (file); |
| |
| |
| file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| filetype = H5T.enum_create ('H5T_NATIVE_INT'); |
| H5T.enum_insert (filetype, 'RF', 0); |
| H5T.enum_insert (filetype, 'IQ', 1); |
| H5T.enum_insert (filetype, 'ENV', 2); |
| gid = H5G.open(file,location); |
| space = H5S.create_simple (1,1,[]); |
|
|
| attr = H5A.create (gid, 'signal_format', filetype, space, 'H5P_DEFAULT'); |
| H5A.write (attr, filetype, uint32(2)); |
| H5A.close (attr); |
| H5G.close(gid); |
| H5S.close (space); |
| H5T.close (filetype); |
| H5F.close (file); |
|
|
| |
| attr_details.Name = 'name'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.name, 'WriteMode', 'append'); |
|
|
| |
| attr_details.Name = 'author'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.author, 'WriteMode', 'append'); |
|
|
| |
| attr_details.Name = 'affiliation'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.affiliation, 'WriteMode', 'append'); |
|
|
| |
| attr_details.Name = 'algorithm'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.algorithm, 'WriteMode', 'append'); |
| |
| |
| attr_details.Name = 'version'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.version, 'WriteMode', 'append'); |
| |
| |
| attr_details.Name = 'creation_date'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, h.creation_date, 'WriteMode', 'append'); |
|
|
| |
|
|
| |
| dset_details.Location = [location '/scan']; |
| dset_details.Name = 'x_axis'; |
| hdf5write(filename, dset_details, single(h.scan.x_axis), 'WriteMode', 'append'); |
| |
| dset_details.Location = [location '/scan']; |
| dset_details.Name = 'z_axis'; |
| hdf5write(filename, dset_details, single(h.scan.z_axis), 'WriteMode', 'append'); |
|
|
| |
| dset_details.Location = location; |
| dset_details.Name = 'transmit_f_number'; |
| hdf5write(filename, dset_details, single(h.transmit_f_number), 'WriteMode', 'append'); |
| dset_details.Location = location; |
| dset_details.Name = 'receive_f_number'; |
| hdf5write(filename, dset_details, single(h.receive_f_number), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'transmit_apodization_window'; |
| hdf5write(filename, dset_details, char(h.transmit_apodization_window), 'WriteMode', 'append'); |
| dset_details.Location = location; |
| dset_details.Name = 'receive_apodization_window'; |
| hdf5write(filename, dset_details, char(h.receive_apodization_window), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'number_plane_waves'; |
| hdf5write(filename, dset_details, single(h.number_plane_waves), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = [location '/data']; |
| dset_details.Name = 'real'; |
| hdf5write(filename, dset_details, single(real(h.data)), 'WriteMode', 'append'); |
| dset_details.Name = 'imag'; |
| hdf5write(filename, dset_details, single(imag(h.data)), 'WriteMode', 'append'); |
| |
| end |
| |
| function read_file_hdf5(h,filename) |
| |
| |
| |
| |
| |
| |
| |
| version_cell = h5readatt(filename,'/','version'); |
| version = version_cell{1}(1:8); |
| |
| switch(version) |
| case 'v.0.0.40' |
| warning('The version of the hdf5 is obsolete. Please generate the image again.'); |
| |
| |
| info = h5info(filename,'/US'); |
|
|
| |
| for n=1:length(info.Groups) |
| location = info.Groups(n).Name; |
| dstype = h5readatt(filename,location,'type'); |
| if strcmp(dstype,'SR') |
| |
| signal_format = h5readatt(filename,location,'signal_format'); |
| switch(signal_format{1}) |
| case 'RF' |
| error('RF format not available!'); |
| case 'IQ' |
| error('RF format not available!'); |
| case 'ENV' |
| ; |
| otherwise |
| error('Unknown signal format!'); |
| end |
|
|
| |
| |
| a = h5readatt(filename,location,'name'); h.name=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'author'); h.author=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'affiliation'); h.affiliation=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'algorithm'); h.algorithm=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'creation_date'); h.creation_date=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'version'); h.version=a{1}(1:end-1); |
|
|
| |
|
|
| |
| x_axis = h5read(filename,[location '/scan/x_axis']); |
| z_axis = h5read(filename,[location '/scan/z_axis']); |
| h.scan = linear_scan(x_axis,z_axis); |
|
|
| |
| h.transmit_f_number = h5read(filename,[location '/transmit_f_number']); |
| h.receive_f_number = h5read(filename,[location '/receive_f_number']); |
|
|
| |
| h.transmit_apodization_window = h5read(filename,[location '/transmit_apodization_window']); |
| h.receive_apodization_window = h5read(filename,[location '/receive_apodization_window']); |
|
|
| |
| real_part = h5read(filename,[location '/data/real']); |
| imag_part = h5read(filename,[location '/data/imag']); |
| h.number_plane_waves = zeros(1,size(real_part,3)); |
| h.data = real_part+1i*imag_part; |
| |
| end |
| |
| end |
| |
| case 'v.0.0.41' |
| |
| info = h5info(filename,'/US'); |
|
|
| |
| for n=1:length(info.Groups) |
| location = info.Groups(n).Name; |
| dstype = h5readatt(filename,location,'type'); |
| if strcmp(dstype,'SR') |
| |
| signal_format = h5readatt(filename,location,'signal_format'); |
| switch(signal_format{1}) |
| case 'RF' |
| error('RF format not available!'); |
| case 'IQ' |
| error('RF format not available!'); |
| case 'ENV' |
| ; |
| otherwise |
| error('Unknown signal format!'); |
| end |
|
|
| |
| |
| a = h5readatt(filename,location,'name'); h.name=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'author'); h.author=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'affiliation'); h.affiliation=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'algorithm'); h.algorithm=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'creation_date'); h.creation_date=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'version'); h.version=a{1}(1:end-1); |
|
|
| |
|
|
| |
| x_axis = h5read(filename,[location '/scan/x_axis']); |
| z_axis = h5read(filename,[location '/scan/z_axis']); |
| h.scan = linear_scan(x_axis,z_axis); |
|
|
| |
| h.transmit_f_number = h5read(filename,[location '/transmit_f_number']); |
| h.receive_f_number = h5read(filename,[location '/receive_f_number']); |
|
|
| |
| h.transmit_apodization_window = h5read(filename,[location '/transmit_apodization_window']); |
| h.receive_apodization_window = h5read(filename,[location '/receive_apodization_window']); |
|
|
| |
| h.number_plane_waves = h5read(filename,[location '/number_plane_waves']); |
|
|
| |
| real_part = h5read(filename,[location '/data/real']); |
| imag_part = h5read(filename,[location '/data/imag']); |
| h.data = real_part+1i*imag_part; |
| end |
| end |
| otherwise |
| error(sprintf('HUFF version %s not supported',version)); |
| end |
| |
| end |
| |
|
|
| function read_file_mat(h,filename) |
| |
| |
| load(filename); |
| |
| |
| |
| h.name = PARAM.name; |
|
|
| |
| h.author = PARAM.author; |
|
|
| |
| h.affiliation = PARAM.affiliation; |
|
|
| |
| h.algorithm = PARAM.algorithm; |
|
|
| |
| h.creation_date = PARAM.creation_date; |
|
|
| |
| h.version = PARAM.version; |
|
|
| |
|
|
| |
| x_axis = PARAM.x_axis; |
| z_axis = PARAM.z_axis; |
| h.scan = linear_scan(x_axis,z_axis); |
|
|
| |
| h.transmit_f_number = PARAM.transmit_f_number; |
| h.receive_f_number = PARAM.receive_f_number; |
|
|
| |
| h.transmit_apodization_window = PARAM.transmit_apodization_window; |
| h.receive_apodization_window = PARAM.receive_apodization_window; |
|
|
| |
| h.number_plane_waves = PARAM.number_plane_waves; |
|
|
| |
| real_part = PARAM.real_part; |
| imag_part = PARAM.imag_part; |
| h.data = real_part+1i*imag_part; |
|
|
| end |
| |
| |
| function write_file_mat(h,filename) |
| |
| |
| |
| PARAM.name = h.name; |
|
|
| |
| PARAM.author = h.author; |
|
|
| |
| PARAM.affiliation = h.affiliation; |
|
|
| |
| PARAM.algorithm = h.algorithm; |
|
|
| |
| PARAM.creation_date = h.creation_date; |
|
|
| |
| PARAM.version = h.version; |
|
|
|
|
| |
|
|
| |
| PARAM.x_axis = single(h.scan.x_axis); |
| PARAM.z_axis = single(h.scan.z_axis); |
|
|
|
|
| |
| PARAM.transmit_f_number = single(h.transmit_f_number); |
| PARAM.receive_f_number = single(h.receive_f_number); |
|
|
| |
| PARAM.transmit_apodization_window = char(h.transmit_apodization_window); |
| PARAM.receive_apodization_window = char(h.receive_apodization_window); |
|
|
| |
| PARAM.number_plane_waves = single(h.number_plane_waves); |
|
|
| |
| PARAM.real_part = single(real(h.data)); |
| PARAM.imag_part = single(imag(h.data)); |
| |
| |
| save(filename,'PARAM'); |
| |
| end |
| |
| end |
| |
| end |
|
|
|
|