function segmentRotatorCuffMuscles(obj) cleanRotatorCuffSegmentationWorkspace(obj); sendImageToRotatorCuffSegmentationWorkspace(obj); callRotatorCuffSegmentation(obj); saveSegmentationResults(obj); cleanRotatorCuffSegmentationWorkspace(obj); end function cleanRotatorCuffSegmentationWorkspace(obj) rotatorCuffSegmentationPath = ConfigFileExtractor.getVariable('pythonDir'); delete(fullfile(rotatorCuffSegmentationPath,'input','*')); delete(fullfile(rotatorCuffSegmentationPath,'IS','*')); delete(fullfile(rotatorCuffSegmentationPath,'SC','*')); delete(fullfile(rotatorCuffSegmentationPath,'SS','*')); delete(fullfile(rotatorCuffSegmentationPath,'TM','*')); end function sendImageToRotatorCuffSegmentationWorkspace(obj) SCase = obj.shoulder.SCase; rotatorCuffSegmentationPath = ConfigFileExtractor.getVariable('pythonDir'); imageForSegmentationPath = fullfile(SCase.dataCTPath,'muscles','imageForSegmentation.png'); copyfile(imageForSegmentationPath,fullfile(rotatorCuffSegmentationPath,'input',[SCase.id '.png'])); end function callRotatorCuffSegmentation(obj) %% Apply UNIBE method to automatically segment normal muscle pythonDir = ConfigFileExtractor.getVariable('pythonDir'); pythonCommandActivateEnvironment= ['source ' fullfile(pythonDir,'venv','bin','activate') ';']; pythonCommandMoveToSegmentationWorkspace = ['cd ' pythonDir ';']; pythonCommandExecuteSegmentation = [fullfile(pythonDir,'rcseg.py') ' segment input' ';']; [~, pythonCommandOutput] = system([pythonCommandActivateEnvironment,... pythonCommandMoveToSegmentationWorkspace,... pythonCommandExecuteSegmentation]); disp(pythonCommandOutput); end function saveSegmentationResults(obj) SCase = obj.shoulder.SCase; muscles = {'IS' 'SS' 'SC' 'TM'}; rotatorCuffSegmentationPath = ConfigFileExtractor.getVariable('pythonDir'); autoSegmentationPath = fullfile(SCase.dataCTPath,'muscles','segmentations','auto'); if not(isfolder(autoSegmentationPath)) mkdir(autoSegmentationPath); end for i = 1:length(muscles) copyfile(fullfile(rotatorCuffSegmentationPath,muscles{i},[SCase.id '.png']),... fullfile(autoSegmentationPath,[muscles{i} '.png']) ); end end