Thread Subject: hide vectors in quiver plot completely

Subject: hide vectors in quiver plot completely

From: Fab Braun

Date: 4 Nov, 2009 20:09:02

Message: 1 of 3

hi all!

i'm dealing around with showing the optical flow of an image in a quiver plot.
so far no problem, except I haven't found a solution yet to completely remove zero valued vectors from the quiver plot.

the following i read somewhere:
Vectors(Vectors == 0) = nan;

bud this doesn't work 100%...because there is still a small point left everywhere i want to set these vectors to zero.

any other ideas?

thanks in advance!
fabian

Subject: hide vectors in quiver plot completely

From: Mohd Kharbat

Date: 6 Nov, 2009 00:29:19

Message: 2 of 3

Hello Fabian

One way to do it is not to include the zero vectors in the first place. You can scan through the flow field and exclude those of zero value from being plotted, like this:

function quiverTest(u,v)
% Initialise arrays
xx=[]; yy=[]; uu=[]; vv=[];
% Scan through all elements
for i=1:size(u,1)
    for j=1:size(u,2)
        if sqrt(u(i,j).^2+v(i,j).^2)~=0 % If it's a zero vector, ignore it, otherwise add it to the array
            xx=[xx i];
            yy=[yy j];
            uu=[uu u(i,j)];
            vv=[vv v(i,j)];
        end
    end
end
% Quiver and reverse the Y axis.
quiver(xx,yy,uu,vv);
set(gca,'YDir','reverse');

Hope this helps,
M

"Fab Braun" <f1braun@hsr.ch> wrote in message <hcsn0u$s36$1@fred.mathworks.com>...
> hi all!
>
> i'm dealing around with showing the optical flow of an image in a quiver plot.
> so far no problem, except I haven't found a solution yet to completely remove zero valued vectors from the quiver plot.
>
> the following i read somewhere:
> Vectors(Vectors == 0) = nan;
>
> bud this doesn't work 100%...because there is still a small point left everywhere i want to set these vectors to zero.
>
> any other ideas?
>
> thanks in advance!
> fabian

Subject: hide vectors in quiver plot completely

From: Fab Braun

Date: 6 Nov, 2009 10:25:05

Message: 3 of 3

Hi Mohd,

Great, Thanks a lot!
That was exactly what i was looking for...

i implemented it a bit in a different way than you suggested - no for loops --> not that slow!

% get all the valid flow vectors - might add some additional conditions here
ValidIndex = (abs(FlowVectors) ~= 0);

% plot only valid flow vectors
quiver(GridX(ValidIndex), GridY(ValidIndex), ...
    real(FlowVectors(ValidIndex)), -imag(FlowVectors(ValidIndex)));

than you very much!
fabian

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
quiver Mohd Kharbat 5 Nov, 2009 19:34:08
optical flow Mohd Kharbat 5 Nov, 2009 19:34:08
motion estimation Mohd Kharbat 5 Nov, 2009 19:34:08
quiver hide vec... Fab Braun 4 Nov, 2009 15:14:03
rssFeed for this Thread

Contact us at files@mathworks.com