为了账号安全,请及时绑定邮箱和手机立即绑定

skimage峰的局部最大值由于图像杂质而在附近找到多个斑点

skimage峰的局部最大值由于图像杂质而在附近找到多个斑点

拉莫斯之舞 2021-05-09 12:23:05
我有一个看起来像这样的图像,其中有一些较大的杂质/曝光过度的斑点。通常,检测到它们并不重要,因为测量是时间分辨的,因此稍后将其删除。但是,我对尽可能多的小点感兴趣-尽可能快。skimage.feature.peak_local_max确实做得很好,并且非常容易在不同数据上使用,因为不需要在强度缩放上花太多时间。问题是,由于某种原因,大斑点会产生非常强的正面影响。import skimage.ioimport skimage.featureimport skimage.morphologyfrom matplotlib.collections import PatchCollectionimport matplotlib.pyplot as pltdef plotRoi(spots, img_ax, color, radius):    patches = []    for spot in spots:        y, x = spot        c = plt.Circle((x, y), radius)        patches.append(c)    img_ax.add_collection(PatchCollection(patches, facecolors = "None", edgecolors = color, alpha = 0.3, linewidths = 1))img = skimage.io.imread("/Path/to/img.png")img = img[:,:,0]fig, ax = plt.subplots()ax.imshow(img, cmap = "Greys")spots = skimage.feature.peak_local_max(img, min_distance = 0, exclude_border = True, num_peaks = 2000)plotRoi(spots, ax, "red", radius = 10)plt.show()在某些图像中搜索数千个斑点会导致大量局部最大值彼此重叠。有没有一种方法可以避免这种情况,例如在图像加载时应用滤镜,因为我不希望转向较慢的峰拟合?
查看完整描述

2 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

问题在于,像素区域中的峰具有完全相同的值。解决此问题的一种方法是将峰合并到这些区域的质心。


下面,我重新创建问题并按照说明解决它。


import numpy as np

import matplotlib.pyplot as plt

from skimage.feature import peak_local_max

from scipy.ndimage.measurements import center_of_mass, label


# Generate test data with two peaks, one of which consists of two pixels of equal value

image = np.zeros((11,11),dtype=np.uint8)

image[5,3] = 128

image[5,2] = 255

image[5,7:9] = 255

image[6,8] = 128


# Finding peaks normally; results in three peaks

peaks = peak_local_max(image)


# Find peaks and merge equal regions; results in two peaks

is_peak = peak_local_max(image, indices=False) # outputs bool image

labels = label(is_peak)[0]

merged_peaks = center_of_mass(is_peak, labels, range(1, np.max(labels)+1))

merged_peaks = np.array(merged_peaks)


# Visualize the results

fig,(ax1,ax2)=plt.subplots(1,2)

ax1.imshow(image.T,cmap='gray')

ax1.plot(peaks[:,0],peaks[:,1],'ro')


ax2.imshow(image.T,cmap='gray')

ax2.plot(merged_peaks[:,0],merged_peaks[:,1],'ro')

结果:

查看完整回答
反对 回复 2021-05-18
  • 2 回答
  • 0 关注
  • 505 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号