<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166333</link>
    <title>MATLAB Central Newsreader - Tracking a path through an image and pulling out associated indices</title>
    <description>Feed for thread: Tracking a path through an image and pulling out associated indices</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by 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>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 25 Mar 2008 14:20:36 -0400</pubDate>
      <title>Tracking a path through an image and pulling out associated indices</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166333#422702</link>
      <author>Scott MacIntosh</author>
      <description>I am trying to track a path through an image and then create a 1XN&lt;br&gt;
vector that contains the values from the image that match the indices&lt;br&gt;
found. Finding the indices is easy, however I can't seem to pull the&lt;br&gt;
values out of the image without using a for loop. There should be&lt;br&gt;
someway to do this without looping. But I can't seem to figure it out.&lt;br&gt;
Below an example of the current code I am using. Any help is&lt;br&gt;
appreciated.&lt;br&gt;
&lt;br&gt;
-Thanks&lt;br&gt;
scott&lt;br&gt;
&lt;br&gt;
%--------------------&lt;br&gt;
% create image&lt;br&gt;
I = peaks;&lt;br&gt;
figure(1)&lt;br&gt;
imagesc(peaks);&lt;br&gt;
&lt;br&gt;
%----------------------&lt;br&gt;
% selection path&lt;br&gt;
x = [1.0081 4.9597  9.9274 15.0081 20.5403 25.5081 29.4597 36.5726&lt;br&gt;
41.4274 46.2823];&lt;br&gt;
y = [28.0804   23.3523   18.1944   16.3319   20.2003   26.0746&lt;br&gt;
28.6535   30.3728   25.7880   19.9137];&lt;br&gt;
hold on&lt;br&gt;
plot(x,y,'xk')&lt;br&gt;
&lt;br&gt;
%-----------------&lt;br&gt;
% fit curve to path and plot&lt;br&gt;
yy = y-mean(y);&lt;br&gt;
[p,s] = polyfit(x,yy,5);&lt;br&gt;
yfit = polyval(p,1:49);;&lt;br&gt;
yfit = yfit+mean(y);&lt;br&gt;
&lt;br&gt;
plot(1:49,yfit,'m');&lt;br&gt;
&lt;br&gt;
%-----------------------&lt;br&gt;
% create matrix of indices&lt;br&gt;
yfit = floor(yfit);&lt;br&gt;
inds = [1:49;yfit];&lt;br&gt;
&lt;br&gt;
%--------------&lt;br&gt;
% loop through image matrix and get data&lt;br&gt;
&amp;nbsp;for ii = 1:49&lt;br&gt;
&amp;nbsp;&amp;nbsp;r(ii)= I(inds(1,ii),inds(2,ii));&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%-------------&lt;br&gt;
plot results&lt;br&gt;
figure&lt;br&gt;
plot(r)</description>
    </item>
    <item>
      <pubDate>Wed, 26 Mar 2008 08:57:01 -0400</pubDate>
      <title>Re: Tracking a path through an image and pulling out associated indices</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166333#422847</link>
      <author>nor ki</author>
      <description>hi Scott,&lt;br&gt;
&lt;br&gt;
help sub2ind&lt;br&gt;
&lt;br&gt;
hth kinor&lt;br&gt;
&lt;br&gt;
Scott MacIntosh &amp;lt;smac2718@yahoo.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;a78a6d95-be55-4603-99d3-aabf56546995@m44g2000hsc.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; I am trying to track a path through an image and then&lt;br&gt;
create a 1XN&lt;br&gt;
&amp;gt; vector that contains the values from the image that match&lt;br&gt;
the indices&lt;br&gt;
&amp;gt; found. Finding the indices is easy, however I can't seem&lt;br&gt;
to pull the&lt;br&gt;
&amp;gt; values out of the image without using a for loop. There&lt;br&gt;
should be&lt;br&gt;
&amp;gt; someway to do this without looping. But I can't seem to&lt;br&gt;
figure it out.&lt;br&gt;
&amp;gt; Below an example of the current code I am using. Any help is&lt;br&gt;
&amp;gt; appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Thanks&lt;br&gt;
&amp;gt; scott&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %--------------------&lt;br&gt;
&amp;gt; % create image&lt;br&gt;
&amp;gt; I = peaks;&lt;br&gt;
&amp;gt; figure(1)&lt;br&gt;
&amp;gt; imagesc(peaks);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %----------------------&lt;br&gt;
&amp;gt; % selection path&lt;br&gt;
&amp;gt; x = [1.0081 4.9597  9.9274 15.0081 20.5403 25.5081 29.4597&lt;br&gt;
36.5726&lt;br&gt;
&amp;gt; 41.4274 46.2823];&lt;br&gt;
&amp;gt; y = [28.0804   23.3523   18.1944   16.3319   20.2003   26.0746&lt;br&gt;
&amp;gt; 28.6535   30.3728   25.7880   19.9137];&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; plot(x,y,'xk')&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %-----------------&lt;br&gt;
&amp;gt; % fit curve to path and plot&lt;br&gt;
&amp;gt; yy = y-mean(y);&lt;br&gt;
&amp;gt; [p,s] = polyfit(x,yy,5);&lt;br&gt;
&amp;gt; yfit = polyval(p,1:49);;&lt;br&gt;
&amp;gt; yfit = yfit+mean(y);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plot(1:49,yfit,'m');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %-----------------------&lt;br&gt;
&amp;gt; % create matrix of indices&lt;br&gt;
&amp;gt; yfit = floor(yfit);&lt;br&gt;
&amp;gt; inds = [1:49;yfit];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %--------------&lt;br&gt;
&amp;gt; % loop through image matrix and get data&lt;br&gt;
&amp;gt;  for ii = 1:49&lt;br&gt;
&amp;gt;   r(ii)= I(inds(1,ii),inds(2,ii));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %-------------&lt;br&gt;
&amp;gt; plot results&lt;br&gt;
&amp;gt; figure&lt;br&gt;
&amp;gt; plot(r)</description>
    </item>
  </channel>
</rss>

