diff --git a/degenerationAll.m b/degenerationAll.m index 076d820..ba7df75 100644 --- a/degenerationAll.m +++ b/degenerationAll.m @@ -1,175 +1,181 @@ -%% degenerationAll +function [] = degenerationAll(source,subject) +%%DEGENERATIONALL fills the Shoulder database with muscle degeneration measurements % -% 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. +% This function fills the Shoulder database with the muscle degeneration +% values of the case given as input. The measurements are stored in a XLS +% file. % -% Author: EPFL-LBO -% Date: 2016-09-05 +% USE: degenerationAll(source,subject) +% +% INPUT source: 'all' to compute values for all cases in the database or +% 'specific' for only one case (the subject is required as second +% argument) +% +% subject: Case IDs for which you want to compute muscle +% degeneration. Case ID is a char in the form 'P###' or 'N###' (starts with +% "P" or "N" followed by 1 to 3 digits). +% +% +% REMARKS The muscle values are saved in the muscle.xls +% file. +% +% created with MATLAB ver.: 9.2.0.556344 (R2017a) on Windows 7 +% Author: EPFL-LBO-VMC +% Date: 12-Jun-2017 % -%% - -% Source is 'all' or 'specific' (for only one case, the subject is required as second argument) -% subject is the case ID: Case IDs for which you want to compute muscle degeneration. -% Case ID is a char in the form 'P###' or 'N###' (starts with "P" or "N" followed by 1 to 3 digits). - -function [] = degenerationAll(source,subject) clc muscleName = cellstr(['SS';'IS';'SC';'TM']); switch source - %% 'specific' Cases +% 'specific' Cases case {'specific'} 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; close all [~,~,~,~,~,Ra,Ri,Ro,Rd] = muscleDegeneration(subject, char(muscleName(j)),HUThresholdMuscle,HUThresholdOsteochondroma,'image'); Degen{j+1,1} = char(muscleName(j)); Degen{j+1,2} = cell2mat(Ra); Degen{j+1,3} = cell2mat(Ri); Degen{j+1,4} = cell2mat(Ro); Degen{j+1,5} = cell2mat(Rd); end % Find the muscles folder to store output 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 +% 'all' Cases case {'all'} 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) 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 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) 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]; for j=1:4 m=1; HUThresholdMuscle = -29; HUThresholdOsteochondroma = 166.25; for i = 1:length(sCases) patient = char(sCases(i,1)); 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 clc percentage = 100*i/length(sCases); fprintf('%s %s, %3.0f%%\n', char(muscleName(j)), CTn, percentage); [~,~,~,~,~,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 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 result=[patientName, SS_results,IS_results, SC_results, TM_results]; xlswrite('muscles', result); otherwise disp('Unknown group name') end