使用ndimage.label缺少标签

时间:2018-02-07 19:07:21

标签: python python-3.x image-processing connected-components

我正在尝试使用连接组件标签来隔离部分图像。 我在这张图片上使用scipy的ndimage.label: enter image description here

由于某种原因,结果如下: enter image description here

我真正感兴趣的图像部分是右上角的白色三角形,由于某种原因被标记为背景。 我究竟做错了什么?

我正在使用的代码是:

import numpy as np 
from scipy import misc
from scipy import ndimage
import matplotlib.pyplot as plt
from skimage.filters import threshold_otsu
from skimage.measure import label
from skimage.morphology import closing, square
from skimage.color import label2rgb
from scipy.ndimage.measurements import label

im = misc.imread('20588046_024ee3569b2605dc_MG_R_ML_ANON.jpg')
med_im = ndimage.median_filter(im1, 3)
bw = closing(med_im > 170, square(3))
fill_bw = ndimage.binary_fill_holes(bw)
s = [[1, 1, 1],
     [1, 1, 1],
     [1, 1, 1]]
label_im, nb_labels = ndimage.label(fill_bw, structure=s)
sizes = ndimage.sum(fill_bw, label_im, range(nb_labels + 1))
mask_size = sizes < 1000
remove_pixel = mask_size[label_im]
label_im[remove_pixel] = 0

plt.imshow(label_im, cmap=plt.cm.spectral)
plt.show()

我也试过没有结构使用它,我得到了相同的结果。 我是python的新手,所以如果代码有点乱,我就道歉了

0 个答案:

没有答案
相关问题