Exemple #1
0
def show_point(file):
    global totalpoint
    img = io.imread(file, as_grey=True)
    tt = (get_outline(
        fill_image((get_fileter_image(
            adjunction_image(np.where(img / 255 > 0.9, 1,
                                      0))))))).astype(np.uint8)
    img_filter = get_fileter_image(
        adjunction_image(np.where(img / 255 > 0.9, 1, 0)))
    fill_img = fill_image(
        (get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))
    fill_img = img_filter
    skelenton_image = skeletonize(fill_img)
    end_pointx, end_pointy = end_point(skelenton_image)
    # plt.subplot(211).imshow(fill_img)
    # pp = plt.subplot(212)
    # pp.imshow(skelenton_image)
    # pp.plot(end_pointy, end_pointx, 'r.')
    # plt.show()

    # plt.show()
    row, col = tt.shape
    # get_line(tt)
    horizontal_projection = np.sum(tt[:int(col / 2), :], axis=1)
    horizontal_projection_t = horizontal_projection[4:-4]
    index_zero = np.where(horizontal_projection_t < 2)
    index = np.where(
        horizontal_projection == np.max(horizontal_projection))[0][0]
    if (len(index_zero[0]) != 0):
        print("change index position")
        index = index_zero[0][0] + 4
    # print(horizontal_projection)
    print('基线位置: ', index)

    pointx, pointy = [], []
    vewol_point = []
    if (col <= 80):
        corners = cv2.goodFeaturesToTrack((tt).astype(np.uint8), 30, 0.2, 7)
    else:
        corners = cv2.goodFeaturesToTrack((tt).astype(np.uint8),
                                          30,
                                          0.001,
                                          0.05,
                                          blockSize=4)
    """
    1.8 skeleton
    water: 71.97

    outline:
    feature point 20,0.25,7 SVM 0.85  81.33 11859-5461
    feature point 20,0.30,7 SVM 0.85  79.72 11180-5353
    feature point 20,0.20,7 SVM 0.85  82.44 12751-5535
    feature point 20,0.20,7 SVM 0.85  82.23 12151-5521   alter-col

    1.4 skeleton
    water:  67.887

    the best result of outline:
    feature point 20,0.20,7 SVM 0.85  78.41 12151-5265   alter-col

    """
    print(row, col, '行列')
    corners = np.int0(corners)
    for item in corners:
        x, y = item.ravel()
        # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
        print(x, 'total', int(col / 3 + 0.5 + 2))
        if ((x <= int(col / 3 + 0.5) or x >= int(col / 3 * 2 + 0.5 - 2))
                and col <= 80):
            print(x, 'now x id')
            continue
        if ((x <= int(col / 4 + 0.5) or x >= int(col / 4 * 3 + 0.5))
                and col > 80):
            continue
        point_flag = True
        if (tt[y][x] == 0):
            y, x = alter_point(tt, y, x)
        vewol = 0
        for i in range(len(end_pointx)):
            if ((end_pointy[i] - x) * (end_pointy[i] - x) +
                (end_pointx[i] - y) *
                (end_pointx[i] - y) < 25) and (abs(y - index) >= 3):
                point_flag = False
                break
            elif (((end_pointy[i] - x) * (end_pointy[i] - x) +
                   (end_pointx[i] - y) * (end_pointx[i] - y) > 25)
                  and (index - y >= 2)):
                vewol = vewol + 1
        if (len(end_pointx) == vewol):
            vewol_point.append([x, y])
        if (not point_flag):
            continue
        if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)
                or y < index):
            continue

        pointx.append(x)
        pointy.append(y)

    alter_pointx, alter_pointy = alter_index_points(tt, index)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 1)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 2)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 3)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy

    pointx, pointy = del_near_point(pointx, pointy)
    if (len(pointx) == 0):
        print("MDZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
        for item in corners:
            x, y = item.ravel()
            # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
            point_flag = True

            if (tt[y][x] == 0):
                y, x = alter_point(tt, y, x)
            if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)):
                continue
            if (x <= int(col / 3 + 0.5 + 1)
                    or x >= int(col / 3 * 2 + 0.5 - 1) and col < 80):
                continue
            if (x <= int(col / 4 + 0.5 + 2)
                    or x >= int(col / 4 * 3 + 0.5 - 2) and col >= 80):
                continue
            if (3 < abs(y - index) < 8):
                pointx.append(x)
                pointy.append(y)
    print('vewol: ', vewol_point)

    if (len(vewol_point) > 0):
        new_vewol = judge_vowel(img_filter, index, vewol_point)

        if (len(new_vewol) > 0):
            print('newwol: ', new_vewol)
            for i in range(len(new_vewol)):
                pointx.append(new_vewol[i][0])
                pointy.append(new_vewol[i][1])
    position_point = get_position(skelenton_image, pointx, pointy)
    if (len(pointx) < 1):
        print("can't find feature point!")
        return 0

    result_point = find_segmention_point(adjunction_image(img), index, pointy,
                                         pointx, position_point)
    print(pointx)
    print(pointy)
    print(position_point)
    # wrfile.write(os.path.basename(file) + ',')
    # for i in range(len(result_point)):
    #     wrfile.write(str(result_point[i][1] - 3) + ' ' + str(result_point[i][0] - 3) + ' '
    #                  + str(result_point[i][3] - 3) + ' ' + str(result_point[i][2] - 3) + ',')
    # wrfile.write('\n')

    result_pointx, result_pointy = [], []
    for result in result_point:
        result_pointy.append(result[0])
        result_pointy.append(result[2])
        result_pointx.append(result[1])
        result_pointx.append(result[3])
    p2 = plt.subplot(111)
    p2.imshow(
        fill_image(
            get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1,
                                                        0)))))
    p2.imshow(img)
    # print(corners)
    # p1 = plt.subplot(212)
    # p1.plot([1, col - 1], [index, index])
    # if (col <= 80):
    #     p1.plot([int(col / 3 + 0.5), int(col / 3 + 0.5)], [0, row - 1], label[0])
    #     p1.plot([int(col / 3 * 2 + 0.5), int(col / 3 * 2 + 0.5)], [0, row - 1], label[0])
    # else:
    #     p1.plot([int(col / 4 + 0.5), int(col / 4 + 0.5)], [0, row - 1], label[0])
    #     p1.plot([int(col / 4 * 3 + 0.5), int(col / 4 * 3 + 0.5)], [0, row - 1], label[0])
    #
    for i in range(len(result_point)):
        p2.plot([result_point[i][1], result_point[i][3]],
                [result_point[i][0], result_point[i][2]], 'b.-')
    p2.plot(pointx, pointy, 'rv')
    #
    # p1.imshow(tt + skelenton_image * 2)
    # p1.plot(pointx, pointy, "r.")
    p2.imshow(np.where(adjunction_image(img) > 0, 0, 1), cmap='gray')
    plt.show()
Exemple #2
0
def show_point(file):
    global totalpoint
    img = io.imread(file, as_grey=True)
    img_filter = get_fileter_image(
        adjunction_image(np.where(img / 255 > 0.9, 1, 0)))
    fill_img = fill_image(
        (get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))
    skelenton_image = skeletonize(fill_img)
    end_pointx, end_pointy = end_point(skelenton_image)
    # plt.subplot(211).imshow(fill_img)
    # pp = plt.subplot(212)
    # pp.imshow(skelenton_image)
    # pp.plot(end_pointy, end_pointx, 'r.')
    # plt.show()
    p2 = plt.subplot(211)
    tt = (get_outline(
        fill_image((get_fileter_image(
            adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))))
    p2.imshow(
        fill_image(
            get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1,
                                                        0)))))
    p2.imshow(img)
    # print(corners)
    p1 = plt.subplot(212)

    # plt.show()
    row, col = tt.shape
    # get_line(tt)
    horizontal_projection = np.sum(tt, axis=1)
    # print(horizontal_projection)
    index = np.where(
        horizontal_projection == np.max(horizontal_projection))[0][0]
    print('基线位置: ', index)
    # vowel, new_img_vowel = judge_vowel(img_filter,index)
    p1.plot([1, col - 1], [index, index])
    p1.plot([int(col / 3 + 0.5), int(col / 3 + 0.5)], [0, row - 1], label[0])
    if (col < 100):
        p1.plot([int(col / 3 * 2 + 0.5),
                 int(col / 3 * 2 + 0.5)], [0, row - 1], label[0])
    else:
        p1.plot([int(col / 4 * 3 + 0.5),
                 int(col / 4 * 3 + 0.5)], [0, row - 1], label[0])
    pointx, pointy = [], []
    corners = cv2.goodFeaturesToTrack((tt).astype(np.uint8), 20, 0.3, 7)
    corners = np.int0(corners)
    for item in corners:
        x, y = item.ravel()
        # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
        point_flag = True
        if (tt[y][x] == 0):
            y, x = alter_point(tt, y, x)
        for i in range(len(end_pointx)):
            if ((end_pointy[i] - x) * (end_pointy[i] - x) +
                (end_pointx[i] - y) *
                (end_pointx[i] - y) < 25) and (abs(y - index) >= 3):
                point_flag = False
                break
        if (not point_flag):
            continue
        if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)
                or y < index):
            continue
        if (x <= int(col / 3 + 0.5 + 2)
                or x >= int(col / 3 * 2 + 0.5 - 2) and col < 100):
            continue
        if (x <= int(col / 3 + 0.5 + 2)
                or x >= int(col / 4 * 3 + 0.5 - 2) and col > 100):
            continue
        pointx.append(x)
        pointy.append(y)
    alter_pointx, alter_pointy = alter_index_points(tt, index)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 1)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 2)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 3)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy

    pointx, pointy = del_near_point(pointx, pointy)
    if (len(pointx) == 0):
        print("MDZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
        for item in corners:
            x, y = item.ravel()
            # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
            point_flag = True
            if (tt[y][x] == 0):
                y, x = alter_point(tt, y, x)
            if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)):
                continue
            if (x <= int(col / 3 + 0.5 + 1)
                    or x >= int(col / 3 * 2 + 0.5 - 1)):
                continue
            if (3 < abs(y - index) < 8):
                pointx.append(x)
                pointy.append(y)
    position_point = get_position(skelenton_image, pointx, pointy)

    result_point = find_segmention_point(img_filter, index, pointy, pointx,
                                         position_point)
    # print(pointx)
    # print(pointy)
    # print(position_point)
    p1.plot(pointx, pointy, "r.")
    # tt = tt.astype(np.uint8)
    # io.imsave('tt.png', tt * 255)
    # tt_new, point1, point2, point3, point4 = find_extreme_point(tt,index)
    p1.imshow(tt + skelenton_image * 2)
    # p1.plot([point1[1]],[point1[0]], 'g.')
    # p1.plot([point2[1]], [point2[0]], 'g.')
    # p1.plot([point3[1]], [point3[0]], 'y.')
    # p1.plot([point4[1]], [point4[0]], 'y.')
    # print([point1[1]], [point1[0]], 'g.')
    # print([point2[1]], [point2[0]], 'k.')
    # print([point3[1]], [point3[0]], 'y.')
    # print([point4[1]], [point4[0]], 'y.')
    plt.show()
Exemple #3
0
def show_point(file):
    global totalpoint
    img = io.imread(file, as_grey=True)
    tt = (get_outline(
        fill_image((get_fileter_image(
            adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))))
    img_filter = get_fileter_image(
        adjunction_image(np.where(img / 255 > 0.9, 1, 0)))
    fill_img = fill_image(
        (get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))
    skelenton_image = skeletonize(fill_img)
    end_pointx, end_pointy = end_point(skelenton_image)
    # plt.subplot(211).imshow(fill_img)
    # pp = plt.subplot(212)
    # pp.imshow(skelenton_image)
    # pp.plot(end_pointy, end_pointx, 'r.')
    # plt.show()

    # plt.show()
    row, col = tt.shape
    # get_line(tt)
    horizontal_projection = np.sum(tt[:int(col / 2), :], axis=1)
    horizontal_projection_t = horizontal_projection[4:-4]
    index_zero = np.where(horizontal_projection_t < 2)
    index = np.where(
        horizontal_projection == np.max(horizontal_projection))[0][0]
    if (len(index_zero[0]) != 0):
        print("change index position")
        index = index_zero[0][0] + 4
    # print(horizontal_projection)
    print('基线位置: ', index)

    pointx, pointy = [], []
    vewol_point = []
    corners = cv2.goodFeaturesToTrack((tt).astype(np.uint8), 20, 0.25, 7)
    corners = np.int0(corners)
    for item in corners:
        x, y = item.ravel()
        # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
        if (x <= int(col / 3 + 0.5 + 2)
                or x >= int(col / 3 * 2 + 0.5 - 2) and col < 100):
            continue
        if (x <= int(col / 3 + 0.5 + 2)
                or x >= int(col / 4 * 3 + 0.5 - 2) and col > 100):
            continue
        point_flag = True
        if (tt[y][x] == 0):
            y, x = alter_point(tt, y, x)
        vewol = 0
        for i in range(len(end_pointx)):
            if ((end_pointy[i] - x) * (end_pointy[i] - x) +
                (end_pointx[i] - y) *
                (end_pointx[i] - y) < 25) and (abs(y - index) >= 3):
                point_flag = False
                break
            elif (((end_pointy[i] - x) * (end_pointy[i] - x) +
                   (end_pointx[i] - y) * (end_pointx[i] - y) > 25)
                  and (index - y >= 2)):
                vewol = vewol + 1
        if (len(end_pointx) == vewol):
            vewol_point.append([x, y])
        if (not point_flag):
            continue
        if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)
                or y < index):
            continue

        pointx.append(x)
        pointy.append(y)

    alter_pointx, alter_pointy = alter_index_points(tt, index)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 1)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 2)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    alter_pointx, alter_pointy = alter_index_points(tt, index + 3)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy

    pointx, pointy = del_near_point(pointx, pointy)
    if (len(pointx) == 0):
        print("MDZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
        for item in corners:
            x, y = item.ravel()
            # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
            point_flag = True

            if (tt[y][x] == 0):
                y, x = alter_point(tt, y, x)
            if (abs(y - index) < 3 and not (total_point(tt, y, x) > 3)):
                continue
            if (x <= int(col / 3 + 0.5 + 1)
                    or x >= int(col / 3 * 2 + 0.5 - 1)):
                continue
            if (3 < abs(y - index) < 8):
                pointx.append(x)
                pointy.append(y)
    print('vewol: ', vewol_point)

    if (len(vewol_point) > 0):
        new_vewol = judge_vowel(img_filter, index, vewol_point)

        if (len(new_vewol) > 0):
            print('newwol: ', new_vewol)
            for i in range(len(new_vewol)):
                pointx.append(new_vewol[i][0])
                pointy.append(new_vewol[i][1])
    position_point = get_position(skelenton_image, pointx, pointy)
    if (len(pointx) < 1):
        print("can't find feature point!")
        return 0

    result_point = find_segmention_point(adjunction_image(img), index, pointy,
                                         pointx, position_point)
    # print(pointx)
    # print(pointy)
    # print(position_point)
    # wrfile.write(os.path.basename(file) + ',')
    # for i in range(len(result_point)):
    #     wrfile.write(str(result_point[i][1] - 3) + ' ' + str(result_point[i][0] - 3) + ' '
    #                  + str(result_point[i][3] - 3) + ' ' + str(result_point[i][2] - 3) + ',')
    # wrfile.write('\n')

    result_pointx, result_pointy = [], []
    for result in result_point:
        result_pointy.append(result[0])
        result_pointy.append(result[2])
        result_pointx.append(result[1])
        result_pointx.append(result[3])
    p2 = plt.subplot(211)
    p2.imshow(
        fill_image(
            get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1,
                                                        0)))))
    p2.imshow(img)
    # print(corners)
    p1 = plt.subplot(212)
    p1.plot([1, col - 1], [index, index])
    p1.plot([int(col / 3 + 0.5), int(col / 3 + 0.5)], [0, row - 1], label[0])
    if (col < 100):
        p1.plot([int(col / 3 * 2 + 0.5),
                 int(col / 3 * 2 + 0.5)], [0, row - 1], label[0])
    else:
        p1.plot([int(col / 4 * 3 + 0.5),
                 int(col / 4 * 3 + 0.5)], [0, row - 1], label[0])
    p2.plot(result_pointx, result_pointy, 'b.')
    p2.imshow(adjunction_image(img))
    p1.imshow(tt + skelenton_image * 2)
    p1.plot(pointx, pointy, "r.")
    plt.show()
Exemple #4
0
def show_point(file):
    global totalpoint
    img = io.imread(file, as_grey=True)
    plt.subplot(111).imshow(img)
    plt.show()
    p2 = plt.subplot(211)
    tt = (get_outline(
        fill_image(
            del_T_type(
                get_fileter_image(
                    adjunction_image(np.where(img / 255 > 0.9, 1, 0)))))))
    p2.imshow(
        fill_image(
            get_fileter_image(adjunction_image(np.where(img / 255 > 0.9, 1,
                                                        0)))))

    # print(corners)
    p1 = plt.subplot(212)

    # plt.show()
    row, col = tt.shape
    # get_line(tt)
    horizontal_projection = np.sum(tt, axis=1)
    # print(horizontal_projection)
    index = np.where(
        horizontal_projection == np.max(horizontal_projection))[0][0]
    print('基线位置: ', index)
    p1.plot([1, col - 1], [index, index])

    pointx, pointy = [], []
    corners = cv2.goodFeaturesToTrack((tt).astype(np.uint8), 1000, 0.4, 7)

    corners = np.int0(corners)
    for item in corners:
        x, y = item.ravel()
        # cv2.circle(img, (x, y), 3, [0, 255, 255], -1)
        if (tt[y][x] == 0):
            y, x = alter_point(tt, y, x)
        if (abs(y - index) < 8
                and not (total_point(tt, y, x) > 3)) or (y < index):
            continue
        pointx.append(x)
        pointy.append(y)
    alter_pointx, alter_pointy = alter_index_points(tt, index)
    pointx = pointx + alter_pointx
    pointy = pointy + alter_pointy
    p1.plot(pointx, pointy, "r.")
    tt = tt.astype(np.uint8)
    io.imsave('tt.png', tt * 255)
    tt_new, point1, point2, point3, point4 = find_extreme_point(tt, index)
    p1.imshow(tt_new, cmap="gray")
    p1.plot([point1[1]], [point1[0]], 'g.')
    p1.plot([point2[1]], [point2[0]], 'g.')
    p1.plot([point3[1]], [point3[0]], 'y.')
    p1.plot([point4[1]], [point4[0]], 'y.')
    print([point1[1]], [point1[0]], 'g.')
    print([point2[1]], [point2[0]], 'k.')
    print([point3[1]], [point3[0]], 'y.')
    print([point4[1]], [point4[0]], 'y.')
    plt.show()
    tem, only_point = [], []
    upget_next_feature_point(tt_new, point1[0], point1[1], point1[0],
                             point1[1] + 1, tem, only_point)
    k = len(totalpoint)
    print('total path: ', k)
    if k % 2 == 1:
        for i in range(k):
            point = totalpoint[i]
            point = np.array(point)
            pt = plt.subplot(2, int(k / 2 + 1), i + 1)
            pt.imshow(tt_new)
            x, y = point[:, 1], point[:, 0]
            pt.plot(x, y, str(label[i]))
    else:
        for i in range(k):
            point = totalpoint[i]
            point = np.array(point)
            pt = plt.subplot(2, int(k / 2), i + 1)
            pt.imshow(tt_new)
            x, y = point[:, 1], point[:, 0]
            pt.plot(x, y, str(label[i]))
    totalpoint = []
    plt.show()
    upget_next_feature_point(tt_new, point3[0], point3[1], point3[0],
                             point3[1] + 1, tem, only_point)
    k = len(totalpoint)
    print('total path: ', k)
    if k % 2 == 1:
        for i in range(k):
            point = totalpoint[i]
            point = np.array(point)
            pt = plt.subplot(2, int(k / 2 + 1), i + 1)
            pt.imshow(tt_new)
            x, y = point[:, 1], point[:, 0]
            pt.plot(x, y, str(label[i]))
    else:
        for i in range(k):
            point = totalpoint[i]
            point = np.array(point)
            pt = plt.subplot(2, int(k / 2), i + 1)
            pt.imshow(tt_new)
            x, y = point[:, 1], point[:, 0]
            pt.plot(x, y, str(label[i]))
    totalpoint = []
    plt.show()