Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!m44g2000hsc.googlegroups.com!not-for-mail
From: Scott MacIntosh <smac2718@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Tracking a path through an image and pulling out associated indices
Date: Tue, 25 Mar 2008 07:20:36 -0700 (PDT)
Organization: http://groups.google.com
Lines: 50
Message-ID: <a78a6d95-be55-4603-99d3-aabf56546995@m44g2000hsc.googlegroups.com>
NNTP-Posting-Host: 66.89.43.210
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1206454837 30578 127.0.0.1 (25 Mar 2008 14:20:37 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 25 Mar 2008 14:20:37 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: m44g2000hsc.googlegroups.com; posting-host=66.89.43.210; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) 
Xref: news.mathworks.com comp.soft-sys.matlab:459041



I am trying to track a path through an image and then create a 1XN
vector that contains the values from the image that match the indices
found. Finding the indices is easy, however I can't seem to pull the
values out of the image without using a for loop. There should be
someway to do this without looping. But I can't seem to figure it out.
Below an example of the current code I am using. Any help is
appreciated.

-Thanks
scott

%--------------------
% create image
I = peaks;
figure(1)
imagesc(peaks);

%----------------------
% selection path
x = [1.0081 4.9597  9.9274 15.0081 20.5403 25.5081 29.4597 36.5726
41.4274 46.2823];
y = [28.0804   23.3523   18.1944   16.3319   20.2003   26.0746
28.6535   30.3728   25.7880   19.9137];
hold on
plot(x,y,'xk')

%-----------------
% fit curve to path and plot
yy = y-mean(y);
[p,s] = polyfit(x,yy,5);
yfit = polyval(p,1:49);;
yfit = yfit+mean(y);

plot(1:49,yfit,'m');

%-----------------------
% create matrix of indices
yfit = floor(yfit);
inds = [1:49;yfit];

%--------------
% loop through image matrix and get data
 for ii = 1:49
  r(ii)= I(inds(1,ii),inds(2,ii));
end

%-------------
plot results
figure
plot(r)