Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!f11g2000yqm.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab and Otsu Thresholding query
Date: Fri, 5 Feb 2010 05:40:13 -0800 (PST)
Organization: http://groups.google.com
Lines: 23
Message-ID: <02124bab-d7f0-4848-ba04-7f17b82d0ea0@f11g2000yqm.googlegroups.com>
References: <hkgur9$c47$1@fred.mathworks.com> <cce067d5-87e1-4435-9ec8-f8a114c7c816@21g2000yqj.googlegroups.com> 
	<c8eeb205-2cbb-4f95-a108-feeb4c668a14@l26g2000yqd.googlegroups.com> 
	<hkh6f0$op3$1@fred.mathworks.com>
NNTP-Posting-Host: 192.44.136.113
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1265377213 27313 127.0.0.1 (5 Feb 2010 13:40:13 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 5 Feb 2010 13:40:13 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: f11g2000yqm.googlegroups.com; posting-host=192.44.136.113; 
	posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-Via: 1.1 bdci2px (NetCache NetApp/6.0.7)
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	CyberSafe-IWA-Enable; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 
	3.5.30729; MS-RTC LM 8),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:604717

Well the shadows are going to cause you a problem because it won't
know if you want to consider shadows an object or not.  They're simply
a different color than the background, just like everything else in
the photo.

But your problem is that you're thresholding before background
correction.  You want to threshold AFTER you get the background
corrected image.

First of all, convert the images to floating point.  Then either
subtract or divide your test image by your background image.  It's at
THIS point that you threshold.  Actually you'll have two thresholds,
for subtraction, everything less than some negative tolerance or
greater than a positive tolerance will be foreground (bitand()those
two thresholded images together), or
for division, everything less than (1.0 - some tolerance) or greater
than (1 + some tolerance) will be foreground (bitand() those two
thresholded images together).

Then call label, and call regionprops.  You might want to do a little
clean up either before of after thresholding, such as small object
removal (use bwareaopen) or hole filling (imfill), or boundary
smoothing (imclose), etc.