def flank_seperation(image):
    """
    Flank area
    :param:
    :return:
    """
    color_img = image.copy()

    green_channel = color_img[:, :, 1]
    show_image("A2_green_channel", green_channel)

    image_new = green_channel.copy()
    green_channel = cv2.medianBlur(green_channel, 39)
    show_image("A2_blur", green_channel)

    image_new[np.where(green_channel >= 180)] = [0]
    show_image("A3_patch1", image_new)

    color_img[np.where(green_channel >= 180)] = [0, 0, 0]
    show_image("A4_patch2", color_img)

    crop_img, _ = crop.crop_radial_arc_two_centres(color_img,
                                                   centre_x1=400,
                                                   centre_y1=-320,
                                                   centre_x2=400,
                                                   centre_y2=-200,
                                                   radius1=500,
                                                   radius2=650,
                                                   theta1=235,
                                                   theta2=310)
    show_image("A5_crop", crop_img)

    return
def teeth_seperation(image):

    num = 0

    color_img = image.copy()
    #gray_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2GRAY)
    #save_image("A1_gray",gray_img)

    green_channel = color_img[:, :, 1]
    save_image("A2_green_a", green_channel)
    image_bk = green_channel.copy()
    green_channel = cv2.medianBlur(green_channel, 21)
    save_image("A2_green_blur", green_channel)

    img1, _ = crop.crop_radial_arc_two_centres(green_channel,
                                               centre_x1=400,
                                               centre_y1=-270,
                                               centre_x2=400,
                                               centre_y2=-280,
                                               radius1=500,
                                               radius2=650,
                                               theta1=230,
                                               theta2=310)
    img1_bk = img1.copy()
    save_image("A3_crop", img1)

    image_bk[np.where(img1 < 200)] = [0]
    save_image("A4_binary", image_bk)

    time2 = time.time()

    return
def teeth_seperation_method2(original_img):
    new_img = original_img.copy()

    gray_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2GRAY)
    blur = cv2.medianBlur(gray_img, 3)
    original_image = cv2.equalizeHist(blur)
    gray_image = original_image.copy()
    pos = np.where(gray_image < 180)
    gray_image[pos] = [0]
    pos = np.where(gray_image > 180)
    gray_image[pos] = [255]
    gray_image, _ = crop.crop_radial_arc_two_centres(gray_image,
                                                     centre_x1=400,
                                                     centre_y1=-270,
                                                     centre_x2=400,
                                                     centre_y2=-280,
                                                     radius1=450,
                                                     radius2=650,
                                                     theta1=230,
                                                     theta2=310)
    # showimage("gray_imge", gray_image)
    contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_NONE)[-2:]
    for cnt in contours:
        contourArea = cv2.contourArea(cnt)
        area = cv2.contourArea(cnt)
        if area < 10000 or area > 100000:
            continue
        x, y, w, h = cv2.boundingRect(cnt)

        ROI = new_img[y:y + h, x:x + w]
        cv2.namedWindow("Largest Contour", cv2.WINDOW_NORMAL)
        cv2.imshow("Largest Contour", ROI)
        cv2.waitKey(0)
def teeth_seperation_method1(color_image):
    """
    teeth seperation
    :param image:
    :return:
    """
    gray_img = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    blur = cv2.medianBlur(gray_img, 3)
    original_image = cv2.equalizeHist(blur)
    gray_image = original_image.copy()
    pos = np.where(gray_image < 180)
    gray_image[pos] = [0]
    pos = np.where(gray_image > 180)
    gray_image[pos] = [255]
    gray_image, _ = crop.crop_radial_arc_two_centres(gray_image,
                                                     centre_x1=400,
                                                     centre_y1=-270,
                                                     centre_x2=400,
                                                     centre_y2=-280,
                                                     radius1=450,
                                                     radius2=650,
                                                     theta1=230,
                                                     theta2=310)
    # showimage("gray_imge", gray_image)
    contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_NONE)[-2:]
    num = 0
    if contours:
        for c in contours:
            area = cv2.contourArea(c)
            if area < 10000 or area > 100000:
                continue
            num += 1
            print(" tooth count: " + str(num) + "\t area: " + str(area))
            rect = cv2.minAreaRect(c)
            width = int(rect[1][0])
            height = int(rect[1][1])
            angle = rect[2]
            print("\t\t\t\t", angle)

            box = cv2.boxPoints(rect)
            box = np.int0(box)

            M = cv2.moments(box)
            if M["m00"] != 0:
                cX = int(M["m10"] / M["m00"])
                cY = int(M["m01"] / M["m00"])
            else:
                cX, cY = 0, 0

            image_patch = sub_image(color_image, (cX, cY), angle + 90, height,
                                    width)
            showimage('A1_original_img_' + str(num), image_patch)
            # blue_img = image_patch[:,:,0]
            # showimage("processed_img" + str(num), blue_img)
            # dent_detection(blue_img, num, angle)

        return 'Teeth seperated successfully'
def teeth_seperation(image):
    global threshold_value

    threshold_value = 180

    color_img = image.copy()

    green_channel = color_img[:, :, 1]
    save_image("A2_green_a", green_channel)

    image_bk = green_channel.copy()
    green_channel = cv2.medianBlur(green_channel, 21)
    save_image("A2_green_blur", green_channel)

    img1, _ = crop.crop_radial_arc_two_centres(green_channel,
                                               centre_x1=400,
                                               centre_y1=-270,
                                               centre_x2=400,
                                               centre_y2=-280,
                                               radius1=500,
                                               radius2=650,
                                               theta1=230,
                                               theta2=310)

    img1_bk = img1.copy()
    save_image("A3_crop", img1)

    image_bk[np.where(img1 <= threshold_value)] = [0]
    save_image("A4_binary", image_bk)

    find_contour(image_bk)
    time2 = time.time()
    # find_teeth_freq(img1_bk)
    #find_teeth(img1,img1_bk)
    print("time taken for freq:", abs(time.time() - time2))

    return
Exemple #6
0
    def process_separation(self, contour=False):
        img = self.image
        threshold_value, flank_list, teeth_list = 200, [], []
        blank_img_flank = np.zeros_like(img)
        blank_img_teeth = np.zeros_like(img)
        img_blur = cv2.medianBlur(img, 29)

        crop_img, _ = crop.crop_radial_arc_two_centres(img_blur,
                                                       centre_x1=400,
                                                       centre_y1=-320,
                                                       centre_x2=400,
                                                       centre_y2=-150,
                                                       radius1=500,
                                                       radius2=510,
                                                       theta1=230,
                                                       theta2=310)
        green_channel = crop_img[:, :, 1]
        cv2.imwrite("analysis/A2_blur.jpg", green_channel)

        pos1 = np.where(
            np.logical_and(green_channel <= threshold_value,
                           green_channel > 0))
        pos2 = np.where(green_channel >= threshold_value)

        blank_img_flank[pos1] = img[pos1]
        blank_img_teeth[pos2] = img[pos2]

        if contour:
            flank_list = self.__find_contour(col_image=blank_img_flank, type=1)

            teeth_list = self.__find_contour(col_image=blank_img_teeth, type=0)
            return flank_list, teeth_list

        flank_list.append(blank_img_flank)
        teeth_list.append(blank_img_teeth)
        return flank_list, teeth_list
Exemple #7
0
def triangle_seperation(gray_image1):
    """
    triangle seperation
    :param image:
    :return:
    """

    # showimage("gray_imge", gray_image)
    cv2.imshow("Gray", gray_image1)
    # ret, gray_image = cv2.threshold(gray_image1, 50, 255,cv2.THRESH_BINARY_INV)
    # ret, gray_image = cv2.threshold(gray_image1, 60, 255, 0)

    # gray_image = gray_image1.copy()
    gray_image = np.zeros(gray_image1.shape, dtype=np.uint8)
    showimage("black image", gray_image)

    # pos = np.where(gray_image1 < 80)
    # gray_image[pos] = [255]
    pos = np.where(gray_image1 < 80)
    gray_image[pos] = [255]

    print(gray_image.shape)
    showimage("gray_imge", gray_image)

    gray_image, _ = crop.crop_radial_arc_two_centres(gray_image,
                                                     centre_x1=390,
                                                     centre_y1=-80,
                                                     centre_x2=380,
                                                     centre_y2=-90,
                                                     radius1=550,
                                                     radius2=675,
                                                     theta1=230,
                                                     theta2=310)

    showimage("gray_image_triangle", gray_image)
    contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_NONE)[-2:]
    num = 0
    if contours:
        for c in contours:
            area = cv2.contourArea(c)
            if area < 100 or area > 100000:
                continue
            num += 1
            print(" tooth count: " + str(num) + "\t area: " + str(area))
            x, y, w, h = cv2.boundingRect(c)

            img = cv2.rectangle(gray_image1, (x, y), (x + w, y + h),
                                (255, 0, 0), 2)
            showimage("rectangle", img)

            rect = cv2.minAreaRect(c)
            rows, cols = gray_image.shape
            width = int(rect[1][0])
            height = int(rect[1][1])
            center = rect[0]
            angle = rect[2]
            print("\t\t\t\t", angle)

            box = cv2.boxPoints(rect)
            box = np.int0(box)

            text = str(num)
            col1 = (0, 0, 0)
            rot = cv2.getRotationMatrix2D(center, angle - 90, 1)

            M = cv2.moments(box)
            if M["m00"] != 0:
                cX = int(M["m10"] / M["m00"])
                cY = int(M["m01"] / M["m00"])
            else:
                cX, cY = 0, 0

            image_patch = sub_image(gray_image1, (cX, cY), angle + 90, height,
                                    width)
            showimage('A1_original_img_' + str(num), image_patch)
            # blue_img = image_patch[:,:,0]
            # showimage("processed_img" + str(num), blue_img)
            # dent_detection(blue_img, num, angle)

    return 'Triangles separated successfully'
def teeth_seperation(color_image):
    """
    teeth seperation
    :param image:
    :return:
    """
    # gray_img = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    # blur = cv2.medianBlur(gray_img, 3)
    # original_image = cv2.equalizeHist(blur)
    # gray_image = original_image.copy()
    # pos = np.where(gray_image < 170)
    # gray_image[pos] = [0]
    # pos = np.where(gray_image > 170)
    # gray_image[pos] = [255]

    gray = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    ret, gray_image = cv2.threshold(gray, 170, 255, 0)

    showimage("gray_imge", gray_image)

    # gray_image, _ = crop.crop_radial_arc_two_centres(gray_image, centre_x1=400, centre_y1=-270,
    #                                              centre_x2=400, centre_y2=-280, radius1=450, radius2=650,
    #                                              theta1=230,
    #                                              theta2=310)
    gray_image, _ = crop.crop_radial_arc_two_centres(gray_image,
                                                     centre_x1=340,
                                                     centre_y1=-210,
                                                     centre_x2=340,
                                                     centre_y2=-280,
                                                     radius1=450,
                                                     radius2=675,
                                                     theta1=230,
                                                     theta2=310)

    showimage("gray_imge_teeth", gray_image)
    # break
    contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_NONE)[-2:]
    num = 0
    if contours:
        for c in contours:
            area = cv2.contourArea(c)
            if area < 3000 or area > 100000:
                continue
            num += 1
            print(" tooth count: " + str(num) + "\t area: " + str(area))
            x, y, w, h = cv2.boundingRect(c)

            # saylee kanitkar
            gray_three = cv2.merge([gray_image, gray_image, gray_image])
            img = cv2.rectangle(gray_three, (x, y), (x + w, y + h),
                                (255, 0, 0), 2)
            showimage("rectangle", img)

            rect = cv2.minAreaRect(c)
            rows, cols = gray_image.shape
            width = int(rect[1][0])

            height = int(rect[1][1])
            center = rect[0]
            angle = rect[2]
            print("\t\t\t\t", angle)

            box = cv2.boxPoints(rect)
            box = np.int0(box)

            text = str(num)
            col1 = (0, 0, 0)
            rot = cv2.getRotationMatrix2D(center, angle - 90, 1)

            M = cv2.moments(box)
            if M["m00"] != 0:
                cX = int(M["m10"] / M["m00"])
                cY = int(M["m01"] / M["m00"])
            else:
                cX, cY = 0, 0

            image_patch = sub_image(color_image, (cX, cY), angle + 90, height,
                                    width)
            showimage('A1_original_img_' + str(num), image_patch)
            blue_img = image_patch[:, :, 0]
            showimage("processed_img" + str(num), blue_img)
            # dent_detection(blue_img, num, angle)

    return 'Teeth seperated successfully'
def between_flank_part(color_image):
    """

    :param color_image:
    :return:
    """

    showimage("color_img", color_image)
    gray_img = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
    blur = cv2.medianBlur(gray_img, 9)
    original_image = cv2.equalizeHist(blur)
    gray_image = original_image.copy()
    showimage('gray', gray_image)
    pos = np.where(gray_image < 180)
    gray_image[pos] = [0]

    showimage('gray_image', gray_image)

    crop1, _ = crop.crop_radial_arc_two_centres(gray_image,
                                                centre_x1=400,
                                                centre_y1=-300,
                                                centre_x2=400,
                                                centre_y2=-170,
                                                radius1=410,
                                                radius2=610,
                                                theta1=230,
                                                theta2=310)
    showimage('crop1', crop1)

    contours, hierarchy = cv2.findContours(crop1, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_NONE)[-2:]
    n = 0
    if contours:
        for c in contours:
            area = cv2.contourArea(c)
            if area < 3000 or area > 15000:
                continue

            x, y, w, h = cv2.boundingRect(c)

            # saylee kanitkar
            gray_three = cv2.merge([crop1, crop1, crop1])
            img = cv2.rectangle(gray_three, (x, y), (x + w, y + h),
                                (255, 0, 0), 2)
            showimage("rectangle", img)
            n += 1
            rect = cv2.minAreaRect(c)

            rows, cols = gray_image.shape
            width = int(rect[1][0])
            print(" tooth count: " + str(n) + "\t area: " + str(area))

            height = int(rect[1][1])
            center = rect[0]
            angle = rect[2]
            box = cv2.boxPoints(rect)
            box = np.int0(box)

            rot = cv2.getRotationMatrix2D(center, angle - 90, 1)
            img = cv2.warpAffine(color_image, rot, (rows, cols))

            M = cv2.moments(box)
            if M["m00"] != 0:
                cX = int(M["m10"] / M["m00"])
                cY = int(M["m01"] / M["m00"])
            else:
                cX, cY = 0, 0

            image_patch = sub_image(color_image, (cX, cY), angle + 90, height,
                                    width)
            showimage('original_img' + str(n), image_patch)