Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fischeryann committed Aug 8, 2024
2 parents b57cbf6 + 7261697 commit 401e9b5
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 181 deletions.
29 changes: 11 additions & 18 deletions ArterialResistivityIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

disp('arterial resistivity...');

[Nx, Ny, N_frame] = size(videoM0);

name_log = strcat(ToolBox.PW_folder_name, '_log.txt');
path_file_log = fullfile(ToolBox.PW_path_log, name_log);
mkdir(ToolBox.PW_path_png, 'arterialResistivityIndex')
mkdir(ToolBox.PW_path_eps, 'arterialResistivityIndex')

fileID = fopen(path_file_log, 'a+');
fprintf(fileID, 'Arterial resistivity... \r\n');
fclose(fileID);
[Nx, Ny, N_frame] = size(videoM0);

meanIm = rescale(mean(videoM0, 3));
videoM0 = rescale(videoM0);
Expand Down Expand Up @@ -56,11 +52,6 @@

close(w);

disp('done.');
fileID = fopen(path_file_log, 'a+');
fprintf(fileID, 'Done. \r\n');
fclose(fileID);

% disp('arterial resistivity...');
% [ARImap, ARI, ARImapRGB, ARIvideoRGB, gamma, img_avg] = construct_resistivity_index(onePulseVideo, maskArtery,path);
% ARImap = ARImap.*maskArtery;
Expand Down Expand Up @@ -96,9 +87,11 @@
c.Label.String = 'Arterial resistivity index';
c.Label.FontSize = 14;
colormap(cmap);
exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'ARImapFig.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'ARImapFig.eps')))
imwrite(ARImapRGB, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'ARI_map.png')), 'png')
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARImapFig.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARImapFig.eps')))

imwrite(ARImapRGB, fullfile(ToolBox.PW_path_png, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARIMapColored.png')), 'png')
imwrite(ARImap, fullfile(ToolBox.PW_path_png, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARIMapRaw.png')), 'png')

% Save colorbar
colorfig = figure(113);
Expand All @@ -110,14 +103,14 @@
hCB.Position = [0.10 0.3 0.81 0.35];
colorfig.Position(4) = 0.1000;
fontsize(gca, 14, "points");
exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'ARImapColorbar.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'ARImapColorbar.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARImapColorbar.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'arterialResistivityIndex', sprintf("%s_%s", ToolBox.main_foldername, 'ARImapColorbar.eps')))

f71 = figure(71);
f71.Position = [300, 300, 570, 630];

timePeriod = ToolBox.stride / ToolBox.fs / 1000;
gifWriter = GifWriter(fullfile(ToolBox.PW_path_gif, sprintf("%s_%s.gif", ToolBox.PW_folder_name, "ARI")), timePeriod, 0.04, N_frame);
gifWriter = GifWriter(fullfile(ToolBox.PW_path_gif, sprintf("%s_%s.gif", ToolBox.PW_folder_name, "ArterialResistivityIndex")), timePeriod, 0.04, N_frame);

for frameIdx = 1:N_frame
imagesc(ARIvideoRGB(:, :, :, frameIdx));
Expand Down
94 changes: 36 additions & 58 deletions OneCycleClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
videoSection
flag_SH_analysis
flag_PulseWave_analysis
flag_velocity_analysis
flag_ARI_analysis
flag_bloodVolumeRate_analysis
%% FIXME : relancer a chaque rendering
ToolBoxmaster ToolBoxClass

Expand Down Expand Up @@ -386,6 +389,7 @@ function onePulse(obj, Ninterp)
% progress_bar = waitbar(0,'');
checkPulsewaveParamsFromJson(obj.directory);
PW_params = Parameters_json(obj.directory);
totalTime = tic;

obj.k = PW_params.k;
obj.ToolBoxmaster = ToolBoxClass(obj.directory);
Expand Down Expand Up @@ -500,27 +504,16 @@ function onePulse(obj, Ninterp)
time = toc;
disp(time)

fileID = fopen(path_file_log, 'a+');
fprintf(fileID, 'CreateMasks timing : % \r\n\n', time);
fclose(fileID);

save_time(path_file_txt_exe_times, 'createMasks', time)
save_time(path_file_txt_exe_times, 'CreateMasks', time)
fileID = fopen(path_file_txt_exe_times, 'a+');
fprintf(fileID, '\r\n----------\r\n');
fclose(fileID);

tic
% [maskArtery, maskVein, maskVessel,maskBackground,maskCRA,maskCRV,maskSectionArtery]= createMasks(obj.reference_interp{1} ,obj.dataM1M0_interp{1}, obj.directory, ToolBox);
% [mask_artery, mask_vein, mask_vessel,mask_background,mask_CRA,maskCRV] = createMasks(obj.reference_interp{1} ,obj.dataM1M0_interp{1}, obj.directory, ToolBox);

% disp('CreatMasks New timing :')
% time = toc;
% disp(time)
%save_time(path_file_txt_exe_times, 'createMasksNew', time)

%% PulseWave Analysis
% waitbar(0.25,progress_bar,"PulseWave analysis");

tic

if obj.flag_PulseWave_analysis
close all

Expand Down Expand Up @@ -562,55 +555,40 @@ function onePulse(obj, Ninterp)
fclose(fileID);
clear exec_times

tic
velocity_figures(v_RMS_all, v_RMS_one_cycle, maskArtery, maskVein, obj.dataM0_interp{n}, FlowVideoRGB, ToolBox, path)
disp('Velocity figures timing :')
time_velo = toc;
disp(time_velo)
save_time(path_file_txt_exe_times, 'Velocity', time_velo)
if obj.flag_velocity_analysis
tic
bloodFlowVelocity(v_RMS_all, v_RMS_one_cycle, maskArtery, maskVein, obj.dataM0_interp{n}, FlowVideoRGB, ToolBox, path)
disp('Blood Flow Velocity timing :')
time_velo = toc;
disp(time_velo)
save_time(path_file_txt_exe_times, 'Blood Flow Velocity', time_velo)
end

% tic
% BKGHistogramm(obj.dataM2M0_interp{1}, maskBackground ,ToolBox)
% disp('BKG Histogramm timing :')
% toc
if obj.flag_ARI_analysis
tic
ArterialResistivityIndex(v_RMS_one_cycle, obj.reference_interp{1}, maskArtery, ToolBox);
disp('ArterialResistivityIndex timing :')
time_arterial_res = toc;
disp(time_arterial_res)
save_time(path_file_txt_exe_times, 'Arterial Resistivity Index', time_arterial_res)
end

if obj.flag_bloodVolumeRate_analysis
tic
bloodVolumeRate(maskArtery, maskVein, maskCRA, maskSectionArtery, v_RMS_all, obj.dataM0_interp{1}, obj.reference_interp{n}, ToolBox, obj.k, obj.directory);
disp('Blood Volume Rate timing :')
time_flowrate = toc;
disp(time_flowrate)
save_time(path_file_txt_exe_times, 'Blood Volume rate', time_flowrate)
end

tic
ArterialResistivityIndex(v_RMS_one_cycle, obj.reference_interp{1}, maskArtery, ToolBox);
disp('ArterialResistivityIndex timing :')
time_arterial_res = toc;
disp(time_arterial_res)
save_time(path_file_txt_exe_times, 'Arterial Resistivity Index', time_arterial_res)

%[v] = pulseAnalysisTest(Ninterp,obj.dataM2M0_interp{n},obj.dataM1M0_interp{n},obj.reference_interp{1},sys_index_list_cell{n},maskArtery,maskVessel,maskVein,maskBackground ,ToolBox,obj.directory);
% detectElasticWave(datacube, maskArtery, maskCRA);
tic
% try
disp('flowrate :')
flow_rate(maskArtery, maskVein, maskCRA, maskSectionArtery, v_RMS_all, obj.dataM0_interp{1}, obj.reference_interp{n}, ToolBox, obj.k, obj.directory);
disp('FlowRate timing :')
time_flowrate = toc;
disp(time_flowrate)
save_time(path_file_txt_exe_times, 'Flow rate', time_flowrate)
% catch
% disp('no flow rate')

% try
% flow_rate(maskArtery, maskVein, maskCRA, v_RMS, ToolBox, obj.k,obj.directory);
% catch
% end

% tic
% spectrogram(maskArtery,maskBackground, obj.dataSH_interp{n}, ToolBox);
% disp('Spectrogram timing :')
% time = toc;
% disp(time)
% save_time(path_file_txt_exe_times, '\tSpectrogram', time)
% else

fileID = fopen(path_file_txt_exe_times, 'a+');
fprintf(fileID, '\r\n=== Total : %.0fs \r\n\n----------\r\n', time_sys_idx + time_pulseanalysis + time_vel_map + time_hist + time_arterial_res + time_flowrate);
tTotal = toc(totalTime);
fprintf(fileID, '\r\n=== Total : %.0fs \r\n\n----------\r\n', tTotal);
fclose(fileID);
% end


end

end
Expand Down
37 changes: 20 additions & 17 deletions velocity_figures.m → bloodFlowVelocity.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function [] = velocity_figures(v_RMS_all, v_one_cycle, maskArtery, maskVein, videoM0, FreqVideoRGB, ToolBox, path)
function [] = bloodFlowVelocity(v_RMS_all, v_one_cycle, maskArtery, maskVein, videoM0, FreqVideoRGB, ToolBox, path)

PW_params = Parameters_json(path);
veins_analysis = PW_params.veins_analysis;
mkdir(ToolBox.PW_path_png, 'bloodFlowVelocity')
mkdir(ToolBox.PW_path_eps, 'bloodFlowVelocity')

tic

Expand Down Expand Up @@ -57,7 +59,7 @@
val_mean = v_mean .* (~(maskArtery + maskVein)) + val_artery_mean .* maskArtery + val_vein_mean .* maskVein;
flowVideoRGB_mean = hsv2rgb(hue_artery_mean + hue_vein_mean, sat_artery_mean + sat_vein_mean, val_mean);
flowVideoRGB_mean = flowVideoRGB_mean .* (maskArtery + maskVein) + ones(Nx, Ny, 3) .* ~(maskArtery + maskVein) .* M0_norm_mean;
imwrite(flowVideoRGB_mean, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, "vRMSMean.png")))
imwrite(flowVideoRGB_mean, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, "vRMSMean.png")))

for frameIdx = 1:N_frame
v = mat2gray(v_RMS_all(:, :, frameIdx));
Expand All @@ -74,7 +76,7 @@
val_mean = v_mean .* (~(maskArtery)) + val_artery_mean .* maskArtery;
flowVideoRGB_mean = hsv2rgb(hue_artery_mean, sat_artery_mean, val_mean);
flowVideoRGB_mean = flowVideoRGB_mean .* (maskArtery) + ones(Nx, Ny, 3) .* ~(maskArtery) .* M0_norm_mean;
imwrite(flowVideoRGB_mean, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, "vRMSMean.png")))
imwrite(flowVideoRGB_mean, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, "vRMSMean.png")))

for frameIdx = 1:N_frame
v = mat2gray(v_RMS_all(:, :, frameIdx));
Expand Down Expand Up @@ -126,8 +128,8 @@
xlabel('Time (s)')
title("Velocity histogram in arteries")

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesOneCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesOneCycle.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesOneCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesOneCycle.eps')))

if veins_analysis
v_histo_veins = round(v_one_cycle .* maskVein);
Expand Down Expand Up @@ -165,8 +167,8 @@
xlabel('Time (s)')
title("Velocity histogram in veins")

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsOneCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsOneCycle.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsOneCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsOneCycle.eps')))

end

Expand Down Expand Up @@ -204,8 +206,8 @@
colorfig.Position(4) = 0.1000;
fontsize(gca, 15, "points");

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityArteries.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityArteries.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityArteries.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityArteries.eps')))

if veins_analysis
% Save colorbar
Expand All @@ -220,8 +222,8 @@
colorfig.Position(4) = 0.1000;
fontsize(gca, 15, "points");

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityVeins.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityVeins.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityVeins.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'colorbarVelocityVeins.eps')))

end

Expand Down Expand Up @@ -337,6 +339,7 @@
set(gca, 'YDir', 'normal')
ylabel('Velocity (mm.s^{-1})')
xlabel('Time (s)')
title("Velocity distribution in arteries")
set(gca, 'PlotBoxAspectRatio', [2.5 1 1])
f = getframe(gcf);
histo_video_artery(:, :, :, frameIdx) = imresize(f.cdata, [M N]);
Expand All @@ -347,8 +350,8 @@
gifWriter.generate();
gifWriter.delete();

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesFullCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesFullCycle.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesFullCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityArteriesFullCycle.eps')))

% AVI

Expand Down Expand Up @@ -428,8 +431,8 @@
gifWriter.generate();
gifWriter.delete();

exportgraphics(gca, fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsFullCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsFullCycle.eps')))
exportgraphics(gca, fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsFullCycle.png')))
exportgraphics(gca, fullfile(ToolBox.PW_path_eps, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'histogramVelocityVeinsFullCycle.eps')))

% AVI

Expand Down Expand Up @@ -462,14 +465,14 @@
freq_video(:, :, 3, :) = imresize3(squeeze(FreqVideoRGB(:, :, 3, :)), [550 550 N_frame]);
combinedGifs = cat(2, freq_video, cat(1, mat2gray(histo_video_artery), mat2gray(histo_video_vein)));
freq_video_mean = rescale(imresize3(imread(fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideo.png'))), [550 550 3]));
imwrite(cat(2, freq_video_mean, cat(1, mat2gray(histo_video_artery(:, :, :, end)), mat2gray(histo_video_vein(:, :, :, end)))), fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideoCombined.png')))
imwrite(cat(2, freq_video_mean, cat(1, mat2gray(histo_video_artery(:, :, :, end)), mat2gray(histo_video_vein(:, :, :, end)))), fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideoCombined.png')))
else
freq_video(:, :, 1, :) = imresize3(squeeze(FreqVideoRGB(:, :, 1, :)), [600 600 N_frame]);
freq_video(:, :, 2, :) = imresize3(squeeze(FreqVideoRGB(:, :, 2, :)), [600 600 N_frame]);
freq_video(:, :, 3, :) = imresize3(squeeze(FreqVideoRGB(:, :, 3, :)), [600 600 N_frame]);
combinedGifs = cat(1, freq_video, mat2gray(histo_video_artery));
freq_video_mean = rescale(imresize3(imread(fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideo.png'))), [600 600 3]));
imwrite(cat(1, freq_video_mean, mat2gray(histo_video_artery(:, :, :, end))), fullfile(ToolBox.PW_path_png, sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideoCombined.png')))
imwrite(cat(1, freq_video_mean, mat2gray(histo_video_artery(:, :, :, end))), fullfile(ToolBox.PW_path_png, 'bloodFlowVelocity', sprintf("%s_%s", ToolBox.main_foldername, 'AVGflowVideoCombined.png')))
end

gifWriter = GifWriter(fullfile(ToolBox.PW_path_gif, sprintf("%s_%s.gif", ToolBox.PW_folder_name, "velocityHistogramCombined")), timePeriod, 0.04, N_frame);
Expand Down
Loading

0 comments on commit 401e9b5

Please sign in to comment.