File size: 10,986 Bytes
7b4139b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | classdef linear_scan < handle
%-- Class defining a linear scan area
%-- Authors: Alfonso Rodriguez-Molares (alfonso.r.molares@ntnu.no)
%-- Olivier Bernard (olivier.bernard@creatis.insa-lyon.fr)
%-- $Date: 2016/03/01 $
properties (SetAccess = public)
x_axis %-- Vector defining the x coordinates of each row of pixels
z_axis %-- Vector defining the z coordinates of each column of pixels
end
properties (SetAccess = private)
x_matrix %-- Matrix containing the x coordinate of each pixel in the matrix
z_matrix %-- Matrix containing the z coordinate of each pixel in the matrix
x %-- Vector containing the x coordinate of each pixel in the matrix
z %-- Vector containing the z coordinate of each pixel in the matrix
dx %-- Spatial step in x-axis
dz %-- Spatial step in z-axis
Nx %-- Number of samples in x-axis
Nz %-- Number of samples in z-axis
pixels %-- total number of pixels in the matrix
end
methods (Access = public)
%-- Constructor
function h = linear_scan(input_x,input_z)
%-- Constructor of linear_scan class
%-- Syntax:
%-- h = linear_scan(x_vector,z_vector)
%-- x_vector: Vector defining the x coordinates of each row of pixels
%-- z_vector: Vector defining the z coordinates of each column of pixels
if nargin>0
h.x_axis=input_x;
end
if nargin>1
h.z_axis=input_z;
end
end
%-- lateral_distance
function xd = lateral_distance(h,x0,z0,steer_angle)
%-- Calculates the lateral distance from the center of
%-- the apodization window for a specific scanning mode
%-- Syntax:
%-- h = lateral_distance(element_position,steering_angle)
%-- x0: Vector containing the x coordinates of the probe elements (either real or virtual) [m]
%-- z0 : Vector containing the x coordinates of the probe elements (either real or virtual) [m]
%-- steering_angle: Steerin angle [rad]
xd = abs(x0-h.x+h.z*tan(steer_angle));
end
%-- Spatial step in the beam direction
function dz = depth_step(h)
%-- Calculates the spatial step for a given scan area
%-- Syntax:
%-- dz = depth_step()
%-- dz: Spatial step in the beam direction
dz = mean(diff(h.z_axis)); %-- spatial step in the beam direction
end
end
%-- Set methods
methods
function h = set.x_axis(h,input_vector)
assert(size(input_vector,1)>size(input_vector,2), 'The x vector must be a column vector!')
h.x_axis = input_vector;
h.dx = h.x_axis(2)-h.x_axis(1);
h.Nx = numel(h.x_axis);
[h.x_matrix,h.z_matrix] = meshgrid(h.x_axis,h.z_axis);
h.x = h.x_matrix(:);
h.z = h.z_matrix(:);
h.pixels = length(h.x);
end
function h = set.z_axis(h,input_vector)
assert(size(input_vector,1)>size(input_vector,2), 'The z vector must be a column vector!')
h.z_axis = input_vector;
h.dz = h.z_axis(2)-h.z_axis(1);
h.Nz = numel(h.z_axis);
[h.x_matrix,h.z_matrix] = meshgrid(h.x_axis,h.z_axis);
h.x = h.x_matrix(:);
h.z = h.z_matrix(:);
h.pixels = length(h.x);
end
end
%-- HDF5 file management
methods (Access = public)
function write_file_hdf5(h,filename)
%-- write HUFF version in the root group
attr_details.Name = 'version';
attr_details.AttachedTo = '/';
attr_details.AttachType = 'group';
hdf5write(filename, attr_details, 'v.0.0.39');
%-- We create the /US metagroup in case it is not there
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
%-- We create a unique us_dataset group
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];
%-- Attributes
%-- Dataset type
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(0)); % <--- US
H5A.close (attr);
H5G.close(gid);
H5S.close(space);
H5T.close(filetype);
H5F.close(file);
%-- us_dataset subtype
file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT');
filetype = H5T.enum_create('H5T_NATIVE_INT');
H5T.enum_insert (filetype,'STA', 0);
H5T.enum_insert (filetype,'CPW', 1);
H5T.enum_insert (filetype,'VS', 2);
H5T.enum_insert (filetype,'BS', 3);
gid = H5G.open(file,location);
space = H5S.create_simple (1,1,[]);
attr = H5A.create (gid,'subtype',filetype,space,'H5P_DEFAULT');
H5A.write (attr,filetype,uint32(1)); % <---- TYPE CPWC
%-- Signal format
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);
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(1)); % <--- IQ
H5A.close(attr);
H5G.close(gid);
H5S.close(space);
H5T.close(filetype);
H5F.close(file);
%-- Common attributes
%-- add x-axis
dset_details.Location = location;
dset_details.Name = 'x_axis';
hdf5write(filename, dset_details, h.x_axis, 'WriteMode', 'append');
%-- add z-axis
dset_details.Location = location;
dset_details.Name = 'z_axis';
hdf5write(filename, dset_details, h.z_axis, 'WriteMode', 'append');
end
function read_file(h,filename)
%-- Reads all the information from a mat or hdf5 file
%-- Syntax:
%-- read_file(file_name)
%-- file_name: Name of the mat or hdf5 file
[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)
%-- Write all the information into a mat or hdf5 file
%-- Syntax:
%-- write_file(file_name)
%-- file_name: Name of the mat or hdf5 file
[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 read_file_hdf5(h,filename)
%-- read US metagroup
info = h5info(filename,'/US');
%-- read the groups in the metagroup
for n=1:length(info.Groups)
location = info.Groups(n).Name;
dstype = h5readatt(filename,location,'type');
if strcmp(dstype,'US')
subtype = h5readatt(filename,location,'subtype');
if strcmp(subtype{1},'CPW')
%-- subtype
dataset_subtype = h5readatt(filename,location,'subtype');
assert(strcmp(dataset_subtype,'CPW'),'Only CPWC us_dataset are supported!');
%-- read signal format
signal_format = h5readatt(filename,location,'signal_format');
switch(signal_format{1})
case 'RF'
error('RF format not available!');
case 'IQ'
;
otherwise
error('Unknown signal format!');
end
%-- Data
%-- read x_axis
h.x_axis = h5read(filename,[location '/x_axis']);
%-- read z_axis
h.z_axis = h5read(filename,[location '/z_axis']);
end
end
end
end
function read_file_mat(h,filename)
%-- Load mat file
load(filename);
%-- Data
%-- read x_axis
h.x_axis = PARAM.x_axis;
%-- read z_axis
h.z_axis = PARAM.z_axis;
end
function write_file_mat(h,filename)
%-- Common attributes
%-- add x-axis
PARAM.x_axis = h.x_axis;
%-- add z-axis
PARAM.z_axis = h.z_axis;
%-- write mat file
save(filename,'PARAM');
end
end
end
|