I need to create a script that demonstrates the use of this function

1 view (last 30 days)
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 Comments
Rik
Rik on 26 Jan 2022
This function already has documentation. What exactly is the issue?
Joao Joao
Joao Joao on 26 Jan 2022
I just need to creat a script that demonstrates the use of the function. Do you thing this is correct?
a=imread('SegmentationImage');
imshow(a);
%% Struct with patient data
[~,PID] = xlsread('data.xlsx','Sheet1','A2:A11'); %Import of the values ​​to be placed in the field 'PatientID'
SNS = xlsread('Data.xlsx','Sheet1','B2:B11'); %Import of values ​​to be placed in field 'SNS_Number'
[~,Nm] = xlsread ('Data.xlsx','Sheet1','C2:C11');%Import of values ​​to put in field 'Name'
[~, date] = xlsread('Data.xlsx','Sheet1','D2:D11');%Import of values ​​to put in field 'Birthday'
Kg = xlsread ('Data.xlsx','Sheet1','E2:E11');%Import of values ​​to put in field 'Weight_kg'
met = xlsread ('Data.xlsx','Sheet1','F2:F11');%Import of values ​​to put in field 'Height_m'
[~,COPD(1:9)] = xlsread ('Data.xlsx','Sheet1','G2:G12');%Import of values ​​to put in field 'COPD'
DemographicData = struct('Patient_ID',PID,'SNS_Number',num2cell(SNS),'Name',Nm,'Birthday',date,'Weight_kg',num2cell(Kg),'Height_m',num2cell(met),' COPD',COPD,'CTR','-');
PID=input('Enter the patient ID');
CXRID=input('Enter the exam you want'); %Exam chosen
function [CTR] = get_ct_ratio(PID,CXRID,Mode,DemographicData)

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 26 Jan 2022
You've asked effectively this same question several times before just with different functions.
Generalize the advice you received for those three previous questions and do the same type of thing for this function.
  1 Comment
Joao Joao
Joao Joao on 26 Jan 2022
I think this is enough to demonstrate the function. What do you think?
a=imread('SegmentationImage');
imshow(a);
%% Struct with patient data
[~,PID] = xlsread('data.xlsx','Sheet1','A2:A11'); %Import of the values ​​to be placed in the field 'PatientID'
SNS = xlsread('Data.xlsx','Sheet1','B2:B11'); %Import of values ​​to be placed in field 'SNS_Number'
[~,Nm] = xlsread ('Data.xlsx','Sheet1','C2:C11');%Import of values ​​to put in field 'Name'
[~, date] = xlsread('Data.xlsx','Sheet1','D2:D11');%Import of values ​​to put in field 'Birthday'
Kg = xlsread ('Data.xlsx','Sheet1','E2:E11');%Import of values ​​to put in field 'Weight_kg'
met = xlsread ('Data.xlsx','Sheet1','F2:F11');%Import of values ​​to put in field 'Height_m'
[~,COPD(1:9)] = xlsread ('Data.xlsx','Sheet1','G2:G12');%Import of values ​​to put in field 'COPD'
DemographicData = struct('Patient_ID',PID,'SNS_Number',num2cell(SNS),'Name',Nm,'Birthday',date,'Weight_kg',num2cell(Kg),'Height_m',num2cell(met),' COPD',COPD,'CTR','-');
PID=input('Enter the patient ID');
CXRID=input('Enter the exam you want'); %Exam chosen
function [CTR] = get_ct_ratio(PID,CXRID,Mode,DemographicData)

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!