图像处理Skimage库的中label和regionprops函数解释
Scikit-image将图片作为numpy数组进行处理,在医学图像处理中会忽略图像的spacing信息。导入:from skimage.measure import label,regionprops1、Skimage中的label参数解释:作用:实现连通区域标记output=label(input,neighbors= None,background= None,return_num= Fal
Scikit-image将图片作为numpy数组进行处理,在医学图像处理中会忽略图像的spacing信息。
导入:from skimage.measure import label,regionprops
1、Skimage中的label参数解释:
作用:实现连通区域标记
output=label(input, neighbors = None, background = None, return_num = False, connectivity = None)
input:是一个二值图像
connectivity:连通域设置,connectivity=1为四连通;connectivity=2为八连通;不设置,connectivity=input.ndim,output为与input连通域一样的标记图像
background:选择背景像素,指定像素作为背景,全部相同像素标记为0,不设置,默认背景像素值为0
return_num:bool值,若True,返回值是一个元组(labels ,num );False则只返回labels
output:与input形状一样,但是数值是从0开始的标记号(0,1,2,....),所以这是一个已经标记的图片
2、Skimage中的regionprops参数解释:
作用:测量标记图像区域的属性
属性包括:连通域的面积,外接矩形的面积,连通域的质心等等
总共访问的属性:
area : int
区域的像素数
bbox : tuple
Bounding box (min_row, min_col, max_row, max_col).
Pixels belonging to the bounding box are in the half-open interval
[min_row; max_row) and [min_col; max_col).
bbox_area : int
Number of pixels of bounding box.
centroid : array
质心坐标 tuple (row, col).
convex_area : int
凸包图像的像素数
convex_image : (H, J) ndarray
Binary convex hull image which has the same size as bounding box.
coords : (N, 2) ndarray
Coordinate list (row, col) of the region.
eccentricity : float
Eccentricity of the ellipse that has the same second-moments as the
region. The eccentricity is the ratio of the focal distance
(distance between focal points) over the major axis length.
The value is in the interval [0, 1).
When it is 0, the ellipse becomes a circle.
equivalent_diameter : float
The diameter of a circle with the same area as the region.
euler_number : int
Euler characteristic of region. Computed as number of objects (= 1)
subtracted by number of holes (8-connectivity).
extent : float
Ratio of pixels in the region to pixels in the total bounding box.
Computed as area / (rows * cols)
filled_area : int
Number of pixels of filled region.
filled_image : (H, J) ndarray
Binary region image with filled holes which has the same size as
bounding box.
image : (H, J) ndarray
Sliced binary region image which has the same size as bounding box.
inertia_tensor : (2, 2) ndarray
Inertia tensor of the region for the rotation around its mass.
inertia_tensor_eigvals : tuple
The two eigen values of the inertia tensor in decreasing order.
intensity_image : ndarray
Image inside region bounding box.
label : int
The label in the labeled input image.
local_centroid : array
Centroid coordinate tuple (row, col), relative to region bounding
box.
major_axis_length : float
The length of the major axis of the ellipse that has the same
normalized second central moments as the region.
max_intensity : float
Value with the greatest intensity in the region.
mean_intensity : float
Value with the mean intensity in the region.
min_intensity : float
Value with the least intensity in the region.
minor_axis_length : float
The length of the minor axis of the ellipse that has the same
normalized second central moments as the region.
moments : (3, 3) ndarray
Spatial moments up to 3rd order
output=regionprops(input, intensity_image=None, cache=True, coordinates=None)
注:这里的input即output=label(input, neighbors = None, background = None, return_num = False, connectivity = None)
input:标记好的输入图像
其他参数默认值就好,可不设置
3、根据regionprops得出的信息,处理满足条件的连通域:
label_image=label(splice_predict)
props=regionprops(label_image)
area=[]
centroid=[]
print("total region number",np.max(label_image))
for i in range(np.max(label_image)): #连通区域个数
area.append(props[i].area)
centroid.append(props[i].centroid)
index=[i+1 for i, element in enumerate(area) if element>100000]
for j in index:
label_image[label_image==j]=0
label_image=np.array(label_image,dtype='uint8')
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)