简体   繁体   English

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

[英]Skimage regionprops feature's(area,euler_number) dimensions not correct in Python

I have 1797 Mnist Images, for which I need to extract two features (FilledArea,EulerNumber).我有 1797 个 Mnist 图像,我需要为此提取两个特征(FilledArea、EulerNumber)。 I know how to do it in Matlab.我知道如何在 Matlab 中做到这一点。 My feature matrix is having(and is correct) size of 1797*2 (1797 for each dimension) In Matlab在 Matlab

Code for matlab (working correctly) 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

I want to do same thing in python with Skimage regionprops, but for 1797 images, I am getting 29350*2 features (29350 props for each features), which according to my understanding should be 1797*2我想在 python 中使用 Skimage regionprops 做同样的事情,但是对于 1797 张图像,我得到 29350*2 个特征(每个特征有 29350 个道具),根据我的理解应该是 1797*2

Code for python (not working correctly) 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

What might be wrong with my approach?我的方法可能有什么问题? why am I having 29350 element for each feature instead of 1797?为什么每个功能都有 29350 个元素而不是 1797 个?

Just like you need a for-loop in Matlab to compute the properties for each image, you need one in Python to do the same.就像您需要 Matlab 中的 for 循环来计算每个图像的属性一样,您需要 Python 中的一个循环来执行相同的操作。 Currently, you are computing the properties for a single 3D image of shape (1797, 8, 8), instead of 1797 2D images of shape (8, 8).目前,您正在计算形状 (1797, 8, 8) 的单个3D图像的属性,而不是形状 (8, 8) 的 1797 个二维图像。 Here is the somewhat equivalent Python code for what you are after:这是您所追求的有点等效的 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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM