diff --git a/ShoulderCase/@Muscle/Muscle.m b/ShoulderCase/@Muscle/Muscle.m index 633c279..5d73398 100644 --- a/ShoulderCase/@Muscle/Muscle.m +++ b/ShoulderCase/@Muscle/Muscle.m @@ -1,120 +1,124 @@ classdef Muscle < handle % The Muscle class is linked to a segmented muscle file (a mask) % and to the slice it has been segmented out of. % % Then, this class can measured values linked to the PCSA and the % muscle's degeneration. properties container = nan; name = ""; segmentationName = ""; sliceName = ""; PCSA = nan; atrophy = nan; fat = nan; osteochondroma = nan; degeneration = nan; centroid = nan; forceApplicationPoint = nan; forceVector = nan; end + properties (Access = private) + subdivisions + end + methods function obj = Muscle(musclesContainer,muscleName) obj.container = musclesContainer; obj.name = muscleName; [~, ~] = mkdir(obj.dataPath); [~, ~] = mkdir(obj.dataMaskPath); end function output = dataPath(obj) output = fullfile(obj.container.dataPath, obj.name); end function output = dataMaskPath(obj) output = fullfile(obj.dataPath, "mask"); end function setSliceName(obj, value) obj.sliceName = value; end function setSegmentationName(obj, value) obj.segmentationName = value; end function output = loadMask(obj, maskSuffix) output = logical(imread(fullfile(obj.dataMaskPath,... obj.segmentationName+"_"+maskSuffix+".png"))); end function saveMask(obj, mask, maskSuffix) imwrite(mask, fullfile(obj.dataMaskPath,... obj.segmentationName+"_"+maskSuffix+".png")); end function output = loadSlice(obj, sliceSuffix) filePattern = fullfile(obj.container.dataSlicesPath,... obj.sliceName + "_" + sliceSuffix + "*"); matchingFile = dir(filePattern); assert(not(isempty(matchingFile)),... "File matching %s not found", filePattern); assert(length(matchingFile) <= 1,... "Multiple matching files found. Include file extension in given suffix"); if endsWith(matchingFile.name, ".mat") loadedFile = load(fullfile(matchingFile.folder, matchingFile.name)); % loaded Matlab archives are structures whose fields contain the saved % variables. When only one variable is saved we want to return its value % directly and avoid having to retrieve the original variable name. loadedVariables = string(fields(loadedFile)); if isequal(length(loadedVariables), 1) loadedFile = loadedFile.(loadedVariables); end output = loadedFile; elseif endsWith(matchingFile.name, ".png") output = imread(fullfile(matchingFile.folder, matchingFile.name)); end end function output = measureFirst(obj) % Call methods that can be run after morphology() methods has been run % by all ShoulderCase objects. obj.setSliceName("rotatorCuffMatthieu"); obj.setSegmentationName("autoMatthieu"); success = Logger.timeLogExecution(... obj.name+" measure and save contour: ",... @(obj) obj.measureAndSaveContour(), obj); success = success | Logger.timeLogExecution(... obj.name+" measure and save centroid: ",... @(obj) obj.measureAndSaveCentroid(), obj); success = success | Logger.timeLogExecution(... obj.name+" PCSA: ",... @(obj) obj.measurePCSA(), obj); success = success | Logger.timeLogExecution(... obj.name+" atrophy: ",... @(obj) obj.measureAtrophy(), obj); success = success | Logger.timeLogExecution(... obj.name+" fat infiltration: ",... @(obj) obj.measureFatInfiltration(), obj); success = success | Logger.timeLogExecution(... obj.name+" osteochondroma: ",... @(obj) obj.measureOsteochondroma(), obj); success = success | Logger.timeLogExecution(... obj.name+" degeneration: ",... @(obj) obj.measureDegeneration(), obj); success = success | Logger.timeLogExecution(... obj.name+" humeral head contact point: ",... @(obj) obj.measureHumerusContactPoint(), obj); success = success | Logger.timeLogExecution(... obj.name+" force: ",... @(obj) obj.measureForceVector(), obj); output = success; end end end diff --git a/ShoulderCase/@Muscle/subdivide.m b/ShoulderCase/@Muscle/subdivide.m new file mode 100644 index 0000000..79d1ba8 --- /dev/null +++ b/ShoulderCase/@Muscle/subdivide.m @@ -0,0 +1,8 @@ +function subdivide(obj, numberOfRadialDivisions, numberOfAngularDivisions) + subdivider = MaskSubdivider(obj.loadMask("Segmentation")); + subdivider.setNumberOfRadialDivisions(numberOfRadialDivisions); + subdivider.setNumberOfAngularDivisions(numberOfAngularDivisions); + humeralHeadCenter = obj.container.shoulder.humerus.center; + subdivider.setCenter(obj.getClosestPointInSlice(humeralHeadCenter)); + obj.subdivisions = subdivider.getMaskSubdivisionsStacked(); +end \ No newline at end of file