<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/154737</link>
    <title>MATLAB Central Newsreader - locating colored pixels in an image</title>
    <description>Feed for thread: locating colored pixels in an image</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 18 Aug 2007 20:53:58 -0400</pubDate>
      <title>Re: locating colored pixels in an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/154737#388261</link>
      <author>us</author>
      <description>Craig:&lt;br&gt;
&amp;lt;SNIP sees red...&lt;br&gt;
&lt;br&gt;
&amp;gt; I want to scan each column at a time and look for the red &lt;br&gt;
pixels (R&amp;gt;200)...&lt;br&gt;
&lt;br&gt;
one of the many solutions&lt;br&gt;
&lt;br&gt;
% the data&lt;br&gt;
% - assume rgb is a nxmx3 mat&lt;br&gt;
% - extract the &amp;lt;red&amp;gt; plane&lt;br&gt;
%     m=rgb(:,:,1);&lt;br&gt;
% - eg,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m=[&lt;br&gt;
	  0   0 203   0   0   0&lt;br&gt;
	201   0   0   0 207 210&lt;br&gt;
	202   0   0 204   0 211&lt;br&gt;
	  0   0   0 205 208 212&lt;br&gt;
	  0   0   0 206 209   0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;];&lt;br&gt;
% the engine&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[mf,mf]=histc(m,[200,inf]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mm=[0,mf(:).',0];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ib=strfind(mm,[0,1]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ie=strfind(mm,[1,0]);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;il=ie-ib;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowx=mod(ib,size(m,1));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;colx=fix(ib/size(m,1))+1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r=[colx.',rowx.',il.'];&lt;br&gt;
% the result&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(sprintf('%% col/row %2d/%2d lenth %2d\n',r.'));&lt;br&gt;
&lt;br&gt;
-but- carefully look at what &amp;lt;john d'errico&amp;gt; says...&lt;br&gt;
us&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 18 Aug 2007 19:51:07 -0400</pubDate>
      <title>Re: locating colored pixels in an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/154737#388256</link>
      <author>John D'Errico</author>
      <description>"Craig " &amp;lt;hillx154@umn.edu&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fa4tcl$69q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have an image (3000x2000 pixels).  I want to scan each &lt;br&gt;
&amp;gt; column at a time and look for the red pixels (R&amp;gt;200).  Most &lt;br&gt;
&amp;gt; pixels are just black.  When it finds a red pixel, I want &lt;br&gt;
&amp;gt; it to search forward and find how many consecutive red &lt;br&gt;
&amp;gt; pixels (R&amp;gt;200) there are.  Any ideas?  &lt;br&gt;
&lt;br&gt;
Except that R &amp;gt;= 200 is not a good criterion for a color&lt;br&gt;
being red.&lt;br&gt;
&lt;br&gt;
patch(rand(3,1),rand(3,1),[201 0 0]/255)&lt;br&gt;
patch(rand(3,1),rand(3,1),[201 255 255]/255)&lt;br&gt;
patch(rand(3,1),rand(3,1),[150 0 0]/255)&lt;br&gt;
patch(rand(3,1),rand(3,1),[201 150 0]/255)&lt;br&gt;
patch(rand(3,1),rand(3,1),[201 0 150]/255)&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?"&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&lt;/a&gt;&lt;br&gt;
objectId=12326&amp;objectType=FILE&lt;br&gt;
&lt;br&gt;
John&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 18 Aug 2007 17:23:03 -0400</pubDate>
      <title>Re: locating colored pixels in an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/154737#388240</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;fa4tcl$69q$1@fred.mathworks.com&amp;gt;, Craig  &amp;lt;hillx154@umn.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt;I have an image (3000x2000 pixels).  I want to scan each &lt;br&gt;
&amp;gt;column at a time and look for the red pixels (R&amp;gt;200).  Most &lt;br&gt;
&amp;gt;pixels are just black.  When it finds a red pixel, I want &lt;br&gt;
&amp;gt;it to search forward and find how many consecutive red &lt;br&gt;
&amp;gt;pixels (R&amp;gt;200) there are.  Any ideas?  &lt;br&gt;
&lt;br&gt;
There are many ways of doing this. This is just a small variant&lt;br&gt;
on finding the boundaries of "runs", which in one form or another&lt;br&gt;
ends up getting asked about every 10 days.&lt;br&gt;
&lt;br&gt;
*One* possible method:&lt;br&gt;
&lt;br&gt;
If the original image is A, then construct&lt;br&gt;
&lt;br&gt;
B = [zeros(1,size(A,2)), A(:,:,1)&amp;gt;200, zeros(1,size(A,2))];&lt;br&gt;
&lt;br&gt;
This would be 3002 x 2000 (x1)&lt;br&gt;
&lt;br&gt;
Then,&lt;br&gt;
&lt;br&gt;
C = B(2:end,:) xor B(1:end-1,:)&lt;br&gt;
&lt;br&gt;
C would be 3001 x 2000 .&lt;br&gt;
&lt;br&gt;
For any particular column C(:,K) the first 1 in the column marks&lt;br&gt;
the beginning of the first run of red at that same offset into&lt;br&gt;
A(:,K) -- e.g., if the first 1 in C(:,K) was in row 5, then A(5,K)&lt;br&gt;
is the first red pixel. The second 1 in the column C(:,K) marks&lt;br&gt;
the beginning of the first run of *non*-red, so if the second 1&lt;br&gt;
in the column C(:,K) were at (say) position 17, then the last&lt;br&gt;
red element in the run was at A(16,K). The pattern continues&lt;br&gt;
with the first 1 of each pair marking the beginning of a red run,&lt;br&gt;
and the second 1 of each pair marking one past the last red in&lt;br&gt;
the run. If C(3001,K) is set then A(3000,K) was a red pixel.&lt;br&gt;
If you encounter a pair C(N,K) and C(N+1,K) that are both 1s,&lt;br&gt;
then A(N,K) was a single red pixel -- you can see then why it is&lt;br&gt;
important that the end-marker be one past the end of the run,&lt;br&gt;
so you can find the "runs" of length 1.&lt;br&gt;
&lt;br&gt;
To find the boundaries, you can iterate over each column K and&lt;br&gt;
use find(C(:,K)). Finding the boundaries in a vectorized&lt;br&gt;
way is left as an exercise for the reader ;-)&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;All is vanity.                                       -- Ecclesiastes&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 17 Aug 2007 19:36:53 -0400</pubDate>
      <title>locating colored pixels in an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/154737#388186</link>
      <author>Craig </author>
      <description>I have an image (3000x2000 pixels).  I want to scan each &lt;br&gt;
column at a time and look for the red pixels (R&amp;gt;200).  Most &lt;br&gt;
pixels are just black.  When it finds a red pixel, I want &lt;br&gt;
it to search forward and find how many consecutive red &lt;br&gt;
pixels (R&amp;gt;200) there are.  Any ideas?  &lt;br&gt;
</description>
    </item>
  </channel>
</rss>
