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 '_Segmentation.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 = getConfig().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 = getConfig().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 = getConfig("convertTextToString", false).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 = getConfig().pythonDir; for muscleName = ["SC", "SS", "IS", "TM"] try copyfile(fullfile(rotatorCuffSegmentationPath,muscleName,SCaseID + ".png"),... fullfile(obj.(muscleName).dataMaskPath,maskName + "_Segmentation.png") ); catch ME warning(ME.message) end end end