Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!o6g2000yqj.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Picking Ones among Zeros
Date: Sat, 4 Jul 2009 15:03:01 -0700 (PDT)
Organization: http://groups.google.com
Lines: 28
Message-ID: <9032f492-3164-4f68-bb9a-7af6be64fb2f@o6g2000yqj.googlegroups.com>
References: <h2oif2$g5h$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.70.56
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246744981 26798 127.0.0.1 (4 Jul 2009 22:03:01 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 4 Jul 2009 22:03:01 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: o6g2000yqj.googlegroups.com; posting-host=75.186.70.56; 
	posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 
	3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:552819


On Jul 4, 5:44 pm, "Frederic Sigoillot" <sigoil...@yahoo.fr> wrote:
> Hello,
>
> What would be the simplest way to retrieve the size of connected components (ones) in a binary string?
>
> as example, I have
>
> a= [ 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0]
>
> I would like to return>>b
>
>       4
>       7
>       2
>
> There are 4 connected 'Ones' then 7 and then 2 among the zeros.
>
> Thank you!
>
> Frederic

------------------------------------------------
Do you have the image processing toolbox?
If so, run "a" though bwlabel(), then use the labeled image in
regionprops() and you're done.  Just two lines of code, and superfast,
especially for such a small matrix as you gave.