通过接近指定颜色的 meanColor 过滤斑点 SimpleCV
Filter blobs by meanColor close to a specified colour SimpleCV
SimpleCV 具有根据特定条件过滤 blob 的漂亮功能。
blobs.filter(numpytrutharray)
其中 numpytrutharray 是由 blob 生成的。[属性] [operator] [value].
我需要过滤掉接近某种颜色的斑点,SimpleCV 使用元组来存储 RGB 颜色值。关于如何做到这一点有什么想法吗?
如果你想做类似的事情
blobs.filter((rmin, gmin, bmin) < blobs.color() < (rmax, gmax, bmax))
然后你可以立即停止你正在做的事情。这不是 Numpy 真值数组生成的工作原理,如果你想使用该方法过滤 blob,你需要这样做:
red, green, blue = [[],[],[]]
color_array = blobs.color()
# Split the color array into separate lists (channels)
for i in color_array:
red.append(i[0])
green.append(i[1])
blue.append(i[2])
# Convert lists to arrays
red_a = np.array(red)
green_a = np.array(green)
blue_a = np.array(blue)
# Generate truth arrays per channel
red_t = rmin < red_a < rmax
green_t = gmin < green_a < gmax
blue_t = bmin < blue_a < bmax
# Combine truth arrays (* in boolean algebra is the & operator, and that's what numpy uses)
rgb_t = red_t * green_t * blue_t
# Run the filter with our freshly baked truth array
blobs.filter(rgb_t)
诚然,生成数组的方式很冗长,但它可能比手动逐个过滤颜色斑点要快。
SimpleCV 具有根据特定条件过滤 blob 的漂亮功能。
blobs.filter(numpytrutharray)
其中 numpytrutharray 是由 blob 生成的。[属性] [operator] [value].
我需要过滤掉接近某种颜色的斑点,SimpleCV 使用元组来存储 RGB 颜色值。关于如何做到这一点有什么想法吗?
如果你想做类似的事情
blobs.filter((rmin, gmin, bmin) < blobs.color() < (rmax, gmax, bmax))
然后你可以立即停止你正在做的事情。这不是 Numpy 真值数组生成的工作原理,如果你想使用该方法过滤 blob,你需要这样做:
red, green, blue = [[],[],[]]
color_array = blobs.color()
# Split the color array into separate lists (channels)
for i in color_array:
red.append(i[0])
green.append(i[1])
blue.append(i[2])
# Convert lists to arrays
red_a = np.array(red)
green_a = np.array(green)
blue_a = np.array(blue)
# Generate truth arrays per channel
red_t = rmin < red_a < rmax
green_t = gmin < green_a < gmax
blue_t = bmin < blue_a < bmax
# Combine truth arrays (* in boolean algebra is the & operator, and that's what numpy uses)
rgb_t = red_t * green_t * blue_t
# Run the filter with our freshly baked truth array
blobs.filter(rgb_t)
诚然,生成数组的方式很冗长,但它可能比手动逐个过滤颜色斑点要快。