I need to create a script that demonstrates the use of this function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everybody. I hope you find each other well. I know this is a little big but if you could help me I would appreciate it.
I've been on a job and this is the last step I'm missing.
I have get_segmentation_size() function which allows to open the resulting binary mask of
targeting a certain structure (eg the lungs or heart) of a certain patient and
calculates its maximum width, maximum height and area (white region).
Now a friend of mine created the get_ct_ratio() function to calculate the cardiothoracic ratio (RCT) of a given
exam, using the formula above. For that, you can use the function
get_segmentation_size() previously defined in order to determine the width of the lungs and
from heart.
I now have to create a script that demonstrates the use of the get_ct_ratio() function. How do I do it? Thanks for helping
This was the function my friend created:
%get_ct_ratio - Calculates the cardiothoracic ratio of a patient to a
%certain exam
%Function call:
%[CTR] = get_ct_ratio(PID,CXRID,Mode,DemographicData)
%Variables:
% PID - input variable (patient ID)
% CXRID - output variable (chosen exam ID)
% Mode - input variable (Hide/Show popups)
% DemographicData - input and output variable (Struct with patient data)
% CTR - output variable (patient's cardiothoracic ratio)
%Goal - Calculates the cardiothoracic ratio of a patient to a
%certain exam. If run in mode 1, show warnings when
%user, otherwise they will be omitted.
% Authors Date
% ==== =======
% 11/01/2022 Ricardo, Fábio, Catarina, João
function [CTR] = get_ct_ratio(PID,CXRID,Mode,DemographicData)
%% Pre-definition of variables
exis_BMH=0;exis_BML=0;exit=0;saveCTR=[];
%% Change current folder to 'segmentations' folder
foldernow=cd('segmentations'); %Changes the current folder to the folder where the segmentations are and stores the location of the current folder in the variable
folderinfo=dir(cd); %Returns a struct with the data referring to the new folder (filename,...)
%% Check for the existence of segmentation of the heart and lungs for the indicated exam
for i=1:length(folderinfo)
if length(folderinfo(i).name)>length(CXRID) %Search through all files with valid name
if str2double(folderinfo(i).name(4:11))==str2double(CXRID(4:11)) %Finds the segmentations for the indicated exam
if folderinfo(i).name(13:17)=='heart'
exis_BMH=1; % Assumes the value 1 if there is segmentation of the heart, otherwise it assumes the value 0
end
if folderinfo(i).name(13:17)=='lungs'
exist_BML=1; % Assumes the value 1 if there is segmentation of the heart, otherwise it assumes the value 0
end
end
end
end
%% Return to home folder
cd(foldernow)
%%
while exit==0 %Loop repeat
if (exis_BMH==1 && exis_BML==1) %If there is segmentation of the heart and lungs for the indicated exam
filepath=[foldernow,'\segmentations']; %Create the directory for the 'segmentations' folder
filenameH=['\',CXRID,'_heart.png']; %Complete the name of the .png file with the image of the binary mask of the heart
BinaryMaskHeart=imread(strcat(filepath, filenameH)); %Binary heart mask reading
BinaryMaskHeart=uint16(BinaryMaskHeart);
filenameL=['\',CXRID,'_lungs.png']; %Complete the name of the .png file with the image of the binary lung mask
BinaryMaskLungs=imread(strcat(filepath, filenameL)); %Lung binary mask reading
BinaryMaskLungs=uint16(BinaryMaskLungs);
[WidthHeart,~,~]=get_segmentation_size(BinaryMaskHeart,1); %Determines the width of the heart
[WidthLungs,~,~]=get_segmentation_size(BinaryMaskLungs,1); %Determines the width of the lungs
CTR=WidthHeart/WidthLungs; %Calculation of the cardiothoracic ratio
if Mode==1 %If the function is executed in Mode 1, it shows the following warning
msg=questdlg(['The cardiothoracic ratio is ',num2str(CTR),'.'],'Medium Intensity','Ok','Ok');
%% Store the patient's CTR value in the struct
P=str2double(PID(2:end));
oldCTR=DemographicData(P).CTR;
if isempty(oldCTR)
oldCTR=0;
end
if oldCTR~=CTR
for i=1:length(DemographicData)
if DemographicData(i).Patient_ID==PID
DemographicData(i).CTR=CTR;
end
end
while isempty(saveCTR)
if oldCTR==0
msg='There is currently no CTR value associated with the patient';
else
msg=['Currently the CTR value associated with the patient is ',num2str(oldCTR)];
end
saveCTR=questdlg([{'Do you want to save the cardiothoracic ratio found in the database?'},{msg}],'Save CTR','Yes','No','Yes');
if saveCTR=='Yes'
row = str2double(PID(2:end)); %Determines the patient number to find the correct excel line
range = ['H',num2str(row+1)]; %Determines the correct cell of the excel file
xlswrite('Data.xlsx',CTR,'Sheet1',range); %Write in excel file
end
end
end
else
exit=1;
end
else
if Mode==1
%% If there is no segmentation of the heart for the indicated exam
if exist_BMH==0
errorBMH=questdlg('There is no heart segmentation available for this exam. Do you want to add it?','Heart Segmentation Error','Yes','No','Yes');
if isempty(errorBMH) %Repeat the input request until a response is entered
errorBMH=q
2 comentarios
Respuestas (1)
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!