# Can the vectors' colours be changed when using opticalFlowFarneback?

조회 수: 5(최근 30일)
ZEE 20 Jan 2019
Hi, I'm trying to create a colored optical flow depending on the magnitude of the vector.
Is there a way to change the colors of the quiver using the built-up functions opticalFlowFarneback and estimate flow?
This is my code which creates just blue arrows. However, I want arrows with different colors depending on the magnitude for example 'jet' or 'parula' colour maps
im1=outA(:,:,:,1);
im2=outA(:,:,:,60);
opticFlow = opticalFlowFarneback();
flow = estimateFlow(opticFlow,im1);
flow = estimateFlow(opticFlow,im2);
figure
imshow(im1)
hold on
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',4);
hold off

댓글을 달려면 로그인하십시오.

### 답변(1개)

Vishnu Sreekumar 25 Jun 2019
An option would be to choose a color based on magnitude first:
thisColor = whatever mapping you have between say mean(flow.Magnitude(:)) and your colormap
and then:
figure;
imshow(im1)
hold on;
quiver(flow.Vx,flow.Vy, 'Color', thisColor)
PS: Just make sure quiver(flow.Vx, ...) gives you the same result as plot(flow), because I've always been confused by what's X and what's Y in these matrices, sometimes, due to the built-in functions in MATLAB being geared towards video applications, X direction can be top to bottom (rows of a matrix) and Y can be columns of the matrix meaning the horizontal axis! So if that's the case, you might find that quiver(flow.Vy, flow.Vx, ...) matches plot(flow) better.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!