Identify contiguous regions in 2D numpy array

后端 未结 1 718
生来不讨喜
生来不讨喜 2021-02-13 09:57

I have a large numpy array that I\'ve applied a filter over. I\'d like to identify the contiguous regions in this masked array. Here I\'m defining a region to be co

相关标签:
1条回答
  • 2021-02-13 10:27

    You're looking for scipy.ndimage.label, more info here. label returns an array the same shape as the input where each "unique feature has a unique value", so if you want the indices of the features you can do something like:

    labels, numL = label(array)
    label_indices = [(labels == i).nonzero() for i in xrange(1, numL+1)]
    
    0 讨论(0)
提交回复
热议问题