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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by