title: Algorithm to split an image into smaller images reducing the amount of whitespace and specifying maximum amount of rectangles
body: <p>I am looking for an algorithm which can split an image into smaller images, with some constraints. 
  One constraint is to use the least amount of "whitespace" meaning empty pixels. And the other is to specify a maximum amount of images to split it into.</p>
  
  <p>For example lets look at the below image. There is a lot of "whitespace" in it. I would like to divide this images into a few other images so i can reduce the amount of memory this image occupies, and also to reduce the amount of "drawing" this image will take.</p>
  
  <pre><code>.=transparent pixel
  x=colored pixel
  
  ....................
  .xxxxxxxxxxx........
  ...xxxx...xxxxxx....
  .............xxxxx..
  ...............xxx..
  ...............xxx..
  ....................
  ..xxxxxx............
  .....xxxxxxxxxxx....
  .........xxxxxxxxxx.
  ....................
  </code></pre>
  
  <p>Let's assume i want the image to be split into a maximum of 4 images, a possible sollution would be as drawn below.</p>
  
  <pre><code>....................
  .111111111111111....
  .111111111111111....
  .............22222..
  .............22222.
  .............22222..
  ....................
  ..3333333...........
  ..33333334444444444.
  .........4444444444.
  ....................
  </code></pre>
  
  <p>Does anyone have an algorithm for this, or knows the name of an algorithm which does this?
  I have been looking for a while and found some related algorithms, but the algorithms i found don't account for the whitespace e.g. they split the image into rectangles covering only the non transparent pixels, resulting in a huge amount of rectangles.
  The real life data i am working with are images of 1024*1024 pixels and i would prefer to reduce them into a maximum of 16 parts. the trick is to extract the 16 images using the least amount of whitespace.</p>