Can the vectors' colours be changed when using opticalFlowFarneback?

조회 수: 4 (최근 30일)
ZEE
ZEE 2019년 1월 20일
답변: Vishnu Sreekumar 2019년 6월 25일
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
Vishnu Sreekumar 2019년 6월 25일
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.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by