python - Skimage regionprops 特征的(面积,euler_number)尺寸在 Python 中不正确

标签 python matlab image-processing computer-vision scikit-image

我有 1797 张 Mnist 图像,为此我需要提取两个特征(FilledArea、EulerNumber)。我知道如何在 Matlab 中做到这一点。我的特征矩阵在 Matlab 中具有(并且是正确的)大小 1797*2(每个维度 1797)

matlab 代码(正常工作)

for i = 1:2*N
    img = regionprops(BW(:,:,i),'FilledArea', 'Solidity');
    features(i, 1) = img.EulerNumber;
    features(i, 2) = img.FilledArea;
    clear img;
end

我想在 python 中使用 Skimage regionprops 做同样的事情,但是对于 1797 张图像,我得到 29350*2 个特征(每个特征 29350 个属性),根据我的理解应该是 1797*2

python 代码(无法正常工作)

digits = datasets.load_digits()
label_img = digits.images
rps = regionprops(label_img, cache=False)
print(len([r.area for r in rps]))  #29350
print(len([r.euler_number for r in rps]))  #29350

我的方法可能有什么问题?为什么每个特征都有 29350 个元素而不是 1797 个元素?

最佳答案

就像您需要在 Matlab 中使用 for 循环来计算每个图像的属性一样,您也需要在 Python 中使用 for 循环来执行相同的操作。目前,您正在计算形状为 (1797, 8, 8) 的单个 3D 图像的属性,而不是计算形状为 (8, 8) 的 1797 个 2D 图像的属性。这是您所追求的在某种程度上等效的 Python 代码:

features = []
for image in digits.images:
    labels = (image > 0).astype(int)  # only one object in the image
    props = regionprops(labels, image)[0]  # only one object
    features.append((props.euler_number, props.filled_area))

关于python - Skimage regionprops 特征的(面积,euler_number)尺寸在 Python 中不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58846984/

相关文章:

python - 使用 OpenCV 检测图像中已知形状/对象的方法

python - 如何根据条件更改 2d numpy 数组的元素

Python - 返回频率最高的前 5 个单词

python - 简化python中的类docstring

matlab - 使用 for-loop MATLAB 时,scatter3 中的系列颜色与图例不匹配

java - OpenCV : Add/merge/combine 'only part' of Image A to Image B

许多文件中的 python GTK+ 操作

c++ - 使用英特尔 C++ 编译器在 C++ 中实现 MATLAB 函数

matlab - 当我有相应的 x 和 y 坐标时,在图形上插入 2 个图像

python - 什么是 alpha 修剪均值滤波器?