【发布时间】:2014-08-13 21:21:17
【问题描述】:
我正在使用 skimage.feature.blob_doh 检测图像上的 blob,并且正在获取我的 blob 区域的格式:
A = 数组([[121, 271, 30], [123, 44, 23], [123, 205, 20], [124, 336, 20], [126, 101, 20], [126, 153, 20], [156, 302, 30], [185, 348, 30], [192, 212, 23], [193, 275, 23], [195, 100, 23], [197, 44, 20], [197, 153, 20], [260, 173, 30], [262, 243, 23], [265, 113, 23], [270, 363, 30]])
A : (n, 3) 数组
一个二维数组,每行代表 3 个值,(y,x,sigma)
其中(y,x) 是 blob 的坐标,sigma 是
高斯核的标准偏差(大约只是我所在区域的半径)
所以问题是 - 如何选择所有这些区域进行进一步的数据处理(计算平均特征,进行一些聚类和分类)。现在我只是在绘图上绘制它们,但不能将它们迁移到位图\数组变量。
而且我不想使用 OpenCV 库来完成这项任务,我必须使用 numpy/scipy/skimage 和其他库来完成。
fig, ax = plt.subplots(1, 1)
ax.set_title(title)
ax.imshow(image, interpolation='nearest')
for blob in blobs:
y, x, r = blob
c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
print c
ax.add_patch(c)
plt.show()
感谢您的帮助!
UPD:获得了一些用于裁剪的代码,但它正在做一些奇怪的事情......它裁剪得很好,但是坐标是什么?
def crop_and_save_blobs(image, blobs):
image = np.asarray(image)
for blob in blobs:
y, x, radius = blob
center = (x, y)
mask = np.zeros((image.shape[0],image.shape[1]))
for i in range(image.shape[0]):
for j in range(image.shape[1]):
if (i-center[0])**2 + (j-center[0])**2 < radius**2:
mask[i,j] = 1
# assemble new image (uint8: 0-255)
newImArray = np.empty(image.shape,dtype='uint8')
# colors (three first columns, RGB)
newImArray[:,:,:3] = image[:,:,:3]
# transparency (4th column)
newImArray[:,:,3] = mask*255
newIm = Image.fromarray(newImArray, "RGBA")
plt.imshow(newIm)
plt.show()
【问题讨论】:
-
您能否轻松上传带有圆圈的实际图像,而不是带有轴和边框的图片?
-
@MarkSetchell 抱歉,我是 Python 新手,我找不到如何用圆圈保存图像的示例,但我可以上传我正在使用的整个代码和图像
标签: python image image-processing numpy scikit-image