%% MATLAB script for generating M-Mode Seashore plots from real-time % recordings of pleural region from files '*_rt_recon.mat' for B-Mode data clear; % clc; % close; %% Image params log_compression = true; dB_range = 40; orthogonal = false; slice_dir = 'yz'; video_out = false; display_plot = true; frame_rate = 5.394; %% Load saved B-Mode complex data for plotting in MATLAB/ % exporting into image data for Origin %Data file path filepath = './datasets_lung/'; %File name filename = 'lung_dataset1_rt_recon'; %Load Complex data bmode_data_struct = load(strcat(filepath, filename, '.mat')); %Assign variables bmode_data = bmode_data_struct.bmode_data; zI = bmode_data_struct.zI; if (slice_dir=='xz') xI = bmode_data_struct.xI; elseif (slice_dir=='yz') yI = bmode_data_struct.yI; end N_frame = size(bmode_data, 3); %% Generate seashore plot %Magnitude of complex data bmode_data = abs(bmode_data); b_mode = bmode_data/max(bmode_data(:)); %Log compression b_mode_temp = 20*log10(b_mode); b_mode = (b_mode_temp+dB_range).*(b_mode_temp>-dB_range); b_mode = uint8(255*b_mode/dB_range); %Set Seashore Parameters and Index the region seashore_center = 0; seashore_roi = 0.12; seashore_depth = 4.4; seashore_width = [-0.5*seashore_roi 0.5*seashore_roi]*1e-2; seashore_depth = [0.15 seashore_depth]*1e-2; % Get Seashore coordinates if(slice_dir == "xz") seashore_index = (xI>=seashore_width(1) & xI<=seashore_width(2) & ... zI>=seashore_depth(1) & zI<=seashore_depth(2)); else seashore_index = (yI>=seashore_width(1) & yI<=seashore_width(2) & ... zI>=seashore_depth(1) & zI<=seashore_depth(2)); end if(slice_dir == "xz") seashore_y = xI(seashore_index); else seashore_y = yI(seashore_index); end seashore_z = zI(seashore_index); % Get Seashore Data seashore_index = repmat(seashore_index, [1 1 N_frame]); seashore_data = b_mode(seashore_index); seashore_data = reshape(seashore_data, size(seashore_y, 1), []); %Interpolate from Scattered XY onto Uniform grid F = scatteredInterpolant(seashore_y, seashore_z, double(seashore_data)); [y_interp, z_interp] = meshgrid(linspace(seashore_width(1), seashore_width(2), 20), ... linspace(seashore_depth(1), seashore_depth(2), 1024)); seashore_interp = F(y_interp, z_interp); %Average along Y seashore_interp = reshape(seashore_interp, size(y_interp, 1), size(y_interp, 2), []); seashore_interp = squeeze(mean(seashore_interp, 2)); seashore_interp = uint8(255*seashore_interp/(max(seashore_interp, [], 'all'))); %Time axis and plot time_end = (N_frame-1)/frame_rate; time_axis = (0:N_frame-1)/frame_rate; depth_axis = 100*z_interp(:, 1); figure(); pcolor(time_axis, depth_axis, seashore_interp); axis ij tight shading flat ylabel('Z (depth) [cm]'); xlabel('Time [s]'); colormap hot c = colorbar; clim([0 255]); c.YTick = [0 255]; c.YTickLabel = {'0 dB',strcat(num2str(dB_range), ' dB')}; yticks(1:4); xticks(0:4:20);