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

ZEE

### ZEE (view profile)

さんによって質問されました 2019 年 1 月 20 日

### Vishnu Sreekumar (view profile)

さんによって 回答されました 2019 年 6 月 25 日 18:22
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

#### 0 件のコメント

サインイン to comment.

## 1 件の回答

### Vishnu Sreekumar (view profile)

2019 年 6 月 25 日 18:22

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.

#### 0 件のコメント

サインイン to comment.

Translated by