【问题标题】:Get boundaries from segmented image从分割图像中获取边界
【发布时间】:2017-07-11 20:01:15
【问题描述】:

我在这里尝试使用 skimage 中的 find_boundaries 函数获取分段图像的边界。但是当应用以下代码时,我得到的只是假或零矩阵。 这是我的代码:

import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage.morphology import watershed
from skimage.segmentation import mark_boundaries, find_boundaries
from skimage.filters import sobel

myimage = io.imread('15746.png')
plt.imshow(myimage, cmap=plt.cm.gray)
plt.show()

hist = np.histogram(myimage, bins= np.arange(0,256))
fig, (ax1, ax2) = plt.subplots(1,2,figsize=(8,3))
ax1.imshow(myimage, cmap=plt.cm.gray, interpolation='nearest')
ax1.axis('off')
ax2.plot(hist[1][:-1], hist[0], lw=2)
ax2.set_title('histogram of grey values')
plt.show()

selected_pixles = []
for i in hist[1][:-1]:
    if hist[0][i] >= 700:
        selected_pixles.append(i)

image = sobel(myimage)
fig, ax = plt.subplots(figsize=(4, 3))
ax.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
ax.axis('off')
ax.set_title('elevation_map')

markers = np.zeros_like(myimage)
markers[myimage < min(selected_pixles)] = 1
markers[myimage > max(selected_pixles)] = 2
fig, ax = plt.subplots(figsize=(4, 3))
ax.imshow(markers, cmap=plt.cm.gray, interpolation='nearest')
ax.axis('off')
ax.set_title('markers')

seg = watershed(image, markers=markers)
#print(np.shape(seg[1]))
fig, ax = plt.subplots(figsize=(4, 3))
ax.imshow(seg, cmap=plt.cm.gray, interpolation='nearest')
ax.axis('off')
ax.set_title('segmentation')
#plt.show()



'''bound = mark_boundaries(seg,seg, mode='thick')
#print(np.shape(bound[0]))
plt.imshow(bound, cmap=plt.cm.gray)
plt.show()'''

bounder = find_boundaries(seg, mode='thick').astype(np.uint8)
print(bounder)

结果如下:

[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

图片如下:

那么我在这里错过了什么?

【问题讨论】:

  • 请贴上相关图片。
  • 我编辑了我的帖子并添加了图片

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


【解决方案1】:

您的脚本运行良好,并且输出不仅包含零。当我绘制它时,我看到:

打印数组时,numpy 会汇总输出;并且由于外部值都是 0,这就是您所看到的。

【讨论】:

  • 我可以使用输出数组作为描述符吗?...如果我想为这样的图像制作一个形状描述符,你认为最好的方法是什么?
  • 要制作描述符,将边界骨架化,提取其坐标,然后使用标准机制之一,例如傅立叶系数 (fourier.eng.hmc.edu/e161/lectures/fd/node1.html)。
猜你喜欢
  • 2018-09-06
  • 2019-01-23
  • 2016-10-08
  • 1970-01-01
  • 1970-01-01
  • 2020-12-31
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
相关资源
最近更新 更多