diff --git a/ShoulderCase/@RotatorCuff/createSliceMatthieu.m b/ShoulderCase/@RotatorCuff/createSliceMatthieu.m index c5cf6ea..2919f0b 100644 --- a/ShoulderCase/@RotatorCuff/createSliceMatthieu.m +++ b/ShoulderCase/@RotatorCuff/createSliceMatthieu.m @@ -1,110 +1,110 @@ function createSliceMatthieu(obj) % This function and its results might be reffered as % Matthieu algorithm and Matthieu slices in some studies. % % This method has been written to simplify, improve, and make reusable % the Nathan's slicing algorithm written in createSlicesNathan(). % This means: % - taking advantage of the MATLAB obliqueslice() method wich wasn't available % when Nathan's algorithm has been written. % - encapsulating the slicing data and methods in a DicomVolumeSlicer object. % - being able to orient a slice according to dicom points coordinates. % - being able to crop the slice according to dicom points coordinates % and cropping dimensions given in the dicom set units. % % Images and pixel spacings are saved at: % shoulder/dataDev/*/*/*/SCase-IPP/CT-SCase-IPP/matlab/shoulder/muscles/oblique_slice/ assert(not(obj.shoulder.scapula.coordSys.isEmpty), 'Scapula coordinate system not measured.'); slices = getSlices(obj); sliceName = "rotatorCuffMatthieu"; saveImages(obj, slices.forSegmentation, slices.forMeasurements, sliceName); saveImagesPixelSpacings(obj, slices.pixelSpacings, sliceName); saveImagesPixelCoordinates(obj, slices.pixelCoordinates, sliceName); end function output = getSlices(obj) SCase = obj.shoulder.SCase; scapula = obj.shoulder.scapula; try rotatorCuffSlicer = DicomVolumeSlicer(SCase.getSmoothDicomPath); catch rotatorCuffSlicer = DicomVolumeSlicer(SCase.dataDicomPath); rotatorCuffSlicer.applyGaussianFilter(); end % The 3D volume must be normalised for the slices not to be distorted rotatorCuffSlicer.setMinimalResolutionDividedBy(2); rotatorCuffSlicer.normaliseVolume; medialisation = 5; origin = scapula.coordSys.origin - medialisation*scapula.coordSys.ML; rotatorCuffSlicer.slice(origin, scapula.coordSys.ML); % The following lines set the slice to display a 200x150 mm area around the % scapula with the "Y" shape of the scapula oriented up rotatorCuffSlicer.orientSliceUpwardVector(origin, scapula.coordSys.IS); height = 200; width = 150; inferiorisation = 40; rotatorCuffSlicer.crop(origin - inferiorisation*scapula.coordSys.IS, height, width); % Rotator cuff segmentation code requires 1024x1024 pixels images if size(rotatorCuffSlicer.sliced,1) > size(rotatorCuffSlicer.sliced,2) rotatorCuffSlicer.resize([1024 nan]); else rotatorCuffSlicer.resize([nan 1024]); end rotatorCuffSlicer.addEmptyBackgroundToSlice(1024,1024); rawSlice = rotatorCuffSlicer.sliced; rotatorCuffSlicer.rescaleSliceToUint8; slice8Bit = rotatorCuffSlicer.sliced; rotatorCuffSlicer.sliced = rawSlice; rotatorCuffSlicer.rescaleSliceToInt16; slice16Bit = rotatorCuffSlicer.sliced; slicePixelCoordinates = rotatorCuffSlicer.getSlicedPixelCoordinates(); % Flip the slices for right and left shoulders to give similar slices if obj.shoulder.side=='L' slice8Bit=rot90(flipud(slice8Bit),2); slice16Bit=rot90(flipud(slice16Bit),2); - slicePixelCoordinates=rot90(flipud(slicePixelCoordinates),2); + slicePixelCoordinates=flipud(slicePixelCoordinates); end slicePixelSpacings = rotatorCuffSlicer.slicedPixelSpacings; output.forSegmentation = slice8Bit; output.forMeasurements = slice16Bit; output.pixelSpacings = slicePixelSpacings; output.pixelCoordinates = slicePixelCoordinates; end function saveImages(obj,imageForSegmentation,imageForMeasurements,sliceName) imwrite(imageForSegmentation,... fullfile(obj.dataSlicesPath,sliceName + "_ForSegmentation.png")); save(fullfile(obj.dataSlicesPath,sliceName + "_ForMeasurements.mat"),... 'imageForMeasurements'); end function saveImagesPixelSpacings(obj,imagesPixelSpacings,sliceName) save(fullfile(obj.dataSlicesPath,sliceName + "_PixelSpacings.mat"),... 'imagesPixelSpacings'); end function saveImagesPixelCoordinates(obj,imagesPixelCoordinates,sliceName) save(fullfile(obj.dataSlicesPath,sliceName + "_PixelCoordinates.mat"),... 'imagesPixelCoordinates'); end \ No newline at end of file