diff --git a/ShoulderCase/@Muscle/Muscle.m b/ShoulderCase/@Muscle/Muscle.m index 2585515..633c279 100644 --- a/ShoulderCase/@Muscle/Muscle.m +++ b/ShoulderCase/@Muscle/Muscle.m @@ -1,103 +1,120 @@ 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 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 = loadPixelCoordinates(obj) - output = load(fullfile(obj.container.dataSlicesPath,... - obj.sliceName + "_PixelCoordinates.mat")).imagesPixelCoordinates; - 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/getMaskCoordinates.m b/ShoulderCase/@Muscle/getMaskCoordinates.m index ddac808..bced46a 100644 --- a/ShoulderCase/@Muscle/getMaskCoordinates.m +++ b/ShoulderCase/@Muscle/getMaskCoordinates.m @@ -1,10 +1,10 @@ function output = getMaskCoordinates(obj, maskSuffix) mask = obj.loadMask(maskSuffix); maskIndices = find(mask); - slicePixelCoordinates = obj.loadPixelCoordinates(); + slicePixelCoordinates = obj.loadSlice("PixelCoordinates"); maskCoordinates = [... slicePixelCoordinates.x(maskIndices),... slicePixelCoordinates.y(maskIndices),... slicePixelCoordinates.z(maskIndices)]; output = maskCoordinates; end \ No newline at end of file