title: find all rectangular areas with certain properties in a matrix
body: <p>given an n*m matrix with the possible values of 1, 2 and null:</p>
  
  <pre><code>  . . . . . 1 . .
    . 1 . . . . . 1
    . . . 2 . . . .
    . . . . 2 . . .
    1 . . . . . 1 .
    . . . . . . . .
    . . 1 . . 2 . .
    2 . . . . . . 1
  </code></pre>
  
  <p>I am looking for all blocks B (containing all values between (x0,y0) and (x1,y1)) that:</p>
  
  <ul>
  <li>contain at least one '1'</li>
  <li>contain no '2'</li>
  <li>are not a subset of a another block with the above properties</li>
  </ul>
  
  <p>Example:</p>
  
  <p><img src="https://i.stack.imgur.com/Yx3i1.png" alt="blocks"></p>
  
  <p>The red, green and blue area all contain an '1', no '2', and are not part of a larger area. 
  There are of course more than 3 such blocks in this picture. I want to find all these blocks.</p>
  
  <p>what would be a fast way to find all these areas?</p>
  
  <p>I have a working brute-force solution, iterating over all possible rectangles, checking if they fulfill the first two criteria; then iterating over all found rectangles, removing all rectangles that are contained in another rectangle; and I can speed that up by first removing consecutive identical rows and columns. But I am fairly certain that there is a much faster way.</p>