title: How can I detect the maximum-sized rectangle that I can draw onto the mask?
body: <p>I'm making an image processing project and I have stuck in one the project's steps. Here is the situation;</p>
  
  <p>This is my mask:</p>
  
  <p><img src="https://i.stack.imgur.com/qolS0.png" alt="enter image description here"></p>
  
  <p>and I want to detect the maximum-sized rectangle that can fit into this mask like this.</p>
  
  <p><img src="https://i.stack.imgur.com/bSPCT.png" alt="enter image description here"></p>
  
  <p>I'm using MATLAB for my project. Do you know any fast way to accomplish this aim. Any code sample, approach or technique would be great.</p>
  
  <p>EDIT 1 : The two algorithms below are works with lot's of the cases. But both of them give wrong results in some difficult cases. I'am using both of them in my project.  </p>