Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the full code:</p> <pre><code>import numpy from scipy import ndimage array = numpy.zeros((100, 100), dtype=np.uint8) x = np.random.randint(0, 100, 2000) y = np.random.randint(0, 100, 2000) array[x, y] = 1 pl.imshow(array, cmap="gray", interpolation="nearest") s = ndimage.generate_binary_structure(2,2) # iterate structure labeled_array, numpatches = ndimage.label(array,s) # labeling 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())[0] + 1 mip = numpy.where(sizes==sizes.min())[0] + 1 # inside the largest, respecitively the smallest labeled patches with values max_index = np.zeros(numpatches + 1, np.uint8) max_index[map] = 1 max_feature = max_index[labeled_array] min_index = np.zeros(numpatches + 1, np.uint8) min_index[mip] = 1 min_feature = min_index[labeled_array] </code></pre> <p>Notes:</p> <ul> <li><code>numpy.where</code> returns a tuple</li> <li>the size of label 1 is sizes[0], so you need to add 1 to the result of <code>numpy.where</code></li> <li>To get a mask array with multiple labels, you can use <code>labeled_array</code> as the index of a label mask array.</li> </ul> <p>The results:</p> <p><img src="https://i.stack.imgur.com/pPmW5.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/7S9Sn.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/IoTr9.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload