diff --git a/degenerationAll.m b/degenerationAll.m index 66da7c3..e8bb0f6 100644 --- a/degenerationAll.m +++ b/degenerationAll.m @@ -1,243 +1,271 @@ %% degenerationAll % % This script analyses the muscles data obtained by contouring SS, IS, SC, and % TM. It returns an excel file (SpecificMusclesState_P###) for % 'specific' argument. In case of 'new' or 'all' arguments, the script % returns four DAT file (musclesState_SS, musclesState_IS, musclesState_SC, % musclesState_TM). They are automatically connected to the Excel file % "musclesStates". Don't forget to actualize the connections in Excel. % % Author: EPFL-LBO % Date: 2016-09-05 % %% % Source is 'all' or 'specific' (for only one case, the subject is required as second argument) % Subject is the patient number (only in case of 'specific') function [] = degenerationAll(source,subject) clc muscleName = cellstr(['SS';'IS';'SC';'TM']); switch source %% 'specific' Cases case {'specific'} if subject > 1000; subject = sprintf('N%03d',subject-1000); end subject = sprintf('P%03d',subject); Degen{1,1} = subject; Degen{1,2} = 'Atrophy'; Degen{1,3} = 'Infiltration'; Degen{1,4} = 'Osteo'; Degen{1,5} = 'Degeneration'; for j=1:4 HUThresholdMuscle = -29; HUThresholdOsteochondroma = 166.25; for i = 1:1 close all [Stot(i),Sm(i),Sa(i),Si(i),So(i),Ra(i),Ri(i),Ro(i),Rd(i)] = muscleDegeneration(subject, char(muscleName(j)),HUThresholdMuscle,HUThresholdOsteochondroma,'image'); allData(j,:,i) = [Stot(i),Sm(i),Sa(i),Si(i),So(i),Ra(i),Ri(i),Ro(i),Rd(i)]; Degen{j+1,1} = char(muscleName(j)); Degen{j+1,2} = cell2mat(Ra(i)); Degen{j+1,3} = cell2mat(Ri(i)); Degen{j+1,4} = cell2mat(Ro(i)); Degen{j+1,5} = cell2mat(Rd(i)); end end - filename = sprintf('specific/SpecificMusclesState_%s.xls', subject); + + % Load the reference 2D CT slice and associated muscle contour + CTDatabaseLocation = 'Z://data'; % Location of the CT database + + listDirInCurrDir = dir([CTDatabaseLocation '/' subject(1) '/' subject(2) '/' subject(3)]); + listDirInCurrDir = listDirInCurrDir(3:end); + + for i=1:length(listDirInCurrDir) + if ~isempty(regexp(listDirInCurrDir(i).name,['^[PN]\d{0,2}[' subject(4) '][-]\w*'], 'once')) + + listDirInCaseFolder = dir([listDirInCurrDir(i).folder '\' listDirInCurrDir(i).name]); + listDirInCaseFolder = listDirInCaseFolder(3:end); + + % In all CT folders in the current Case Folder, find CT #1 + for j=1:length(listDirInCaseFolder) + if ~isempty(regexp(listDirInCaseFolder(j).name,'^[C][T][-][PN]\d{1,3}[-]\d*[-][1]', 'once')) + % If 'muscles' exists, save iput path + if exist([listDirInCaseFolder(j).folder '\' listDirInCaseFolder(j).name '\muscles'],'dir') == 7 + inputPath = [listDirInCaseFolder(j).folder '\' listDirInCaseFolder(j).name '\muscles\']; + else + error(['Missing "muscles" directory for CaseID: ' subject]); + end + end + end + end + end + + + filename = [inputPath 'SpecificMusclesState_' subject '.xls']; xlswrite(filename, Degen); - + %% 'all' Cases case {'all'} % Pfolders = dir('results\SS\*'); % for i = 3:numel(Pfolders) % Pcases(i-2,1) = str2double(Pfolders(i).name(2:4)); % if strcmp(Pfolders(i).name(1),'N') % Pcases(i-2,1) = Pcases(i-2,1) + 1000; % end % end % Pcases = sort(Pcases); location = 'N'; l=1; rootDir = '../../../../data/N'; for levelDir1 = 0:9 for levelDir2 = 0:9 curentDir = sprintf('%s/%d/%d/N*', rootDir, levelDir1, levelDir2); folderInfo = dir(curentDir); for i=1:1:numel(folderInfo) name = folderInfo(i).name; sCases_normal{l,1} = folderInfo(i).name; sCases_normal{l,2} = levelDir1; sCases_normal{l,3} = levelDir2; sCases_normal{l,4} = 'N'; l=l+1; end end end location = 'P'; l=1; rootDir = '../../../../data/P'; for levelDir1 = 0:9 for levelDir2 = 0:9 curentDir = sprintf('%s/%d/%d/P*', rootDir, levelDir1, levelDir2); folderInfo = dir(curentDir); for i=1:1:numel(folderInfo) name = folderInfo(i).name; sCases_pathologic{l,1} = folderInfo(i).name; sCases_pathologic{l,2} = levelDir1; sCases_pathologic{l,3} = levelDir2; sCases_pathologic{l,4} = 'P'; l=l+1; end end end sCases = [sCases_normal;sCases_pathologic]; patientList = sCases(:,1); for j=1:4 m=1; HUThresholdMuscle = -29; HUThresholdOsteochondroma = 166.25; for i = 1:length(sCases) patient = char(sCases(i,1)); levelDir1 = cell2mat(sCases(i,2)); levelDir2 = cell2mat(sCases(i,3)); location = char(sCases(i,4)); CTn = strtok(patient,'-'); CTn = strtok(CTn, location); CTn = str2num(CTn); CTn = sprintf('%s%03d',location,CTn); if exist(sprintf('results/%s/%s', char(muscleName(j)),CTn),'dir') == 7 close all % subject = sprintf('P%03d',Pcases(i)); % if Pcases(i) > 1000; subject = sprintf('N%03d',Pcases(i)-1000); end clc percentage = 100*i/length(sCases); %fprintf('%s %d, %3.0f%%\n', char(muscleName(j)), CTn, percentage); fprintf('%s %s, %3.0f%%\n', char(muscleName(j)), CTn, percentage); [Stot(m),Sm(m),Sa(m),Si(m),So(m),Ra(m),Ri(m),Ro(m),Rd(m)] = muscleDegeneration(CTn, char(muscleName(j)),HUThresholdMuscle,HUThresholdOsteochondroma,'image'); else Ra(m) = cellstr(' '); Ri(m) = cellstr(' '); Ro(m) = cellstr(' '); Rd(m) = cellstr(' '); end patientName{m} = strtok(patient,'-'); m=m+1; end % result=[patientName, num2cell(SS_results)]; % xlswrite('musclesTest', results); % filename = sprintf('musclesState2_%s.dat', char(muscleName(j))); % csvwrite(filename, [patientList(:) Ra(:) Ri(:) Ro(:) Rd(:)]) if j==1 SS_results = [Ra(:) Ri(:) Ro(:) Rd(:)] end if j==2 IS_results = [Ra(:) Ri(:) Ro(:) Rd(:)] end if j==3 SC_results = [Ra(:) Ri(:) Ro(:) Rd(:)] end if j==4 TM_results = [Ra(:) Ri(:) Ro(:) Rd(:)] end end -% %% 'new' cases -% case {'new'} -% if ( exist('musclesState_SS.dat', 'file') || exist('musclesState_IS.dat', 'file') || exist('musclesState_SC.dat', 'file') || exist('musclesState_TM.dat', 'file') ) -% -% Pfolders = dir('results\SS\*'); -% for i = 3:numel(Pfolders) -% Pcases(i-2,1) = str2double(Pfolders(i).name(2:4)); -% if strcmp(Pfolders(i).name(1),'N') -% Pcases(i-2,1) = Pcases(i-2,1) + 1000; -% end -% end -% Pcases = sort(Pcases); -% -% %Read the existing dat file -% load 'musclesState_SS.dat'; -% load 'musclesState_IS.dat'; -% load 'musclesState_SC.dat'; -% load 'musclesState_TM.dat'; -% SSfile = musclesState_SS; -% ISfile = musclesState_IS; -% SCfile = musclesState_SC; -% TMfile = musclesState_TM; -% -% missing = setdiff(Pcases,SSfile(:,1)); -% -% if ~isempty(missing) -% for j=1:4 -% -% HUThresholdMuscle = -29; -% HUThresholdOsteochondroma = 166.25; -% -% for i = 1:length(missing) -% close all -% -% load 'musclesState_SS.dat'; -% load 'musclesState_IS.dat'; -% load 'musclesState_SC.dat'; -% load 'musclesState_TM.dat'; -% SSfile = musclesState_SS; -% ISfile = musclesState_IS; -% SCfile = musclesState_SC; -% TMfile = musclesState_TM; -% -% subject = sprintf('P%03d',missing(i)); -% if missing(i) > 1000; subject = sprintf('N%03d',missing(i)-1000); end -% percentage = 100*i/length(missing); -% clc -% fprintf('%s %d, %3.0f%%\n', char(muscleName(j)), missing(i), percentage) -% [Stot(i),Sm(i),Sa(i),Si(i),So(i),Ra(i),Ri(i),Ro(i),Rd(i)] = muscleDegeneration(subject, char(muscleName(j)),HUThresholdMuscle,HUThresholdOsteochondroma,'image'); -% clc -% fprintf('%d, %3.0f%%\n', missing(i), percentage) -% output = eval(sprintf('%sfile', char(muscleName(j)))); -% n=length(output); -% -% output(n+1,:) = [missing(i) Ra(i) Ri(i) Ro(i) Rd(i)]; -% output = sortrows(output,1); -% -% filename = sprintf('musclesState_%s.dat', char(muscleName(j))); -% csvwrite(filename, output) -% end -% end -% else -% disp('No new cases found!') -% end -% end + % %% 'new' cases + % case {'new'} + % if ( exist('musclesState_SS.dat', 'file') || exist('musclesState_IS.dat', 'file') || exist('musclesState_SC.dat', 'file') || exist('musclesState_TM.dat', 'file') ) + % + % Pfolders = dir('results\SS\*'); + % for i = 3:numel(Pfolders) + % Pcases(i-2,1) = str2double(Pfolders(i).name(2:4)); + % if strcmp(Pfolders(i).name(1),'N') + % Pcases(i-2,1) = Pcases(i-2,1) + 1000; + % end + % end + % Pcases = sort(Pcases); + % + % %Read the existing dat file + % load 'musclesState_SS.dat'; + % load 'musclesState_IS.dat'; + % load 'musclesState_SC.dat'; + % load 'musclesState_TM.dat'; + % SSfile = musclesState_SS; + % ISfile = musclesState_IS; + % SCfile = musclesState_SC; + % TMfile = musclesState_TM; + % + % missing = setdiff(Pcases,SSfile(:,1)); + % + % if ~isempty(missing) + % for j=1:4 + % + % HUThresholdMuscle = -29; + % HUThresholdOsteochondroma = 166.25; + % + % for i = 1:length(missing) + % close all + % + % load 'musclesState_SS.dat'; + % load 'musclesState_IS.dat'; + % load 'musclesState_SC.dat'; + % load 'musclesState_TM.dat'; + % SSfile = musclesState_SS; + % ISfile = musclesState_IS; + % SCfile = musclesState_SC; + % TMfile = musclesState_TM; + % + % subject = sprintf('P%03d',missing(i)); + % if missing(i) > 1000; subject = sprintf('N%03d',missing(i)-1000); end + % percentage = 100*i/length(missing); + % clc + % fprintf('%s %d, %3.0f%%\n', char(muscleName(j)), missing(i), percentage) + % [Stot(i),Sm(i),Sa(i),Si(i),So(i),Ra(i),Ri(i),Ro(i),Rd(i)] = muscleDegeneration(subject, char(muscleName(j)),HUThresholdMuscle,HUThresholdOsteochondroma,'image'); + % clc + % fprintf('%d, %3.0f%%\n', missing(i), percentage) + % output = eval(sprintf('%sfile', char(muscleName(j)))); + % n=length(output); + % + % output(n+1,:) = [missing(i) Ra(i) Ri(i) Ro(i) Rd(i)]; + % output = sortrows(output,1); + % + % filename = sprintf('musclesState_%s.dat', char(muscleName(j))); + % csvwrite(filename, output) + % end + % end + % else + % disp('No new cases found!') + % end + % end result=[patientName, SS_results,IS_results, SC_results, TM_results]; xlswrite('muscles', result); otherwise disp('Unknown group name') end diff --git a/muscleContours.m b/muscleContours.m index e0fed61..3486f88 100644 --- a/muscleContours.m +++ b/muscleContours.m @@ -1,124 +1,148 @@ %% muscleContours % This script allows to select the contours on Tiff images of the four % cuff rotator muscles: Supraspinatus (SS), Infraspinatus (IS), Subscapularis (SC) % and Teres Minor (TM). % % INPUT: % subject: ### subject number % type: 'normal' or 'pathologic' % Author: EPFL-LBO % Date: 2016-09-05 %% function [] = muscleContours(subject,type) -directory = '../../../../data'; -location = 'Pathologic'; +directory = 'Z://data'; % Location of the CT database +location = 'P'; CTn = sprintf('P%03d',subject); + +listDirInCurrDir = dir([directory '/' CTn(1) '/' CTn(2) '/' CTn(3)]); +listDirInCurrDir = listDirInCurrDir(3:end); + +for i=1:length(listDirInCurrDir) + if ~isempty(regexp(listDirInCurrDir(i).name,['^[PN]\d{0,2}[' CTn(4) '][-]\w*'], 'once')) + + listDirInCaseFolder = dir([listDirInCurrDir(i).folder '\' listDirInCurrDir(i).name]); + listDirInCaseFolder = listDirInCaseFolder(3:end); + + % In all CT folders in the current Case Folder, find CT #1 + for j=1:length(listDirInCaseFolder) + if ~isempty(regexp(listDirInCaseFolder(j).name,'^[C][T][-][PN]\d{1,3}[-]\d*[-][1]', 'once')) + outputPath = [listDirInCaseFolder(j).folder '\' listDirInCaseFolder(j).name]; + end + end + end +end + + pathologic_list = dir(sprintf('%s/%s/P*', directory, location)); %Create the case list for i = 1:1:numel(pathologic_list) % Loop over the list of patients and extract the complete name of the specific patient name = pathologic_list(i).name; t = strfind(name,CTn); if t == 1; patient_name = name; end end -finaldirectory = sprintf('%s/%s/%s/CT-%s-1/amira/*tif',directory, location, patient_name, patient_name); +finaldirectory = [outputPath '\amira\*tif']; muscleName = cellstr(['SS';'IS';'SC';'TM']); close all; % Close all figure windows except those created by imtool. imtool close all; % Close all figure windows created by imtool. workspace; % Make sure the workspace panel is showing. fontSize = 16; imageWindow = [-100 200]; % Choose file [inputFile, inputPath] = uigetfile(finaldirectory,'Select the image for muscle atrophy measurement'); whereisp = strfind(inputFile, 'P'); if isempty(whereisp) whereisp = strfind(inputFile, 'N'); if isempty(whereisp) return end end subject = inputFile(whereisp:whereisp+3); % Read gray scale image. inputImage = imread(sprintf('%s%s',inputPath,inputFile)); if size(inputImage,3) == 3 % Calculate the monochrome luminance by combining the RGB values according to the NTSC standard inputImage = 0.2989*inputImage(:,:,1)... +0.5870*inputImage(:,:,2)... +0.1140*inputImage(:,:,3); end for i=1:4; finished = 'Redo'; while strcmp('Redo',finished) msg = 0; % 0 = no message % clc; % Clear command window. close all; % Close all figure windows except those created by imtool. imtool close all; % Close all figure windows created by imtool. imshow(inputImage,imageWindow); imagetitle = sprintf('Select %s ideal section', char(muscleName(i))); title(imagetitle, 'FontSize', fontSize); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. if msg == 1 message = sprintf('Select the ideal section of your muscle in the image. \nLeft click to place points and draw a polygon. Click again on the first point to close the shape.\nYou can move the points once the line is closed. Double-click or right-click and "Create Mask" to finish.'); msg = 0; uiwait(msgbox(message)); end binaryImage1 = roipoly(); if isempty(binaryImage1) error('Invalid selection or interface closed') end binaryImage1 = bwmorph(binaryImage1,'majority'); % Get coordinates of the boundary of the polygonal drawn region. structBoundaries1 = bwboundaries(binaryImage1); xy1 = structBoundaries1{1}; % Get n by 2 array of x,y coordinates. x1 = xy1(:, 2); % Columns. y1 = xy1(:, 1); % Rows. hold on plot(x1, y1, 'color','green'); % check contours finished = questdlg('Please verify the contours. Press "Save" if they are satisfactory or "Redo" if you would like to redo the selection. ',... 'Contour verification','Save','Redo','Save'); end %% Report results % mkdir('./results',subject); - outputPath = sprintf('results/%s/%s/', char(muscleName(i)), subject); - mkdir(outputPath); + if exist([outputPath '\muscles'],'dir') == 0 + mkdir(outputPath,'muscles'); + end + + outputPath2 = [outputPath '\muscles\' char(muscleName(i)) '\']; + mkdir(outputPath2); outputFile = sprintf('ssContours%s',subject); % Check for overwriting - overwrite = exist(sprintf('%s%s.mat',outputPath,outputFile), 'file'); + overwrite = exist(sprintf('%s%s.mat',outputPath2,outputFile), 'file'); switch overwrite case 2 isoverwrite = questdlg('Overwrite existing file ?', 'Warning', 'No', 'Yes', 'No'); switch isoverwrite case 'Yes' - save(sprintf('%s%s.mat',outputPath,outputFile), 'inputImage','binaryImage1') - saveas(gcf,sprintf('%s%s.tif',outputPath,outputFile)) - fprintf('%s%s.mat\n%s%s.tif\n',outputPath,outputFile,outputPath,outputFile); + save(sprintf('%s%s.mat',outputPath2,outputFile), 'inputImage','binaryImage1') + saveas(gcf,sprintf('%s%s.tif',outputPath2,outputFile)) + fprintf('%s%s.mat\n%s%s.tif\n',outputPath2,outputFile,outputPath2,outputFile); end case 0 - save(sprintf('%s%s.mat',outputPath,outputFile), 'inputImage','binaryImage1') - saveas(gcf,sprintf('%s%s.tif',outputPath,outputFile)) - fprintf('%s%s.mat\n%s%s.tif\n',outputPath,outputFile,outputPath,outputFile); + save(sprintf('%s%s.mat',outputPath2,outputFile), 'inputImage','binaryImage1') + saveas(gcf,sprintf('%s%s.tif',outputPath2,outputFile)) + fprintf('%s%s.mat\n%s%s.tif\n',outputPath2,outputFile,outputPath2,outputFile); end end close all; end \ No newline at end of file diff --git a/muscleDegeneration.m b/muscleDegeneration.m index ea114ca..7be72e8 100644 --- a/muscleDegeneration.m +++ b/muscleDegeneration.m @@ -1,170 +1,194 @@ function [Stot,Sm,Sa,Si,So,Ra,Ri,Ro,Rd] = muscleDegeneration(subject,muscleName,HUThresholdMuscle,HUThresholdOsteochondroma,output) %%MUSCLEDEGENERATION computes degeneration parameters from muscle contours % % This function is called by "degenerationAll.m" and returns muscle atrophy, % fat infiltration, osteochondroma and degeneration values. % % USE: muscleDegeneration(subject,muscleName,HUThresholdMuscle,HUThresholdOsteochondroma,output) % % INPUT subject: patient number % muscleName: name of the rotator cuff muscle being measured (SS,IS, SC or TM) % HUThresholdMuscle: HU threshold used for muscle segmentation (muscle-fat limit) % HUThresholdMuscle:HU threshold used for osteochondroma segmentation (muscle-osteochondroma limit) % output: type of output returned (image) % % OUTPUT Stot: total area of the muscle fossa % Sm: area of the degenerated muscle, without atrophy, fat infiltration and osteochondroma % Sa: area of the atrophy (Stot - Sm) % Si: area of fat infiltration % So: area of osteochondroma % Ra: ratio of muscle atrophy (area atrophy over total area of muscle fossa) % Ri: ratio of fat infiltration in the muscle (area fat infiltration over total area of muscle fossa) % Ro: ratio of osteochondroma in the muscle (area osteochondroma over total area of muscle fossa) % Rd: the ratio of degeneration of the muscle (sum of atrophy, fat infiltration and osteochondroma over total area of muscle fossa) % % REMARKS The degeneration values are saved in .dat files. % % created with MATLAB ver.: 9.2.0.556344 (R2017a) on Windows 7 % Author: EPFL-LBO-VMC % Date: 07-Jun-2017 % % Load the reference 2D CT slice and associated muscle contour -inputPath = sprintf('results/%s/%s/', muscleName, subject); -inputFile = sprintf('ssContours%s.mat',subject); +CTDatabaseLocation = 'Z://data'; % Location of the CT database + +listDirInCurrDir = dir([CTDatabaseLocation '/' subject(1) '/' subject(2) '/' subject(3)]); +listDirInCurrDir = listDirInCurrDir(3:end); + +for i=1:length(listDirInCurrDir) + if ~isempty(regexp(listDirInCurrDir(i).name,['^[PN]\d{0,2}[' subject(4) '][-]\w*'], 'once')) + + listDirInCaseFolder = dir([listDirInCurrDir(i).folder '\' listDirInCurrDir(i).name]); + listDirInCaseFolder = listDirInCaseFolder(3:end); + + % In all CT folders in the current Case Folder, find CT #1 + for j=1:length(listDirInCaseFolder) + if ~isempty(regexp(listDirInCaseFolder(j).name,'^[C][T][-][PN]\d{1,3}[-]\d*[-][1]', 'once')) + % If 'muscles' exists, save iput path + if exist([listDirInCaseFolder(j).folder '\' listDirInCaseFolder(j).name '\muscles'],'dir') == 7 + inputPath = [listDirInCaseFolder(j).folder '\' listDirInCaseFolder(j).name '\muscles\' muscleName '\']; + inputFile = ['ssContours' subject '.mat']; + else + error(['Missing "muscles" directory for CaseID: ' subject]); + end + end + end + end +end + contouredMuscle = load(sprintf('%s%s',inputPath,inputFile)); % --Atrophied muscle segmentation-- % Normalize image and thresholds rangeHU = double([min(contouredMuscle.inputImage(:)) max(contouredMuscle.inputImage(:))]); normalizedThresholdMuscle = (HUThresholdMuscle-rangeHU(1))/(rangeHU(2)-rangeHU(1)); normalizedThresholdOsteochondroma = (HUThresholdOsteochondroma-rangeHU(1))/(rangeHU(2)-rangeHU(1)); normalizedInputImage = double(contouredMuscle.inputImage)-rangeHU(1); normalizedInputImage = normalizedInputImage/(rangeHU(2)-rangeHU(1)); % Mask image using muscle fossa contours maskedImage = normalizedInputImage; maskedImage(~contouredMuscle.binaryImage1) = 0; % Segment using muscle threshold myMuscle = imbinarize(maskedImage,normalizedThresholdMuscle); myMuscle = imfill(myMuscle, 'holes'); % Fill holes % --Atrophied muscle without fat infiltration segmentation-- % Mask image using atrophied muscle segmentation maskedImage = normalizedInputImage; maskedImage(~myMuscle) = 0; % Segment using muscle threshold myMuscleNoFat = imbinarize(maskedImage,normalizedThresholdMuscle); % --Osteochondroma segmentation-- %Segment using osteochondroma threshold myOsteo = imbinarize(maskedImage,normalizedThresholdOsteochondroma); myOsteo = imfill(myOsteo, 'holes'); % Fill holes % --Measure atrophy and degeneration so that Stot = Sa + Sm + Si + So-- Stot = bwarea(contouredMuscle.binaryImage1); % Stot = manually delimited contours Sa = bwarea(contouredMuscle.binaryImage1) - bwarea(myMuscle); % Sa = atrophy zone (around muscle) So = bwarea(myOsteo); % So = osteochondroma Sm = bwarea(myMuscleNoFat) - bwarea(myOsteo); % Sm = remaining muscle (muscle only) Si = bwarea(myMuscle) - Sm - So; % Si = fat infiltration Ra = Sa/Stot; % Atrophy ratio Ro = So/Stot; % Osteochondroma ratio Ri = Si/Stot; % Fat infiltration ratio Rd = (Stot-Sm)/Stot; % Degeneration % Report results if exist('output','var') == 1 if strcmp(output,'image') % --Plot CT slice with all contours-- fontSize = 14; visualizationWindow = [-100 200]; imshow(contouredMuscle.inputImage,visualizationWindow); [r,c,~] = size(contouredMuscle.inputImage); title(sprintf('Muscle threshold: %.0fHU, Muscle atrophy: %.2f%%, Muscle infiltration: %.2f%%, Osteochondroma: %.2f%%', ... HUThresholdMuscle,Ra*100,Ri*100,Ro*100), 'FontSize', fontSize); set(gcf, 'Position', get(0,'Screensize'), 'Visible', 'on'); % Maximize figure. hold on % Plot muscle fossa contours. structBoundaries = bwboundaries(contouredMuscle.binaryImage1); xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates. x = xy(:, 2); % Columns. y = xy(:, 1); % Rows. plot(x, y, 'color','green'); % Plot atrophied muscle contours structBoundaries = bwboundaries(myMuscle); xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates. x = xy(:, 2); % Columns. y = xy(:, 1); % Rows. plot(x, y, 'color','blue'); % Plot fat infiltration contours structBoundaries = bwboundaries(myMuscleNoFat); for i = 1:size(structBoundaries,1) xy = structBoundaries{i}; % Get n by 2 array of x,y coordinates. x = xy(:, 2); % Columns. y = xy(:, 1); % Rows. hold on; % Keep the image. plot(x, y,'color','red'); end % Plot osteochondroma contours structBoundaries = bwboundaries(myOsteo); for i = 1:size(structBoundaries,1) xy = structBoundaries{i}; % Get n by 2 array of x,y coordinates. x = xy(:, 2); % Columns. y = xy(:, 1); % Rows. hold on; % Keep the image. plot(x, y,'color','magenta'); end % --Save images-- outputFile = sprintf('ssDegeneration%s.%d',subject,HUThresholdMuscle); saveas(gcf,sprintf('%s%s.png',inputPath,outputFile)) set(gca,'Units','normalized','Position',[0 0 1 1]) set(gcf,'Units','pixels','Position',[200 200 c r]); f = getframe(gcf); imwrite(f.cdata,sprintf('%s%s.jpg',inputPath,outputFile)); close all % --Write to file-- dlmwrite(sprintf('%s%s.dat',inputPath,outputFile),... [HUThresholdMuscle; Ra*100; Ri*100; Ro*100; Rd*100],'precision',6); end end Ra = num2cell(Ra); Ri = num2cell(Ri); Ro = num2cell(Ro); Rd = num2cell(Rd); end \ No newline at end of file