title: Effectively take batch of images and crop rectangular slices of images in numpy or tensorflow (batch image cropping)
body: <p>I want to find a way to effectively do batch image cropping. The input image is the same. Each crop has different input offsets, height, and width.</p>
  <p>Naive code:</p>
  <pre><code>img = np.zeros([100, 100, 3])
  ofsets_x = np.array([10, 15, 18])
  img_w = np.array([10, 12, 15])
  ofsets_y = np.array([20, 22, 14])
  img_h = np.array([14, 12, 16])
  
  crops= []
  for i in range(ofsets_x.shape[0]):
      ofset_x = ofsets_x[i]
      ofset_y = ofsets_y[i]
      w = img_w[i]
      h = img_h[i]
  
      crop = img[ofsets_x:ofsets_x + w, ofsets_y:ofsets_y + h, :] 
      crops.append(crop)
  </code></pre>
  <p>Because of this works very slow both in numpy and tensorflow(in tensorflow I am resizing each crop in the end of the loop to the specific size with tf.image.resize). In tensorflow I have tried also tf.vectorized_map and tf.while_loop - didn't gave me any significant speed boost. All this &gt; 20x more slow then in C++. Crop is a simple
  memcpy. It should be superfast especially with preallocated memory.</p>
  <p>How to this faster in numpy or tensorflow?</p>