2
我有一個大的numpy數組,並用scipy中的連接組件標記進行標記。現在我想創建這個數組的子集,其中只剩下最大或最小的標籤。 這兩個極值當然可以發生多次。從numpy數組中分離最大/最小的標籤補丁
import numpy
from scipy import ndimage
....
# Loaded in my image file here. To big to paste
....
s = ndimage.generate_binary_structure(2,2) # iterate structure
labeled_array, numpatches = ndimage.label(array,s) # labeling
# get the area (nr. of pixels) of each labeled patch
sizes = ndimage.sum(array,labeled_array,range(1,numpatches+1))
# To get the indices of all the min/max patches. Is this the correct label id?
map = numpy.where(sizes==sizes.max())
mip = numpy.where(sizes==sizes.min())
# This here doesn't work! Now i want to create a copy of the array and fill only those cells
# inside the largest, respecitively the smallest labeled patches with values
feature = numpy.zeros_like(array, dtype=int)
feature[labeled_array == map] = 1
有人可以給我提示如何繼續前進?
太好了,謝謝你非常喜歡!這工作得很好。我嘗試過索引它,但我沒有得到將1添加到標籤1的大小之前的技巧。 – Curlew 2013-03-08 16:42:06