Пример #1
0
def calc_simetry(image):
    '''Calculates leaf simerty.'''

    _, _, rect_points = f.find_rect(image, keep_original=True)
    middle_points = [
    ]  #Array of points that represent the centers of all four sides of the rectangle

    #Calculate middle poitns
    for poin_index in range(len(rect_points)):
        next_point_index = (poin_index + 1) % 4
        point1 = rect_points[poin_index]
        point2 = rect_points[next_point_index]

        x = int((point1[0] + point2[0]) / 2)
        y = int((point1[1] + point2[1]) / 2)
        middle_point = [x, y]
        middle_points.append(middle_point)

    #Initiation
    segments = []  #Segments of leafs
    segment_areas = []  #Areas of leaf segments
    simetries = []  #Simetries (rectangles) of leafs
    thresh = f.find_thresh(image)

    #Create al the simetries (right, left, bottom, top)
    simetries.append(
        np.array([
            rect_points[0], middle_points[0], middle_points[2], rect_points[3]
        ]))
    simetries.append(
        np.array([
            middle_points[0], rect_points[1], rect_points[2], middle_points[2]
        ]))
    simetries.append(
        np.array([
            rect_points[0], rect_points[1], middle_points[1], middle_points[3]
        ]))
    simetries.append(
        np.array([
            middle_points[3], middle_points[1], rect_points[2], rect_points[3]
        ]))

    #Calculates the segments and the areas
    for sim in simetries:
        canvas = np.zeros((image.shape[0], image.shape[1], 1), dtype=np.uint8)
        cv2.fillPoly(canvas, pts=[sim], color=(255, 255, 255))
        segments.append(cv2.bitwise_and(thresh, canvas))

        area = cv2.countNonZero(canvas)
        segment_areas.append(area)

    #Calculate the simery
    tb_simetry = segment_areas[3] / segment_areas[2]
    rl_simetry = segment_areas[1] / segment_areas[0]
    simetry = tb_simetry * rl_simetry

    #Return simetry
    return simetry
Пример #2
0
def calc_hw_ratio(image):
    '''Calculates height-width ratio of a leaf.'''

    #Calculates the height and the width
    _, rect, _ = f.find_rect(image)
    height = rect[1][0]
    width = rect[1][1]

    #Returns ratio
    return height / width
Пример #3
0
def calc_cw_ratio(image):
    '''Calculates ratio betwen circumference of 
    eclosing circle ant the width of the leaf.'''

    #Calculates circumference of the enclosing circle
    encl_circ = calc_encl_circumference(image)

    #Calculates the width of the leaf
    _, rect, _ = f.find_rect(image)
    width = rect[1][1]

    #Return ratio
    return encl_circ / width
Пример #4
0
def calc_ch_ratio(image):
    '''Calculates ratio betwen circumference of 
    eclosing circle ant the height of the leaf.'''

    #Calculates circumference of the enclosing circle
    encl_circ = calc_encl_circumference(image)

    #Calculates the height of the leaf
    _, rect, _ = f.find_rect(image)
    height = rect[1][0]

    #Returns the ratio
    return encl_circ / height
Пример #5
0
def calc_rectangularity(image):
    '''Calculates the rectangularity of a leaf.'''

    #Calculates enclosing rectangle area
    _, rect, _ = f.find_rect(image)
    rect_area = rect[1][0] * rect[1][1]

    #Calculate leaf area
    leaf_area = calc_leaf_area(image)

    #Calculate rectangularity in procentage
    rectangularity = (leaf_area / rect_area) * 100

    return rectangularity
Пример #6
0
def calc_center_distance_ratio(image):
    '''Calculates the ratio between the circumference 
    of the enclosing circle and the distance between the centers
    of the enclosing circle and rectangel.'''

    #Calculates circumference of the enclosing circle
    encl_circ = calc_encl_circumference(image)

    #Calulate centers
    _, _, encl = f.find_encl(image, keep_original=True)
    _, _, rect = f.find_rect(image, keep_original=True)
    encl_center = encl[0]
    rect_center = rect[0]

    #Calulate distance
    distance = sqrt(
        pow(encl_center[0] - rect_center[0], 2) +
        pow(encl_center[1] - rect_center[1], 2))

    #Returns ratio
    return encl_circ / distance