Find edges of images
<p>I have software that generates several images like the following four images:</p>

<p><a href="http://i.stack.imgur.com/XwbtA.png" rel="nofollow"><img src="http://i.stack.imgur.com/XwbtA.png" alt="image 01"></a></p>

<p><a href="http://i.stack.imgur.com/OiezM.png" rel="nofollow"><img src="http://i.stack.imgur.com/OiezM.png" alt="image 02"></a></p>

<p><a href="http://i.stack.imgur.com/0vm2f.png" rel="nofollow"><img src="http://i.stack.imgur.com/0vm2f.png" alt="image 03"></a></p>

<p><a href="http://i.stack.imgur.com/GSu1Q.png" rel="nofollow"><img src="http://i.stack.imgur.com/GSu1Q.png" alt="image 04"></a></p>

<p>Does an algorithm exist that detects the (horizontal &amp; vertical) edges and creates a binary output like this?</p>

<p><a href="http://i.stack.imgur.com/iq4Hb.png" rel="nofollow"><img src="http://i.stack.imgur.com/iq4Hb.png" alt="enter image description here"></a></p>

<p>If possible I'd like to implement this with <code>numpy</code> and <code>scipy</code>. I already tried to implement an algorithm, but I failed because I didn't find a place to start. I also tried to use a neural network to do this, but this seems to be overpowered and does not work perfectly.</p>

<p>The simplest thing to try is to:</p>

<ul>
<li>Convert your images to binary images (by a simple threshold)</li>
<li>Apply the Hough transform (OpenCV, Matlab have it already implemented)</li>
<li>In the Hough transform results, detect the peaks for angles 0 degree, + and - 90 degrees. (Vertical and horizontal lines)</li>
</ul>

<p>In OpenCV and Matlab, you have extra options for the Hough transform which allow you to fill the gaps between two disconnected segments belonging to a same straight line. You may need a few extra operations for post-processing your results but the main steps should be these ones.</p>

python algorithm python-2.7 numpy image-processing