
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Visioneers &#187; projects</title>
	<atom:link href="http://www.oliveragustin.com/category/projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oliveragustin.com</link>
	<description>Tech, IT, Security, Research, Trends and  Tips</description>
	<lastBuildDate>Thu, 29 Oct 2009 16:56:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AFMA Best R&amp;D Paper for Technology/Information Generation</title>
		<link>http://www.oliveragustin.com/afma-best-rd-paper-for-technologyinformation-generation/</link>
		<comments>http://www.oliveragustin.com/afma-best-rd-paper-for-technologyinformation-generation/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 16:56:01 +0000</pubDate>
		<dc:creator>whaldsz</dc:creator>
				<category><![CDATA[news]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://www.oliveragustin.com/?p=85</guid>
		<description><![CDATA[Our study, &#8220;Development of a Computer Vision System for Milled Rice Quality Analysis&#8221; won the AFMA Best R&#038;D Paper for Technology/Information Generation &#8211; Agriculture category.
The event was held during the 21st National Research Symposium last October 9, 2009 at the Fernando Lopez Hall of the Bureau of Soils and Water Management (BSWM) Bldg., Visayas Avenue, [...]]]></description>
			<content:encoded><![CDATA[<p>Our study, &#8220;Development of a Computer Vision System for Milled Rice Quality Analysis&#8221; won the AFMA Best R&#038;D Paper for Technology/Information Generation &#8211; Agriculture category.</p>
<p>The event was held during the 21st National Research Symposium last October 9, 2009 at the Fernando Lopez Hall of the Bureau of Soils and Water Management (BSWM) Bldg., Visayas Avenue, Diliman, Quezon City.</p>
<p>Check the full article @ <a href="http://www.bar.gov.ph/news/21stnrswinners.asp">http://www.bar.gov.ph/news/21stnrswinners.asp</a></p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=AFMA+Best+R%26D+Paper+for+Technology%2FInformation+Generation&u=http%3A%2F%2Fwww.oliveragustin.com%2Fafma-best-rd-paper-for-technologyinformation-generation%2F&b=Reading %22AFMA+Best+R%26D+Paper+for+Technology%2FInformation+Generation%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oliveragustin.com/afma-best-rd-paper-for-technologyinformation-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Background Subtraction in C#</title>
		<link>http://www.oliveragustin.com/background-subtraction-in-c/</link>
		<comments>http://www.oliveragustin.com/background-subtraction-in-c/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 17:16:27 +0000</pubDate>
		<dc:creator>whaldsz</dc:creator>
				<category><![CDATA[emgu]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[background subtraction]]></category>
		<category><![CDATA[emgu.cv]]></category>
		<category><![CDATA[opencv]]></category>

		<guid isPermaLink="false">http://www.oliveragustin.com/background-subtraction-in-c</guid>
		<description><![CDATA[I have been trying to learn OpenCV for a while now and I came across Emgu.CV, a C# wrapper.  Although the Emgu.CV is still under development, it has a many features that will make your work a lot easier if you&#8217;re doing a project in computer vision and image processing areas.  Some of its capabilities [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to learn <a rel="nofollow" href="http://sourceforge.net/projects/opencvlibrary/">OpenCV</a> for a while now and I came across <a rel="nofollow" href="http://www.emgu.com">Emgu.CV</a>, a C# wrapper.  Although the Emgu.CV is still under development, it has a many features that will make your work a lot easier if you&#8217;re doing a project in computer vision and image processing areas.  Some of its capabilities enable you to develop  web applications that can do processing of video and images via TCP/IP.</p>
<p>My goal in this article is to demonstrate simple background segmentation techniques using Emgu.CV.  Background segmentation is important if you are trying to extract features from an image and you want to remove or filter out unwanted objects.  You may also find this technique important when the recovery of color information from foreground objects is important.</p>
<p>Our objective is to remove the background from the rice image below. We want to get the color information from the rice kernels and be able to extract features for for each kernel, maybe for shape analysis or classification purposes.</p>
<p>Source code is available at the <a rel="tag" href="http://www.oliveragustin.com/forum/viewtopic.php?f=26&#038;t=25">Visioneer Forum</a> site.</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/11/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/11/image-thumb.png" border="0" alt="Original image" width="244" height="204" /></a></p>
<p>I am sure there are other ways to perform background subtraction but this article will cover three methods that .</p>
<ol>
<li>Color filtering in Cielab color space</li>
<li>Image masking (as i call it)</li>
<li>Cielab + image masking</li>
</ol>
<p>The three methods will be explained shortly and the link to the source code is available at the visioneer forum.</p>
<p><strong>Color Filtering in Cielab Color Space</strong></p>
<p>In this method, a copy of RGB image in Cielab space is obtained, and then process this image (in Cielab space) pixel by pixel.  Each pixel is checked if its color value is within specified range, otherwise, the pixel in the corresponding RGB image is set to black color.  An implementation is visible below:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">// background subtraction in cielab color space</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> CielabColorFilteringBGSubtraction(<span style="color: #0000ff">string</span> filename, <span style="color: #0000ff">bool</span> displayResult)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     <span style="color: #008000">// create new image from file</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     Image&lt;Bgr, Byte&gt; rgbimage = <span style="color: #0000ff">new</span> Image&lt;Bgr, <span style="color: #0000ff">byte</span>&gt;(filename);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     <span style="color: #008000">// make a copy of the image in lab color space</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     Image&lt;Lab, Byte&gt; labimage = rgbimage.Convert&lt;Lab, Byte&gt;();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     <span style="color: #008000">// get the width and size</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     <span style="color: #0000ff">int</span> width = labimage.Width;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     <span style="color: #0000ff">int</span> height = labimage.Height;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>     <span style="color: #008000">// get the filter range for each channel in lab color space</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>     IntRange l = <span style="color: #0000ff">new</span> IntRange(Byte.Parse(min1TextBox.Text), Byte.Parse(max1TextBox.Text));</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     IntRange a = <span style="color: #0000ff">new</span> IntRange(Byte.Parse(min2TextBox.Text), Byte.Parse(max2TextBox.Text));</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>     IntRange b = <span style="color: #0000ff">new</span> IntRange(Byte.Parse(min3TextBox.Text), Byte.Parse(max3TextBox.Text));</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>     <span style="color: #008000">// process each row in the image</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>     <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; width; i++)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>         <span style="color: #008000">// process each pixel</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>         <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> j = 0; j &lt; height; j++)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span>         {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span>             <span style="color: #0000ff">if</span> (</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span>                 (labimage[j, i].X &gt;=l.Max ) || (labimage[j, i].X &lt;= l.Min) ||</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span>                  (labimage[j, i].Y &gt;= a.Max) || (labimage[j, i].Y &lt;= a.Min) ||</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  28:</span>                  (labimage[j, i].Z &gt;= b.Max) || (labimage[j, i].Z &lt;= b.Min)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  29:</span>                 )</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  30:</span>             {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  31:</span>                 <span style="color: #008000">// if outside the filter range, set the pixel to black color</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  32:</span>                 rgbimage[j, i] = <span style="color: #0000ff">new</span> Bgr(0, 0, 0);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  33:</span>             }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  34:</span>         }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  35:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  36:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  37:</span>     <span style="color: #008000">// display</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  38:</span>     <span style="color: #0000ff">if</span> (displayResult) <span style="color: #0000ff">this</span>.NewImage(<span style="color: #006080">"Cielab-based background segmented image"</span>, rgbimage);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  39:</span> }</pre>
<p> </p>
</div>
</div>
<p>The resulting image looks like this.  In my PC, it took about 3.20 sec to perform background segmentation.</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/11/output.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/11/output-thumb.png" border="0" alt="output" width="244" height="204" /></a></p>
<p><strong>Image Masking</strong></p>
<p>In this method, what we do is convert an RGB image into binary via binary thresholding.  (The choice of threshold value depends on the image, so you have to experiment on this.)  This binary image will serve as the mask image to copy pixels from the original image to the destination image, if the corresponding pixel in the mask image is nonzero. This is given by the following representation:</p>
<p>DestinatioImage(x,y) = SourceImage(x,y) if MaskImage(x,y) &lt;&gt; 0</p>
<p>where x and y is the pixel coordinates of the image. Source, destination and mask image have the same size.</p>
<p>Code implementation is as follows:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">// background subtraction by converting the RGB image to binary to create the mask</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #008000">// then use this mask to copy foreground objects in the image</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> RGBImageMaskBGSubtraction(<span style="color: #0000ff">string</span> filename, <span style="color: #0000ff">bool</span> displayResult)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #008000">// load the threshold value for grayscale image</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     <span style="color: #0000ff">double</span> threshold = <span style="color: #0000ff">double</span>.Parse(max2TextBox.Text);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     <span style="color: #008000">// create new image</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     Image&lt;Bgr, Byte&gt; img = <span style="color: #0000ff">new</span> Image&lt;Bgr, <span style="color: #0000ff">byte</span>&gt;(filename);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     <span style="color: #008000">//convert to grayscale</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     Image&lt;Gray, Byte&gt; gray = img.Convert&lt;Gray, Byte&gt;();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>     <span style="color: #008000">//convert to binary image using the threshold</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>     gray = gray.ThresholdBinary(<span style="color: #0000ff">new</span> Gray(threshold), <span style="color: #0000ff">new</span> Gray(255));</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>     <span style="color: #008000">// copy pixels from the original image where pixels in </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>     <span style="color: #008000">// mask image is nonzero</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>     Image&lt;Bgr, Byte&gt; newimg = img.Copy(gray);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>     <span style="color: #008000">// display result</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>     <span style="color: #0000ff">if</span> (displayResult) <span style="color: #0000ff">this</span>.NewImage(<span style="color: #006080">"Background segmented"</span>, newimg);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span> }</pre>
<p> </p>
</div>
</div>
<p>One thing we should be aware of is that, all channels in RGB image is used to convert the image in grayscale image, then eventually binary image.  The output image is shown below:</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/11/output1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/11/output-thumb1.png" border="0" alt="output" width="244" height="204" /></a></p>
<p>Obviously, this is far worst then the first method.  But the advantage of segmentation using this technique is the speed.  The image was segmented for only 0.25 sec with more than 12X improvement, but we have to live with the quality. According to my tests, the performance improvement increases as the image size increased.  If we are very much concerned with the pixels in foreground objects, then the Image Masking method will not satisfy our requirements. </p>
<p>However, there is another method to achieve the segmentation quality of cielab color filtering method, and the speed of the image masking method. </p>
<p><strong>Cielab + Image masking</strong></p>
<p>In this method, we combine the first two techniques to get the cream of both ice creams. <img src='http://www.oliveragustin.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   What we do is to perform the processing as in image masking method, but instead of using 3 channels (in RGB format) to convert the image to grayscale, we convert the image into Cielab space, select the a*-channel of the image, and use this channel to derive the mask image.</p>
<p>Code implementation here:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #008000">// background subtraction by extracting one channel in cielab image to </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>  <span style="color: #008000">// create binary mask, and use this mask to copy foreground objects in </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>  <span style="color: #008000">// the original image</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>  <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> CielabChannelMaskBGSubtraction(<span style="color: #0000ff">string</span> filename, <span style="color: #0000ff">bool</span> displayResult)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>  {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>      <span style="color: #0000ff">double</span> threshold = <span style="color: #0000ff">double</span>.Parse(max2TextBox.Text);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>      Image&lt;Bgr, <span style="color: #0000ff">byte</span>&gt; rgb = <span style="color: #0000ff">new</span> Image&lt;Bgr, <span style="color: #0000ff">byte</span>&gt;(filename);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>      Image&lt;Lab, Byte&gt; img = rgb.Convert&lt;Lab, Byte&gt;();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>      <span style="color: #008000">//get the a* channel </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>      Image&lt;Gray, Byte&gt; gray = img[channel];</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>      <span style="color: #008000">//threshold and invert</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>      gray = gray.ThresholdBinary(<span style="color: #0000ff">new</span> Gray(threshold), <span style="color: #0000ff">new</span> Gray(255)).Not();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>     <span style="color: #008000">// display the result</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>      <span style="color: #0000ff">if</span> (displayResult) <span style="color: #0000ff">this</span>.NewImage(<span style="color: #006080">"Background segmented"</span>, image);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>  }</pre>
<p> </p>
</div>
</div>
<p>Resulting output image here, note that it has almost the same quality as in the first method but with little performance penalty (processing takes around 0.03 sec longer than the second method).</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/11/output2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/11/output-thumb2.png" border="0" alt="output" width="244" height="204" /></a></p>
<p>Please note that you need to tweak the filter range(threshold value) for this to work in your problem area. Also,</p>
<ol>
<li>In Method 1, all three channels are used as filter ranges.</li>
<li>Method 2, uses channel 1(maximum) for grayscale threshold value</li>
<li>In method 3, you can select among the radio buttons (on the right) which channels to choose as the source for the mask image.  Then modify the filter range for that selected channel mask. You can also modify the source code to select one or more channels if it gives better performance.</li>
<li>I have included two images located in the source code folder for testing purposes.</li>
</ol>
<p>Screenshot is given below:</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/11/image1.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/11/image-thumb1.png" border="0" alt="image" width="244" height="202" /></a></p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Background+Subtraction+in+C%23&u=http%3A%2F%2Fwww.oliveragustin.com%2Fbackground-subtraction-in-c%2F&b=Reading %22Background+Subtraction+in+C%23%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oliveragustin.com/background-subtraction-in-c/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Caliper Software for Milled-Rice &#8211; Counts the number of grains, headrice and broken kernels</title>
		<link>http://www.oliveragustin.com/caliper-software-for-milled-rice-counts-the-number-of-grains-headrice-and-broken-kernels/</link>
		<comments>http://www.oliveragustin.com/caliper-software-for-milled-rice-counts-the-number-of-grains-headrice-and-broken-kernels/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 02:53:02 +0000</pubDate>
		<dc:creator>whaldsz</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[aforge]]></category>
		<category><![CDATA[bpre]]></category>
		<category><![CDATA[caliper]]></category>
		<category><![CDATA[Milled Rice]]></category>
		<category><![CDATA[nfa]]></category>
		<category><![CDATA[SVM]]></category>

		<guid isPermaLink="false">http://www.oliveragustin.com/caliper-software-for-milled-rice-counts-the-number-of-grains-headrice-and-broken-kernels</guid>
		<description><![CDATA[ This is an application for counting milled rice grains, determining the count of headrice, broken, and brewers. Using these grade factors, the caliper software (as I call it) is able to estimate the total weight in terms of percentage. Weight estimation of rice grain is performed using linear regression and support vector machines (SVM). [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/09/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 5px; border-right-width: 0px" height="174" alt="Milled rice software caliper" src="http://www.oliveragustin.com/wp-content/uploads/2008/09/image-thumb1.png" width="236" align="right" border="0"></a> This is an application for counting milled rice grains, determining the count of headrice, broken, and brewers. Using these grade factors, the <strong><em>caliper software</em></strong> (as I call it) is able to estimate the total weight in terms of percentage. Weight estimation of rice grain is performed using linear regression and support vector machines (SVM). It uses AForge library from <a href="http://code.google.com/p/aforge" target="_blank">AForge.NET</a> for various image processing task.</p>
<p>I did this software for <a href="http://www.bpre.gov.ph" target="_blank">Bureau of Post-harvest Research Extension (BPRE)</a> and indirectly, to <a href="http://www.nfa.gov.ph/" target="_blank">National Food Authority (NFA)</a> for the purpose of quickly determining the grain size of milled rice. </p>
<p>The demo and initial version of the caliper software is available for download here:</p>
<ul>
<li><a href="http://www.oliveragustin.com/downloads/Calip_Binary.rar" target="_blank">caliper software</a>.&nbsp; </li>
</ul>
<p>To use the software, simply install the application, then open the sample image included in the installation (&#8220;bigas.bmp&#8221;), then that&#8217;s it!&nbsp; You can try it for other similar problems, like corn, barley, etc.&nbsp; Please give me feedback if problems arises.&nbsp; For any questions, you may email me at {vlad_crasher at yahoo point com}.</p>
<p>UPDATE: Yesterday (September 15, 2008), they told me that the test was successful!&nbsp; The classification result did matched with the manual methods performed by human inspector.</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Caliper+Software+for+Milled-Rice+%E2%80%93+Counts+the+number+of+grains%2C+headrice+and+broken+kernels&u=http%3A%2F%2Fwww.oliveragustin.com%2Fcaliper-software-for-milled-rice-counts-the-number-of-grains-headrice-and-broken-kernels%2F&b=Reading %22Caliper+Software+for+Milled-Rice+%E2%80%93+Counts+the+number+of+grains%2C+headrice+and+broken+kernels%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oliveragustin.com/caliper-software-for-milled-rice-counts-the-number-of-grains-headrice-and-broken-kernels/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use SVM for classification</title>
		<link>http://www.oliveragustin.com/how-to-use-svm-for-classification/</link>
		<comments>http://www.oliveragustin.com/how-to-use-svm-for-classification/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 22:42:22 +0000</pubDate>
		<dc:creator>whaldsz</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[classification]]></category>
		<category><![CDATA[how-to svm]]></category>
		<category><![CDATA[LibSVM]]></category>
		<category><![CDATA[support vectors]]></category>
		<category><![CDATA[svc]]></category>
		<category><![CDATA[SVM]]></category>
		<category><![CDATA[svr]]></category>

		<guid isPermaLink="false">http://www.oliveragustin.com/how-to-use-svm-for-classification</guid>
		<description><![CDATA[Support Vector Machine or simply SVM is a machine learning algorithm for data regression and classification.&#160; I have adopted it for use in my project in milled rice kernel classification according to the following categories:

Chalky
Sound/Good
Damaged
Red
Paddy
Discolored

My goal is to share how to build a model, apply this classifier to your test data to determine its accuracy, [...]]]></description>
			<content:encoded><![CDATA[<p>Support Vector Machine or simply SVM is a machine learning algorithm for data regression and classification.&nbsp; I have adopted it for use in my project in milled rice kernel classification according to the following categories:</p>
<ul>
<li>Chalky
<li>Sound/Good
<li>Damaged
<li>Red
<li>Paddy
<li>Discolored</li>
</ul>
<p>My goal is to share how to build a model, apply this classifier to your test data to determine its accuracy, and finally, implement the model as an application.&nbsp; The library called <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/">LibSVM</a> has made my work a lot simpler.&nbsp; Why reinvent the wheel?&nbsp; Here&#8217;s how you do it:</p>
<ol>
<li>Acquire the image.&nbsp; This could be accomplished by various methods.&nbsp; You can use scanner, digital camera, or video camera.
<li>Pre-process the captured image.&nbsp; The goal is to ensure that unimportant objects are discarded, and enhance your region of interests to prevent lost of features.
<li>Extract features (Morphological &amp; Color), one set for training and another set for testing.
<li>You may need to scale your data, especially if the value of some features are a lot&nbsp; larger than the other.
<li>Train and build the SVM model.&nbsp; You may need to find the optimal parameters (the penalty, C and kernel parameter, gamma).&nbsp; This may take a while depending on the type of SVM and kernel you choose.
<li>If you are satisfied with the prediction accuracy of your model, then apply it to your test data, or real data.
<li>Build your application.</li>
</ol>
<p>Simple, eh? </p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e527ae05-f1dc-4dba-91a9-2a9b254198cb" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/SVM" rel="tag">SVM</a>,<a href="http://technorati.com/tags/SVR" rel="tag">SVR</a>,<a href="http://technorati.com/tags/SVC" rel="tag">SVC</a>,<a href="http://technorati.com/tags/support%20vectors" rel="tag">support vectors</a>,<a href="http://technorati.com/tags/LibSVM" rel="tag">LibSVM</a></div>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=How+to+use+SVM+for+classification&u=http%3A%2F%2Fwww.oliveragustin.com%2Fhow-to-use-svm-for-classification%2F&b=Reading %22How+to+use+SVM+for+classification%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oliveragustin.com/how-to-use-svm-for-classification/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Software caliper for milled rice</title>
		<link>http://www.oliveragustin.com/software-caliper-for-milled-rice/</link>
		<comments>http://www.oliveragustin.com/software-caliper-for-milled-rice/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 13:16:44 +0000</pubDate>
		<dc:creator>whaldsz</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[bpre]]></category>
		<category><![CDATA[caliper]]></category>
		<category><![CDATA[grain size]]></category>
		<category><![CDATA[milled]]></category>
		<category><![CDATA[rice]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.oliveragustin.com/software-caliper-for-milled-rice</guid>
		<description><![CDATA[Few months ago, I completed a utility capable of measuring the percentage by weight of headrice, broken kernels and brewers for BPRE.  A screen shot is shown below.

The software is used for determining the grain size of a given milled rice sample.  Additional information about other milled rice grade factors are also provided as follows:

Total [...]]]></description>
			<content:encoded><![CDATA[<p>Few months ago, I completed a utility capable of measuring the percentage by weight of headrice, broken kernels and brewers for <a title="software caliper for milled rice" rel="tag" href="http://www.bpre.gov.ph">BPRE</a>.  A screen shot is shown below.</p>
<p><a href="http://www.oliveragustin.com/wp-content/uploads/2008/08/software-caliper2.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://www.oliveragustin.com/wp-content/uploads/2008/08/software-caliper-thumb2.jpg" border="0" alt="software_caliper" width="368" height="268" /></a></p>
<p>The software is used for determining the grain size of a given milled rice sample.  Additional information about other milled rice grade factors are also provided as follows:</p>
<ol>
<li>Total number of kernels and weight of the milled rice sample</li>
<li>Number of headrice and weight</li>
<li>Number of broken kernels including its total weight</li>
<li>Brewers</li>
</ol>
<p>I will provide more information soon.  Keep posted!  And hey&#8230; feel free to comment.  Tell me what you think!</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Software+caliper+for+milled+rice&u=http%3A%2F%2Fwww.oliveragustin.com%2Fsoftware-caliper-for-milled-rice%2F&b=Reading %22Software+caliper+for+milled+rice%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.oliveragustin.com/software-caliper-for-milled-rice/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
