2017-02-27 77 views
0

SimpleCV具有此基於特定條件的漂亮過濾功能。通過meanColor過濾blob以接近指定顏色SimpleCV

blobs.filter(numpytrutharray) 

其中numpytrutharray由blob生成。[property] [operator] [value]。

我需要過濾掉接近某種顏色的斑點,SimpleCV使用元組來存儲RGB顏色值。任何想法如何做到這一點?

回答

0

如果你想這樣做

blobs.filter((rmin, gmin, bmin) < blobs.color() < (rmax, gmax, bmax)) 

那麼你就可以馬上停止你在做什麼。這是真理陣列一代的作品,如果你想用這種方法來過濾斑點你不用怎麼numpy的做到這一點:

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) 

不可否認,經歷了漫長的方式來生成陣列,但它可能比過濾的顏色斑點快通過blob手動。