3

我想使用 scikit-image 做一些光学标记识别。我正在寻找 2 个功能

假设我有一个看起来像这样的图像:光学磁共振

我检测它的方式是使用过滤器来清理图像:(即filter模块中噪声斑点的双边和高斯过滤)

然后我会在模块中使用灰度第三我会在模块color中使用精明的边缘检测器filter

我试图找出我用什么来按颜色过滤单元格,以便我可以区分红色和蓝色?

我猜有一些用于色调、饱和度和亮度或 RGB 的功能可用于过滤掉特定颜色或可用于k-means过滤scikit learn数据的某些东西

其次是我如何将此图像转换为 numpy 数组/熊猫数据框,如下所示:

[[1,2,0,2,0]
[0,1,1,0,1]
[0,0,1,2,0]]

其中红色为 1,蓝色为 2,白色为 0。我看到有些人在它下面放了一条线,但不知道它叫什么,也不知道它是否在 sk-image 中可用。

4

1 回答 1

7

以下代码使用 scikit-image 的峰值检测器,应用于图像与纯红色和纯蓝色值之间计算的距离图:

from skimage import io, color, img_as_float
from skimage.feature import corner_peaks, plot_matches

import matplotlib.pyplot as plt
import numpy as np

image = img_as_float(io.imread('colordots.jpg'))

black_mask = color.rgb2gray(image) < 0.1
distance_red = color.rgb2gray(1 - np.abs(image - (1, 0, 0)))
distance_blue = color.rgb2gray(1 - np.abs(image - (0, 0, 1)))

distance_red[black_mask] = 0
distance_blue[black_mask] = 0

coords_red = corner_peaks(distance_red, threshold_rel=0.9, min_distance=50)
coords_blue = corner_peaks(distance_blue, threshold_rel=0.9, min_distance=50)

f, ((ax0, ax1), (ax2, ax3)) = plt.subplots(2, 2, figsize=(15, 10))
ax0.imshow(image)
ax0.set_title('Input image')
ax1.imshow(image)
ax1.set_title('Marker locations')
ax1.plot(coords_red[:, 1], coords_red[:, 0], 'ro')
ax1.plot(coords_blue[:, 1], coords_blue[:, 0], 'bo')
ax1.axis('image')
ax2.imshow(distance_red, interpolation='nearest', cmap='gray')
ax2.set_title('Distance to pure red')
ax3.imshow(distance_blue, interpolation='nearest', cmap='gray')
ax3.set_title('Distance to pure blue')
plt.show()

色点检测

于 2014-02-09T14:45:39.627 回答