<?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: Let Me Count the Ways</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-20924</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 09 Nov 2007 15:29:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-20924</guid>
		<description>Alex-

You&#039;d have to define red to begin with.  Is it only [1 0 0] or are there other choices?  Once you have the choices, you can then apply logic to see which pixels are red.

--Loren</description>
		<content:encoded><![CDATA[<p>Alex-</p>
<p>You&#8217;d have to define red to begin with.  Is it only [1 0 0] or are there other choices?  Once you have the choices, you can then apply logic to see which pixels are red.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Reid</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-20868</link>
		<dc:creator>Alex Reid</dc:creator>
		<pubDate>Thu, 08 Nov 2007 22:55:20 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-20868</guid>
		<description>How would I go about counting red pixels please?

Thanks

Alex</description>
		<content:encoded><![CDATA[<p>How would I go about counting red pixels please?</p>
<p>Thanks</p>
<p>Alex</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes Campaigne</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16283</link>
		<dc:creator>Wes Campaigne</dc:creator>
		<pubDate>Thu, 07 Jun 2007 04:43:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16283</guid>
		<description>Thanks for the response, Peter. I did assume that it was the call to &#039;ones&#039; and the concatenation that caused the slowdown.

I just did a quick search, and found that accumarray was first introduced in R14, and then the interesting upgrades to it came with R14SP3. I first used accumarray with a version prior to that, which is when I had issues with it. I&#039;m pretty sure my university skipped R14SP3, and by the point they upgraded to a later release, I no longer depended on accumarray enough to notice the improvements.

It seems like a fantastically versatile function but for some reason I&#039;ve found it quite difficult to wrap my head around it. These examples help quite a bit. Thanks again!

-Wes</description>
		<content:encoded><![CDATA[<p>Thanks for the response, Peter. I did assume that it was the call to &#8216;ones&#8217; and the concatenation that caused the slowdown.</p>
<p>I just did a quick search, and found that accumarray was first introduced in R14, and then the interesting upgrades to it came with R14SP3. I first used accumarray with a version prior to that, which is when I had issues with it. I&#8217;m pretty sure my university skipped R14SP3, and by the point they upgraded to a later release, I no longer depended on accumarray enough to notice the improvements.</p>
<p>It seems like a fantastically versatile function but for some reason I&#8217;ve found it quite difficult to wrap my head around it. These examples help quite a bit. Thanks again!</p>
<p>-Wes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Perkins</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16276</link>
		<dc:creator>Peter Perkins</dc:creator>
		<pubDate>Wed, 06 Jun 2007 17:29:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16276</guid>
		<description>Wes, ACCUMARRAY was indeed substantially rewritten; as I recall it was for R14 (maybe R14SP1), which was a couple years ago.  Glad to hear you like it.  Faster, yes; accepts more data types, you bet; and it also accepts function handles, with which you can do some interesting things.  Loren touched on a few of them, but examples like these from the help:

       subs = [1 1; 2 1; 2 3; 2 1; 2 3];
       A = accumarray(subs, 101:105, [2 4], @(x)length(x)&gt;1)

       subs = [1 1; 2 1; 2 3; 2 1; 2 3];
       A = accumarray(subs, 101:105, [2 4], @(x){x})

go even further.

You are right, that color counting example does benefit from using the 1-D form of the indexing arg (even Loren, who, believe me, knows a lot about MATLAB, misses simple things sometimes).  It&#039;s faster, though perhaps not for the reason you were thinking: it&#039;s the creation of the 2-column indexing argument that seems to take the bulk of the extra time in the cases I looked at.

And, as you probably noticed, specifying the size of the output (via the third input arg) saves ACCUMARRAY the trouble of figuring it out, also saving time.

- Peter</description>
		<content:encoded><![CDATA[<p>Wes, ACCUMARRAY was indeed substantially rewritten; as I recall it was for R14 (maybe R14SP1), which was a couple years ago.  Glad to hear you like it.  Faster, yes; accepts more data types, you bet; and it also accepts function handles, with which you can do some interesting things.  Loren touched on a few of them, but examples like these from the help:</p>
<p>       subs = [1 1; 2 1; 2 3; 2 1; 2 3];<br />
       A = accumarray(subs, 101:105, [2 4], @(x)length(x)&gt;1)</p>
<p>       subs = [1 1; 2 1; 2 3; 2 1; 2 3];<br />
       A = accumarray(subs, 101:105, [2 4], @(x){x})</p>
<p>go even further.</p>
<p>You are right, that color counting example does benefit from using the 1-D form of the indexing arg (even Loren, who, believe me, knows a lot about MATLAB, misses simple things sometimes).  It&#8217;s faster, though perhaps not for the reason you were thinking: it&#8217;s the creation of the 2-column indexing argument that seems to take the bulk of the extra time in the cases I looked at.</p>
<p>And, as you probably noticed, specifying the size of the output (via the third input arg) saves ACCUMARRAY the trouble of figuring it out, also saving time.</p>
<p>- Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes Campaigne</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16268</link>
		<dc:creator>Wes Campaigne</dc:creator>
		<pubDate>Wed, 06 Jun 2007 03:25:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16268</guid>
		<description>Was accumarray substantially written in some recent release? Previously when I&#039;d used it for computing very wide histograms on very large images it was slow and memory intensive and would not accept integer-typed inputs. I&#039;m happy to see that in R2007a all of that is no longer the case.

There is, however, one oddity about the example given here: Why did you use two dimensional indexing by concatenating with ones(M,1)? The transpose of the result from using one-dimensional indices (i.e., just X(:)) is equivalent, and for large images on my computer, seems to take only ~25% of the time:

&gt;&gt; tic; H = accumarray([ones(M,1) X(:)], 1 , [1 nc]); toc
Elapsed time is 0.483881 seconds.
&gt;&gt; tic; H2 = accumarray(X(:), 1, [nc 1])&#039;; toc
Elapsed time is 0.127087 seconds.
&gt;&gt; isequal(H,H2)

ans =

     1
</description>
		<content:encoded><![CDATA[<p>Was accumarray substantially written in some recent release? Previously when I&#8217;d used it for computing very wide histograms on very large images it was slow and memory intensive and would not accept integer-typed inputs. I&#8217;m happy to see that in R2007a all of that is no longer the case.</p>
<p>There is, however, one oddity about the example given here: Why did you use two dimensional indexing by concatenating with ones(M,1)? The transpose of the result from using one-dimensional indices (i.e., just X(:)) is equivalent, and for large images on my computer, seems to take only ~25% of the time:</p>
<p>&gt;&gt; tic; H = accumarray([ones(M,1) X(:)], 1 , [1 nc]); toc<br />
Elapsed time is 0.483881 seconds.<br />
&gt;&gt; tic; H2 = accumarray(X(:), 1, [nc 1])&#8217;; toc<br />
Elapsed time is 0.127087 seconds.<br />
&gt;&gt; isequal(H,H2)</p>
<p>ans =</p>
<p>     1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16172</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 04 Apr 2007 12:34:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16172</guid>
		<description>Sharareh-

Please look at the documentation in which there are examples for just your problem.   You may also be interested in reading Steve&#039;s blog on &lt;a href=&quot;http://blogs.mathworks.com/steve/&quot; rel=&quot;nofollow&quot;&gt;image processing&lt;/a&gt;.

--Loren</description>
		<content:encoded><![CDATA[<p>Sharareh-</p>
<p>Please look at the documentation in which there are examples for just your problem.   You may also be interested in reading Steve&#8217;s blog on <a href="http://blogs.mathworks.com/steve/" rel="nofollow">image processing</a>.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sharareh</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16171</link>
		<dc:creator>sharareh</dc:creator>
		<pubDate>Wed, 04 Apr 2007 05:28:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16171</guid>
		<description>please guide me how can write program to show histogram of an image</description>
		<content:encoded><![CDATA[<p>please guide me how can write program to show histogram of an image</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-16003</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 03 Jan 2007 12:36:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-16003</guid>
		<description>Folks-

Just as an update, I ran this M-file as a script and as a function with some timings of the first counting problem and get the following results on my dual-core T60 laptop:

&lt;pre&gt;
timesScript =
     for      sparse   accumarray
    0.2425    0.0478    0.0210

timesFunction =
     for      sparse   accumarray
     0.0063    0.0334    0.0175

&lt;/pre&gt;

In any case, there still remain ways to do accomplish the same goal, some of which may be better suited to your needs than others.

--Loren</description>
		<content:encoded><![CDATA[<p>Folks-</p>
<p>Just as an update, I ran this M-file as a script and as a function with some timings of the first counting problem and get the following results on my dual-core T60 laptop:</p>
<pre>
timesScript =
     for      sparse   accumarray
    0.2425    0.0478    0.0210

timesFunction =
     for      sparse   accumarray
     0.0063    0.0334    0.0175
</pre>
<p>In any case, there still remain ways to do accomplish the same goal, some of which may be better suited to your needs than others.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Urs (us) Schwarz</title>
		<link>http://blogs.mathworks.com/loren/2006/12/01/let-me-count-the-ways/#comment-15721</link>
		<dc:creator>Urs (us) Schwarz</dc:creator>
		<pubDate>Sat, 02 Dec 2006 16:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=68#comment-15721</guid>
		<description>-and- dear loren, let us not forget our beloved and fast HISTC...
% take the clowny bit with the COUNT
     n=histc(X(:),1:nc);
     isequal(n,count.&#039;)
just a thought
us</description>
		<content:encoded><![CDATA[<p>-and- dear loren, let us not forget our beloved and fast HISTC&#8230;<br />
% take the clowny bit with the COUNT<br />
     n=histc(X(:),1:nc);<br />
     isequal(n,count.&#8217;)<br />
just a thought<br />
us</p>
]]></content:encoded>
	</item>
</channel>
</rss>

