function measureSlicedPixelSpacings(obj) longestRowIndex = find(sum(obj.pointsInVolume,2) == max(sum(obj.pointsInVolume,2))); longestColumnIndex = find(sum(obj.pointsInVolume) == max(sum(obj.pointsInVolume))); longestRowElements = find(obj.pointsInVolume(longestRowIndex(1),:)); longestColumnElements = find(obj.pointsInVolume(:,longestColumnIndex(1))); leftSliceIndex = [longestRowIndex(1),longestRowElements(1)]; leftVolumeIndex = [round(obj.slicedX(leftSliceIndex(1),leftSliceIndex(2))),... round(obj.slicedY(leftSliceIndex(1),leftSliceIndex(2))),... round(obj.slicedZ(leftSliceIndex(1),leftSliceIndex(2)))]; % Volume boundaries can be exceeded at this point but must be asserted. leftVolumeIndex = max(leftVolumeIndex,[1 1 1]); leftVolumeIndex = min(leftVolumeIndex,size(obj.volume)); leftPoint = obj.getPointCoordinates(leftVolumeIndex); rightSliceIndex = [longestRowIndex(1),longestRowElements(end)]; rightVolumeIndex = [round(obj.slicedX(rightSliceIndex(1),rightSliceIndex(2))),... round(obj.slicedY(rightSliceIndex(1),rightSliceIndex(2))),... round(obj.slicedZ(rightSliceIndex(1),rightSliceIndex(2)))]; % Volume boundaries can be exceeded at this point but must be asserted. rightVolumeIndex = max(rightVolumeIndex,[1 1 1]); rightVolumeIndex = min(rightVolumeIndex,size(obj.volume)); rightPoint = obj.getPointCoordinates(rightVolumeIndex); topSliceIndex = [longestColumnElements(1),longestColumnIndex(1)]; topVolumeIndex = [round(obj.slicedX(topSliceIndex(1),topSliceIndex(2))),... round(obj.slicedY(topSliceIndex(1),topSliceIndex(2))),... round(obj.slicedZ(topSliceIndex(1),topSliceIndex(2)))]; % Volume boundaries can be exceeded at this point but must be asserted. topVolumeIndex = max(topVolumeIndex,[1 1 1]); topVolumeIndex = min(topVolumeIndex,size(obj.volume)); topPoint = obj.getPointCoordinates(topVolumeIndex); bottomSliceIndex = [longestColumnElements(end),longestColumnIndex(1)]; bottomVolumeIndex = [round(obj.slicedX(bottomSliceIndex(1),bottomSliceIndex(2))),... round(obj.slicedY(bottomSliceIndex(1),bottomSliceIndex(2))),... round(obj.slicedZ(bottomSliceIndex(1),bottomSliceIndex(2)))]; % Volume boundaries can be exceeded at this point but must be asserted. bottomVolumeIndex = max(bottomVolumeIndex,[1 1 1]); bottomVolumeIndex = min(bottomVolumeIndex,size(obj.volume)); bottomPoint = obj.getPointCoordinates(bottomVolumeIndex); % window = true(100,100); % pointsInVolumeSubarray = findSubarray(obj.pointsInVolume,window); % assert(not(isempty(pointsInVolumeSubarray)),'No subarray found'); % row = pointsInVolumeSubarray(1,1); % column = pointsInVolumeSubarray(1,2); % % originIndex = [round(obj.slicedX(row,column)),... % round(obj.slicedY(row,column)),... % round(obj.slicedZ(row,column))]; % originPoint = obj.getPointCoordinates(originIndex); % % bottomLeftIndex = [round(obj.slicedX(row+size(window,1)-1,column)),... % round(obj.slicedY(row+size(window,1)-1,column)),... % round(obj.slicedZ(row+size(window,1)-1,column))]; % bottomLeftPoint = obj.getPointCoordinates(bottomLeftIndex); % % topRightIndex = [round(obj.slicedX(row,column+size(window,2)-1)),... % round(obj.slicedY(row,column+size(window,2)-1)),... % round(obj.slicedZ(row,column+size(window,2)-1))]; % topRightPoint = obj.getPointCoordinates(topRightIndex); % % obj.slicedPixelSpacings = [norm(topRightPoint-originPoint)/(size(window,2)-1),... % norm(bottomLeftPoint-originPoint)/(size(window,1)-1)]; obj.slicedPixelSpacings = [norm(rightPoint - leftPoint)/(length(longestRowElements)-1),... norm(bottomPoint - topPoint)/(length(longestColumnElements)-1)]; end