计算最大和最小 Feret 直径。
项目描述
Feret:一个 Python 模块,用于计算二值图像的 Feret 直径
这个 python 模块可以计算二进制图像的以下参数:
- 最大费雷特直径 (maxferet, maxf)
- 最小费雷特直径 (minferet, minf)
- Feret 直径 90° 到 minferet (minferet90, minf90)
- Feret 直径 90° 至 maxferet (maxferet90, maxf90)
请参阅此Wikipedia 页面以获取这些参数的定义。
该模块给出了与 ImageJ 一样的精确结果(使用edge=True如下所示),所有参数都是精确计算的,而不是近似的。
安装
该项目可通过 pip 获得:
pip install feret
信息片段
凸包
maxferet 和 minferet 的定义使用卡尺的图像。因此,只有与对象的凸包相对应的点才起作用。这就是为什么在任何计算之前确定凸包以减少运行时间。
麦克斯费雷
maxferet 计算为所有像素的最大欧几里得距离。
米费雷
minferet 是精确计算的,而不是近似的。我的算法使用了这样一个事实,即定义 minferet 的卡尺在一侧通过两个点,在另一侧通过一个点。该脚本遍历所有边缘点并定义一条通过该点和它旁边的线。然后计算到其他点的所有距离并取最大值。所有这些最大值中的最小值是minferet。所有这些最大值中的最大值不是maxferet,这就是单独计算它的原因。它的运行时间已经很不错了,但希望我将来可以改进它。
利用
该模块可以按如下方式使用:
首先,您需要一个二值图像,应计算其feret 直径。背景必须具有零值,对象可以具有任何非零值。对象不必是凸的。目前该模块仅支持每个图像一个对象。这意味着,如果有多个未连接的区域,脚本将计算一个包含所有区域的凸包,并为该包计算 feret 直径。
电话号码是:
import feret
# tifffile is not required nor included in this module.
import tifffile as tif
img = tif.imread('example.tif') # Image has to be a numpy 2d-array.
# get the values
maxf, minf, minf90, maxf90 = feret.all(img)
# get only maxferet
maxf = feret.max(img)
# get only minferet
minf = feret.min(img)
# get only minferet90
minf90 = feret.min90(img)
# get only maxferet90
maxf90 = feret.max90(img)
# get all the informations
res = feret.calc(img)
maxf = res.maxf
minf = res.minf
minf90 = res.minf90
minf_angle = res.minf_angle
minf90_angle = res.minf90_angle
maxf_angle = res.maxf_angle
maxf90_angle = res.maxf90_angle
有一个选项可以计算像素边缘而不是中心的 Feret 直径。只需edge=True在调用中添加一个,如下所示。这适用于所有类似的调用。
import feret
# tifffile is not required nor included in this module.
import tifffile as tif
img = tif.imread('example.tif') # Image has to be a numpy 2d-array.
# get only maxferet
maxf = feret.max(img, edge=True)
该模块还可以绘制结果。只需使用
import feret
# tifffile is not required nor included in this module.
import tifffile as tif
img = tif.imread('example.tif') # Image has to be a numpy 2d-array.
# plot the result
feret.plot(img) #edge=True can be passed here too
左边两个MinFeret点的原因上面已经描述过了。MinFeret 线不必在其两个基点之间或通过其中之一。MaxFeret 和 MinFeret 不必彼此成 90°。计算 MaxFeret 和 MinFeret 的 90° 使用feret.max90(img)和feret.min90(img)方法。