|
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)
|