Beispiel #1
0
    def level_loop(cls, mask):

        # 연부조직 레벨링
        for i in range(0, 1):
            level = i + (-300)
            level_mask = magic_wand.soft_tissue(mask, level)
            title = f'{level}'
            cv.imshow(title, level_mask)
            cv.waitKey(0)
            cv.destroyAllWindows()
Beispiel #2
0
    def level_loop(self, cv_image):

        # roi 리스트 초기화
        self.roi_list.clear()

        # 레벨링
        for i in range(0, self.level_range):

            # 연부조직 level
            level = i + self.level_start

            # 이미지 레벨링
            level_image = magic_wand.soft_tissue(cv_image, level,
                                                 self.level_window,
                                                 self.level_bone,
                                                 self.level_unit)

            # 이미지 광역 쓰레숄드
            _, thresh = cv.threshold(level_image, 0, 255, 0)
            contours, _ = cv.findContours(thresh, cv.RETR_TREE,
                                          cv.CHAIN_APPROX_SIMPLE)

            for cnt in contours:
                x, y, w, h = cv.boundingRect(cnt)

                # 관심 영역 데이터를 객체에 넣고
                roi = Roi()
                roi.rect_level = level
                roi.rect_start_x = x
                roi.rect_start_y = y
                roi.rect_width = w
                roi.rect_height = h
                roi.center()
                roi.dimensions()
                roi.position_list = cnt

                # 관심 영역 사각형 표시
                # level_image = cv.rectangle(level_image, (x, y), (x + w, y + h), (255, 255, 255), 1)

                # 리스트로 보관
                self.roi_list.append(roi)

        return self.roi_list
Beispiel #3
0
    def check_result(self, array, cv_image, index):

        level = array[1]
        roi: Roi = array[2]

        level_image = magic_wand.soft_tissue(cv_image, level)
        rect_image = cv.rectangle(level_image,
                                  (roi.rect_start_x, roi.rect_start_y),
                                  (roi.rect_start_x + roi.rect_width,
                                   roi.rect_start_y + roi.rect_height),
                                  (255, 255, 255), 1)

        view_image = cv.rectangle(cv_image,
                                  (roi.rect_start_x, roi.rect_start_y),
                                  (roi.rect_start_x + roi.rect_width,
                                   roi.rect_start_y + roi.rect_height),
                                  (255, 255, 255), 1)

        mask_group = (rect_image, index)
        view_group = (view_image, index)
        self.mask_list.append(mask_group)
        self.best_list.append(view_group)
Beispiel #4
0
    def level_loop(self, cv_image):

        # roi 리스트 초기화
        self.roi_list.clear()

        # 연부조직 레벨링
        for i in range(0, 100):
            level = i + (-250)

            # 이미지 레벨링
            level_image = magic_wand.soft_tissue(cv_image, level)

            # 이미지 쓰레숄드
            ret, thresh = cv.threshold(level_image, 0, 255, 0)
            contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE,
                                                  cv.CHAIN_APPROX_SIMPLE)
            for obj in contours:
                cnt = obj
                x, y, w, h = cv.boundingRect(cnt)

                # 관심 영역 사각형 표시
                level_image = cv.rectangle(level_image, (x, y), (x + w, y + h),
                                           (255, 255, 255), 1)

                # 관심 영역 데이터를 객체에 넣고
                roi = Roi()
                roi.rect_level = level
                roi.rect_start_x = x
                roi.rect_start_y = y
                roi.rect_width = w
                roi.rect_height = h
                roi.center()
                roi.dimensions()

                # 리스트로 보관
                self.roi_list.append(roi)

        return self.roi_list
Beispiel #5
0
    def loop_logic(self, dicom_image, threshold_value):

        # 연부조직 레벨링
        for i in range(0, 1600):
            level = i + (-400)
            level_mask = magic_wand.soft_tissue(dicom_image, level)
            title = f'{level}'
            cv.imshow(title, level_mask)
            cv.waitKey(0)
            cv.destroyAllWindows()

        # 템플릿 알고리즘을 결과 좌표를 가지고 쓰레숄드 알고리즘을 적용합니다.
        rectangle_list = algorithm.template(dicom_image, self.trim_dicom)

        # 지역 변수 초기화
        local_count: int = 0
        comparative_list = []
        threshold_list = []

        # 템플릿 알고리즘 결과 좌표
        for obj in rectangle_list:
            template_x = obj[0]
            template_y = obj[1]

            # 템플릿 결과 좌표의 중심 좌표
            trim_h, trim_w = self.trim_dicom.shape
            center_x = math.floor(template_x + (trim_w / 2))
            center_y = math.floor(template_y + (trim_h / 2))
            threshold_image = magic_wand.get_threshold(threshold_value,
                                                       level_mask, center_x,
                                                       center_y)

            # title = f'{local_count}'
            # cv.imshow(title, threshold_image)
            # cv.waitKey(0)
            # cv.destroyAllWindows()

            # 두점사이 거리 저장
            distance = point2D.dot_distance(self.save_x, self.save_y, center_x,
                                            center_y)
            comparative_list.append(
                [distance, local_count, center_x, center_y])
            threshold_list.append(threshold_image)
            local_count = local_count + 1

        # 정렬
        comparative_list.sort()
        best_tuple = comparative_list[0]

        # tuple Parsing
        self.save_x = best_tuple[2]
        self.save_y = best_tuple[3]

        best_index = best_tuple[1]
        choice_image = threshold_list[best_index]

        # 리스트 비우기
        comparative_list.clear()
        threshold_list.clear()
        rectangle_list.clear()

        # threshold_image 의 ROI 영역을 정사각형 크기로 자른다.
        threshold_copy = choice_image.copy()
        x, y, w, h = self.cut_square(threshold_copy)

        self.trim_dicom = dicom_image[y:y + h, x:x + w]

        # 빈곳 체우기 로직
        result_image = algorithm.fill_blank(choice_image)

        # ORB 알고리즘 적용
        orb = algorithm.features_orb(choice_image, self.standard_image)
        print('점수 = ', orb)

        cv.imshow('result_image', result_image)
        cv.waitKey(0)
        cv.destroyAllWindows()

        # TODO: 할일
        switch = False
        # if orb[0] > 2000 or orb[0] < 100:
        #     switch = True

        return result_image, switch