谁能解释为什么`skimage.measure.perimeter(img)`返回此结果? [英] Can anyone explain why `skimage.measure.perimeter(img)` returns this result?

查看:262
本文介绍了谁能解释为什么`skimage.measure.perimeter(img)`返回此结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我测试scikit-image方法时,遇到了skimage.measure.perimeter(image),但无法解释此函数的输出.

As I test scikit-image methods ,I came across skimage.measure.perimeter(image) but couldn't explain the output of this function.

import numpy as np  
image=np.zeros((100,100))  
image[10:30,10:30]=1                   # this creates a white square  
from skimage.measure import perimeter  
x=perimeter(image)  
print x                               #Should be (20+20+20+20) = 80  
76.0        <<<<<<<<<< it returns this value

我是否误解了该函数应该返回什么.我知道周长是一条围绕区域的路径.
注意:-
(1)计算出的周长与返回的周长之间的差并不总是乘以4,因为无论是正方形,矩形还是任何其他多边形,有时它都可以是6.
更新:=
(1)功能页面

Did I misunderstand what this function should return . I know that perimeter is a path that surrounds an area .
Note:-
(1) The difference between the calculated perimeter and the returned perimeter not always by 4.as sometimes it can be 6 no matter it's a square a rectangle or any other polygon.
Update:=
(1) The function page

推荐答案

您正在使用哪个版本的skimage? 版本0.6和 github来源没有skimage.measure.perimeter函数.

Which version of skimage are you using ? Version 0.6 and github sources do not have a skimage.measure.perimeter function.

另外,我认为您的意思是第3行:image[10:30, 10:30] = 1

Additionaly, I think you meant line 3 : image[10:30, 10:30] = 1

修改

好吧,我想我明白了.从0.7.1版开始,该函数在_regionprops.py中定义. 结果76实际上是正确的.它计算形状为白色正方形(20,20)的周长.

Ok, I think I got it. The function is defined in _regionprops.py since version 0.7.1. The result 76 is actually right. It computes the perimeter of a white square of shape (20, 20).

您认为每侧占20像素,总计80像素.但是这样做,您可以计算两倍于角落的像素.删除您最终以76像素为周长的角像素.

You think each side accounts for 20 pixels which total to 80 pixels. But by doing so you count twice the corner pixels. Removing corner pixels you end-up with a perimeter of 76 pixels.

对于其他形状,差异可能不超过4个像素.

For other shapes the difference may not be of 4 pixels.

编辑2

查看源代码和文档:

  • regionprops的文档说,周长是周长的近似值:

将轮廓近似为一条线的对象的周长 通过4连通性穿过边界像素的中心.

Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity.

  • 代码计算出一个border_image,它由图像减去侵蚀后的图像组成.该数组与我第一次编辑时所考虑的周长相对应.

    • The code computes a border_image which consist of the image minus its erosion. This array corresponds to the idea of the perimeter I had in the first edit.

      然后通过对边界图像应用卷积和加权和来计算周长.我认为这样做是为了计算通过文档中所述的穿过边界像素中心的线的长度.

      It then computes the perimeter by applying a convolution and a weighted sum to the border image. I think this is done to compute the length of the line going through the centers of border pixels as stated in the doc.

      如果您想了解更多详细信息,请咨询一名开发人员.这是软件包中的一个非常新的功能.

      If you want more details, you should ask one of the dev. This is a very new function in the package.

      这篇关于谁能解释为什么`skimage.measure.perimeter(img)`返回此结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆