【Python】计算圆度

公式

圆度计算公式:

4*PI*A/P^2

其中PI表示Π,A表示区域面积,P表示区域周长。

Opencv

def compute_roundness(label_image):
    contours, hierarchy = cv2.findContours(np.array(label_image, dtype=np.uint8), cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)
    a = cv2.contourArea(contours[0]) * 4 * math.pi
    b = math.pow(cv2.arcLength(contours[0], True), 2)
    if b == 0:
        return 0
    return a / b

skimage 

from scipy import misc
import numpy as np
from skimage.measure import label, regionprops
import cv2
import math

mask = misc.imread(mask_path)
img = misc.imread(img_path, mode="L")
mask = label(mask)
mask_props = regionprops(mask, intensity_image=img)
for mask_prop in mask_props:
    roundness = (4 * math.pi * mask_prop['area']) / (mask_prop['perimeter']**2)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值