diff --git a/ShoulderCase/@DicomVolume/applyGaussianFilter.m b/ShoulderCase/@DicomVolume/applyGaussianFilter.m new file mode 100644 index 0000000..5d0bf96 --- /dev/null +++ b/ShoulderCase/@DicomVolume/applyGaussianFilter.m @@ -0,0 +1,4 @@ +function applyGaussianFilter(obj) + % Apply a gaussian filter to the loaded volume. + obj.volume = imgaussfilt3(obj.volume, 1); +end \ No newline at end of file diff --git a/ShoulderCase/@RotatorCuff/createSliceMatthieu.m b/ShoulderCase/@RotatorCuff/createSliceMatthieu.m index 201c716..a1bea26 100644 --- a/ShoulderCase/@RotatorCuff/createSliceMatthieu.m +++ b/ShoulderCase/@RotatorCuff/createSliceMatthieu.m @@ -1,98 +1,99 @@ 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.'); [imageForSegmentation,imageForMeasurements,imagesPixelSpacings,imagesPixelCoordinates] = getSlices(obj); sliceName = "rotatorCuffMatthieu"; saveImages(obj,imageForSegmentation,imageForMeasurements,sliceName); saveImagesPixelSpacings(obj,imagesPixelSpacings,sliceName); saveImagesPixelCoordinates(obj,imagesPixelCoordinates,sliceName); end function [slice8Bit,slice16Bit,slicePixelSpacings,slicePixelCoordinates] = 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; rotatorCuffSlicer.slice(scapula.coordSys.origin,scapula.coordSys.ML); % The following lines set the slice to display a 300x300 mm area around the % scapula with the "Y" shape of the scapula oriented up rotatorCuffSlicer.orientSliceUpwardVector(scapula.coordSys.origin,scapula.coordSys.IS); rotatorCuffSlicer.crop(scapula.coordSys.origin-100*scapula.coordSys.IS,300,300); % 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); end slicePixelSpacings = rotatorCuffSlicer.slicedPixelSpacings; 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