<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Detecting Blank Images with C#</title>
	<atom:link href="http://www.chinhdo.com/20080910/detect-blank-images/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chinhdo.com/20080910/detect-blank-images/</link>
	<description>Chinh's not quite random thoughts on software development, .NET, gadgets, and other things.</description>
	<lastBuildDate>Wed, 01 Feb 2012 12:26:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-115961</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Fri, 23 Dec 2011 21:56:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-115961</guid>
		<description>Hi Leonardo: That makes a lot of sense. Thanks for sharing the info. I guess we can even calculate Standard Deviation for each color channel individually and make sure each of them is below the threshold.</description>
		<content:encoded><![CDATA[<p>Hi Leonardo: That makes a lot of sense. Thanks for sharing the info. I guess we can even calculate Standard Deviation for each color channel individually and make sure each of them is below the threshold.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonardo Pignataro</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-115956</link>
		<dc:creator>Leonardo Pignataro</dc:creator>
		<pubDate>Fri, 23 Dec 2011 21:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-115956</guid>
		<description>I use this algorithm in some of my programs, but with a few changes. One of the changes I did to the algorithm was on this line:

int pixelValue = Color.FromArgb(0, red, green, blue).ToArgb();

This is not very wise, because since the ToArgb() method will return a 32-bit integer in the form AARRGGBB, differences among the pixels on the red channel will account more on the calculated standard deviation than differences on the green channel, and even more than on the blue channel. This leads to some difficulty in setting a threshold for the standard deviation value of the images, because the algorithm may return quite different values for images which are near the blank/not-blank point.

A more meaningful value to the pixelValue variable is:

int pixelValue = red + green + blue / 3;

or

double pixelValue = red + green + blue / 3.0;

This way, differences in the 3 channels are accounted with the same weight on the result. Also, the algorithm&#039;s output becomes much more comprehensive, varying from 0 to 255. Setting a threshold with this modification to the algorithm has proven much easier. The algorithm usually returns a value close to 1 on blank images and above 8 on non-blank images. I am currently using 2 for threshold, with a near perfect accuracy rate.

I know this means we&#039;re interpreting the image as if it were in grayscale, but in my experience it makes no difference.</description>
		<content:encoded><![CDATA[<p>I use this algorithm in some of my programs, but with a few changes. One of the changes I did to the algorithm was on this line:</p>
<p>int pixelValue = Color.FromArgb(0, red, green, blue).ToArgb();</p>
<p>This is not very wise, because since the ToArgb() method will return a 32-bit integer in the form AARRGGBB, differences among the pixels on the red channel will account more on the calculated standard deviation than differences on the green channel, and even more than on the blue channel. This leads to some difficulty in setting a threshold for the standard deviation value of the images, because the algorithm may return quite different values for images which are near the blank/not-blank point.</p>
<p>A more meaningful value to the pixelValue variable is:</p>
<p>int pixelValue = red + green + blue / 3;</p>
<p>or</p>
<p>double pixelValue = red + green + blue / 3.0;</p>
<p>This way, differences in the 3 channels are accounted with the same weight on the result. Also, the algorithm&#8217;s output becomes much more comprehensive, varying from 0 to 255. Setting a threshold with this modification to the algorithm has proven much easier. The algorithm usually returns a value close to 1 on blank images and above 8 on non-blank images. I am currently using 2 for threshold, with a near perfect accuracy rate.</p>
<p>I know this means we&#8217;re interpreting the image as if it were in grayscale, but in my experience it makes no difference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Srinivas</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-101071</link>
		<dc:creator>Srinivas</dc:creator>
		<pubDate>Mon, 03 Oct 2011 13:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-101071</guid>
		<description>Hi,

I have an scanned document with multiple pages and every alternate page is blank.
When I tried to convert each page to image and run the above code still it is showing Isblank has &quot;false&quot;. 

How do I overcome the above issue?

Whether tolerance is same for all .tiff files (or) it varies for each page?

For an given multi page scanned document, how do I find the tolerance value?

Any help is highly appreciated.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have an scanned document with multiple pages and every alternate page is blank.<br />
When I tried to convert each page to image and run the above code still it is showing Isblank has &#8220;false&#8221;. </p>
<p>How do I overcome the above issue?</p>
<p>Whether tolerance is same for all .tiff files (or) it varies for each page?</p>
<p>For an given multi page scanned document, how do I find the tolerance value?</p>
<p>Any help is highly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pablo</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-80640</link>
		<dc:creator>Pablo</dc:creator>
		<pubDate>Sat, 25 Sep 2010 14:44:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-80640</guid>
		<description>It&#039;s posible to do this without unsafe code???.. thanks</description>
		<content:encoded><![CDATA[<p>It&#8217;s posible to do this without unsafe code???.. thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rashid</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-80367</link>
		<dc:creator>Rashid</dc:creator>
		<pubDate>Tue, 14 Sep 2010 09:41:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-80367</guid>
		<description>Hi Chinh

need your suggestion as to how to put the code that you have given into a project?
I want to do something similar, and scan through a folder, containing thousands of images, and get as output the filename of a blank image.</description>
		<content:encoded><![CDATA[<p>Hi Chinh</p>
<p>need your suggestion as to how to put the code that you have given into a project?<br />
I want to do something similar, and scan through a folder, containing thousands of images, and get as output the filename of a blank image.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-78452</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Fri, 14 May 2010 17:43:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-78452</guid>
		<description>I&#039;m trying to convert this code to run under VB.net.  I&#039;m having a problem with the following line. byte* p = (byte*)(void*)Scan0;

Has anyone convert this code to VB?  

Do I have to use the &quot;Pointer&quot; method or can the code be written without using a Pointer?

Thank you for your Help!
Phil</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to convert this code to run under VB.net.  I&#8217;m having a problem with the following line. byte* p = (byte*)(void*)Scan0;</p>
<p>Has anyone convert this code to VB?  </p>
<p>Do I have to use the &#8220;Pointer&#8221; method or can the code be written without using a Pointer?</p>
<p>Thank you for your Help!<br />
Phil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stowaway</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-77931</link>
		<dc:creator>Stowaway</dc:creator>
		<pubDate>Wed, 31 Mar 2010 03:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-77931</guid>
		<description>thanks for your reply chinh do.
I already did that work around actually..

I&#039;ll keep my eye on this page incase anyone else has a more efficient solution.
:)</description>
		<content:encoded><![CDATA[<p>thanks for your reply chinh do.<br />
I already did that work around actually..</p>
<p>I&#8217;ll keep my eye on this page incase anyone else has a more efficient solution.<br />
 <img src='http://www.chinhdo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-77924</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Tue, 30 Mar 2010 23:29:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-77924</guid>
		<description>Hi Stowaway: Sorry I can&#039;t devote time to investigate this right now, but perhaps a work around can be achieved by converting the 1 BPP bitmaps to the right format? It looks like that can be fairly easily done according to sample code from here: http://www.wischik.com/lu/programmer/1bpp.html</description>
		<content:encoded><![CDATA[<p>Hi Stowaway: Sorry I can&#8217;t devote time to investigate this right now, but perhaps a work around can be achieved by converting the 1 BPP bitmaps to the right format? It looks like that can be fairly easily done according to sample code from here: <a href="http://www.wischik.com/lu/programmer/1bpp.html" rel="nofollow">http://www.wischik.com/lu/programmer/1bpp.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stowaway</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-77911</link>
		<dc:creator>Stowaway</dc:creator>
		<pubDate>Mon, 29 Mar 2010 22:57:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-77911</guid>
		<description>There is an error when working with BMPS that are lower than 8 bit per pixel.

ie:
byte bytesPerPixel = (byte)(bitsPerPixel / 8); 

if bitsperpixel &lt; 8 the bytersperpixel = 0

and       p += bytesPerPixel;  is p += 0;

I tried a work around by making in p++ every 8 loops but that didnt work.... (for a 1 bpp bmp)
im a programming n00b.. any ideas?</description>
		<content:encoded><![CDATA[<p>There is an error when working with BMPS that are lower than 8 bit per pixel.</p>
<p>ie:<br />
byte bytesPerPixel = (byte)(bitsPerPixel / 8); </p>
<p>if bitsperpixel &lt; 8 the bytersperpixel = 0</p>
<p>and       p += bytesPerPixel;  is p += 0;</p>
<p>I tried a work around by making in p++ every 8 loops but that didnt work&#8230;. (for a 1 bpp bmp)<br />
im a programming n00b.. any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cy</title>
		<link>http://www.chinhdo.com/20080910/detect-blank-images/comment-page-1/#comment-76956</link>
		<dc:creator>Cy</dc:creator>
		<pubDate>Tue, 16 Feb 2010 19:19:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080910/detect-blank-images/#comment-76956</guid>
		<description>Seems on certain images I get the pointer error even with Timex code.

I&#039;ve added try catch with continue inside:
try
                        {
                            count++;

                            byte blue = p[0];
                            byte green = p[1];
                            byte red = p[2];

                            int pixelValue = Color.FromArgb(0, red, green, blue).ToArgb();
                            total += pixelValue;
                            double avg = total / count;
                            totalVariance += Math.Pow(pixelValue - avg, 2);
                            stdDev = Math.Sqrt(totalVariance / count);
                            p += bytesPerPixel;
                        }
                        catch
                        {
                            continue;
                        }

seems to have fixed the issue, but I still dont understand why some images will throw an error.

Times: What do you mean changing the hex to dec? all functions really on a byte not decimal value. Can you repost the decimal version?

Thanks</description>
		<content:encoded><![CDATA[<p>Seems on certain images I get the pointer error even with Timex code.</p>
<p>I&#8217;ve added try catch with continue inside:<br />
try<br />
                        {<br />
                            count++;</p>
<p>                            byte blue = p[0];<br />
                            byte green = p[1];<br />
                            byte red = p[2];</p>
<p>                            int pixelValue = Color.FromArgb(0, red, green, blue).ToArgb();<br />
                            total += pixelValue;<br />
                            double avg = total / count;<br />
                            totalVariance += Math.Pow(pixelValue &#8211; avg, 2);<br />
                            stdDev = Math.Sqrt(totalVariance / count);<br />
                            p += bytesPerPixel;<br />
                        }<br />
                        catch<br />
                        {<br />
                            continue;<br />
                        }</p>
<p>seems to have fixed the issue, but I still dont understand why some images will throw an error.</p>
<p>Times: What do you mean changing the hex to dec? all functions really on a byte not decimal value. Can you repost the decimal version?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

