function segmentMuscles(obj, sliceName, maskName) % sliceName is the part before the '_ForSegmentation.png' part of the name of % the file that is sent to rcseg. % maskName is the part before the '_Mask.png' part of the name of % the file that is saved in the SCase folder. cleanRotatorCuffSegmentationWorkspace(obj); sendImageToRotatorCuffSegmentationWorkspace(obj,sliceName); callRotatorCuffSegmentation(obj); saveSegmentationResults(obj,maskName); 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,sliceName) SCase = obj.shoulder.SCase; rotatorCuffSegmentationPath = ConfigFileExtractor.getVariable('pythonDir'); imageForSegmentationPath = fullfile(obj.dataSlicesPath,sliceName + "_ForSegmentation.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,maskName) SCaseID = obj.shoulder.SCase.id; rotatorCuffSegmentationPath = ConfigFileExtractor.getVariable('pythonDir'); for muscleName = ["SC", "SS", "IS", "TM"] try copyfile(fullfile(rotatorCuffSegmentationPath,muscleName,SCaseID + ".png"),... fullfile(obj.(muscleName).dataMaskPath,maskName + "_Mask.png") ); catch ME warning(ME.message) end end end