Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm thinking in a solution based on ImageMagick. We would need the following steps:</p> <ol> <li>Find the color used to draw in the scanned document (for now on, called <strong>target color</strong>);</li> <li>Find its <code>x</code> and <code>y</code> coordinates in the image;</li> <li>Pass this position as a seed to Flood Fill algorithm.</li> </ol> <p>We could use the following script based on functions of ImageMagick:</p> <ol> <li><p>Output all the unique colors in the picture. This will be used to find out which are the RGB components of the target color (<a href="http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&amp;t=13493" rel="nofollow">command source</a>). </p> <pre><code>convert &lt;image&gt; -unique-colors -depth 8 txt:- &gt; output.txt </code></pre></li> <li><p>Output the coordinates of each color in a text file:</p> <pre><code>convert &lt;image&gt; txt:- &gt; coord.txt </code></pre></li> <li><p>Find the <code>x</code> and <code>y</code> coordinates of the target color (<a href="http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&amp;t=20900" rel="nofollow">command source</a>). Suppose the target color obtained by step 1 was red:</p> <pre><code>grep red coord.txt </code></pre></li> <li><p>Finally, use <code>x</code> and <code>y</code> as a seed to <code>floodfill</code> to replace the circle region by your desired color (<a href="http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&amp;t=17659" rel="nofollow">command source</a>). In this case, I've used <code>white</code> to erase the region:</p> <pre><code>convert &lt;image&gt; -fill white -fuzz 13% \ -draw 'color &lt;x&gt;,&lt;y&gt; floodfill' &lt;image_floodfill_output&gt; </code></pre></li> </ol> <p>The <code>-fuzz</code> parameter will avoid that colors which were originally <code>red</code> and became corrupted due to noise also gets replaced.</p> <p>This <a href="http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&amp;t=17659" rel="nofollow">tutorial</a> gives more information about <code>floodfill</code> function, such as how to replace the edge colors.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload