def get_points_left(ds): img = dicom_utils.transformToHu(ds, ds.pixel_array) if type(ds.WindowWidth) == pydicom.multival.MultiValue: windowWidth = ds.WindowWidth[0] else: windowWidth = ds.WindowWidth if type(ds.WindowCenter) == pydicom.multival.MultiValue: windowCenter = ds.WindowCenter[0] else: windowCenter = ds.WindowCenter th_img = image_processing.thresholdCTImage(img, windowCenter, windowWidth) alt_th = image_processing.thresholdAlternative(img, windowCenter, windowWidth) alt_th = alt_th.astype(np.uint8) roi_img2 = image_processing.getROI(alt_th) roi_img2 = roi_img2.astype(np.uint8) roi_img = image_processing.getROI(th_img) flood_full = roi_img | roi_img2 flood_full = flood_full.astype(np.uint8) kernel = np.ones((3, 2)) flood_full = cv2.morphologyEx(flood_full, cv2.MORPH_CLOSE, kernel) _, throclea_points = interesting_points.getDeepestPointTrochlea( roi_img2, "left") rotated_img, angle = image_processing.rotateFemur(roi_img2, "left") _, (extBot, extBot2) = interesting_points.getPointsFemur( rotated_img, roi_img2, -angle, ) return extBot, extBot2, throclea_points
def get_point_tibia_right(ds): if type(ds.WindowWidth) == pydicom.multival.MultiValue: windowWidth = ds.WindowWidth[0] else: windowWidth = ds.WindowWidth if type(ds.WindowCenter) == pydicom.multival.MultiValue: windowCenter = ds.WindowCenter[0] else: windowCenter = ds.WindowCenter img_tibia = dicom_utils.transformToHu(ds, ds.pixel_array) img_tibia_norm = dicom_utils.normalizeImage255(img_tibia, windowCenter, windowWidth) th_img = image_processing.thresholdAlternative(img_tibia, windowCenter, windowWidth) left_image = image_processing.getROI2(th_img) left_image = left_image.astype(np.uint8) rotated_img, angle = image_processing.rotateFemur(left_image, "right") contours, _ = cv2.findContours(rotated_img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) sorted_contours = sorted(contours, key=cv2.contourArea, reverse=True) north_west = tuple(sorted_contours[0][sorted_contours[0][:, :, 1].argmin()][0]) transform_points = np.array([[[north_west[0], north_west[1]]]]) h, w = rotated_img.shape[:2] center = (w // 2, h // 2) M = cv2.getRotationMatrix2D(center, angle, 1.0) tf2 = cv2.transform(transform_points, M) points = [north_west[0], north_west[1]] return tf2[0][0]
def __init__(self, dcmfile): ds = pydicom.dcmread(dcmfile) self.originalImage = ds.pixel_array if type(ds.WindowCenter) == pydicom.multival.MultiValue: self.WindowCenter = ds.WindowCenter[0] else: self.WindowCenter = ds.WindowCenter if type(ds.WindowWidth) == pydicom.multival.MultiValue: self.WindowWidth = ds.WindowWidth[0] else: self.WindowWidth = ds.WindowWidth self.PixelSpacing = ds.PixelSpacing self.RescaleSlope = ds.RescaleSlope self.RescaleIntercept = ds.RescaleIntercept self.huImage = dicom_utils.transformToHu(ds, ds.pixel_array) self.contourImage = image_processing.thresholdAlternative(self.huImage, self.WindowCenter, self.WindowWidth)
def get_points_rotula_right(ds): if type(ds.WindowWidth) == pydicom.multival.MultiValue: windowWidth = ds.WindowWidth[0] else: windowWidth = ds.WindowWidth if type(ds.WindowCenter) == pydicom.multival.MultiValue: windowCenter = ds.WindowCenter[0] else: windowCenter = ds.WindowCenter img = dicom_utils.transformToHu(ds, ds.pixel_array) alt_th = image_processing.thresholdAlternative(img, windowCenter, windowWidth) alt_th = alt_th.astype(np.uint8) roi_img2 = image_processing.getROI2(alt_th) roi_img2 = roi_img2.astype(np.uint8) points1, points2 = interesting_points.getPointsRotula(roi_img2) return points1, points2
def get_points_right(ds): img = dicom_utils.transformToHu(ds, ds.pixel_array) if type(ds.WindowWidth) == pydicom.multival.MultiValue: windowWidth = ds.WindowWidth[0] else: windowWidth = ds.WindowWidth if type(ds.WindowCenter) == pydicom.multival.MultiValue: windowCenter = ds.WindowCenter[0] else: windowCenter = ds.WindowCenter th_img = image_processing.thresholdCTImage(img, windowCenter, windowWidth) alt_th = image_processing.thresholdAlternative(img, windowCenter, windowWidth) roi_img2 = image_processing.getROI2(alt_th) roi_img2 = roi_img2.astype(np.uint8) tr_im, throclea_points = interesting_points.getDeepestPointTrochlea( roi_img2) roi_img = image_processing.getROI2(th_img) rotated_img, angle = image_processing.rotateFemur(roi_img2, "right") _, (extBot, extBot2) = interesting_points.getPointsFemur(rotated_img, roi_img2, -angle) return extBot, extBot2, throclea_points