diff --git a/ShoulderCase/@Muscle/Muscle.m b/ShoulderCase/@Muscle/Muscle.m index 91c2863..f9e9d13 100644 --- a/ShoulderCase/@Muscle/Muscle.m +++ b/ShoulderCase/@Muscle/Muscle.m @@ -1,145 +1,145 @@ 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 = ""; + container = []; + name = []; + segmentationName = []; + sliceName = []; - PCSA = nan; - atrophy = nan; - fat = nan; - osteochondroma = nan; - degeneration = nan; - - centroid = nan; - insertion = nan; - forceApplicationPoint = nan; - forceVector = nan; + PCSA = []; + atrophy = []; + fat = []; + osteochondroma = []; + degeneration = []; + + centroid = []; + insertion = []; + forceApplicationPoint = []; + forceVector = []; end properties (Access = ?RotatorCuff) 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 output = dataContourPath(obj) output = fullfile(obj.dataPath, "contour"); 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(getConfig().rotatorCuffSliceName); obj.setSegmentationName(getConfig().rotatorCuffSegmentationName); subdivisionsResolutionX = getConfig().muscleSubdivisionsResolutionInMm.x; subdivisionsResolutionY = getConfig().muscleSubdivisionsResolutionInMm.y; success = Logger.timeLogExecution(... obj.name+sprintf(" subdivide segmentation %d mm by %d mm: ",... subdivisionsResolutionX, subdivisionsResolutionY),... @(obj) obj.subdivide(subdivisionsResolutionX, subdivisionsResolutionY),... obj); success = 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+" insertion: ",... @(obj) obj.measureInsertion(obj.container.shoulder.humerus), 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); % Saving subdivisions resulting from obj.subdivide(10,10) increases the % file size by roughly 15MB (x2000%) for 1 shoulder only. % This caused problems with the MATLAB save/load functions and, even % if saving in the v7.3 MAT-file version solved the problems, subdivisions % don't need to be saved so they are removed here. obj.subdivisions = []; output = success; end end end