Thread Subject: Tracking a path through an image and pulling out associated indices

Subject: Tracking a path through an image and pulling out associated indices

From: Scott MacIntosh

Date: 25 Mar, 2008 14:20:36

Message: 1 of 2

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)

Subject: Tracking a path through an image and pulling out associated indices

From: nor ki

Date: 26 Mar, 2008 08:57:01

Message: 2 of 2

hi Scott,

help sub2ind

hth kinor

Scott MacIntosh <smac2718@yahoo.com> wrote in message
<a78a6d95-be55-4603-99d3-aabf56546995@m44g2000hsc.googlegroups.com>...
> 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)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com