title: bounding box of numpy array
body: <p>Suppose you have a 2D numpy array with some random values and surrounding zeros.</p>
  
  <p>Example "tilted rectangle":</p>
  
  <pre><code>import numpy as np
  from skimage import transform
  
  img1 = np.zeros((100,100))
  img1[25:75,25:75] = 1.
  img2 = transform.rotate(img1, 45)
  </code></pre>
  
  <p>Now I want to find the smallest bounding rectangle for all the nonzero data. For example:</p>
  
  <pre><code>a = np.where(img2 != 0)
  bbox = img2[np.min(a[0]):np.max(a[0])+1, np.min(a[1]):np.max(a[1])+1]
  </code></pre>
  
  <p>What would be the <strong>fastest</strong> way to achieve this result? I am sure there is a better way since the np.where function takes quite a time if I am e.g. using 1000x1000 data sets.</p>
  
  <p>Edit: Should also work in 3D...</p>