Can I set the maximum displacement for opticalflow?

조회 수: 2 (최근 30일)
Daewon Kim
Daewon Kim 2021년 6월 2일
답변: Ayush 2024년 4월 30일
Hi, I am using optical flow to compute sea surface current speed using satellite data.
But, the results of opticalflow show the overestimated current speed rather than known speed current.
So I want to set the maximum displacement of pixels (e.g. not over 5 pixel).
Can I set the maximum displacement for opticalflow method?

답변 (1개)

Ayush
Ayush 2024년 4월 30일
Hi,
You can follow the below steps as a workaround to set the maximum displacement for the optical flow:
  1. Find the horizontal and vertical flow components for each pixel using the optical flow function.
  2. Calculate the magnitude of displacement for each pixel using the horizontal and vertical components. This gives you the speed at each pixel.
  3. For pixels where the displacement magnitude exceeds your threshold (e.g., 5 pixels), you can scale down the Vx and Vy components to meet your maximum displacement criterion.
Refer to the pseudo code below for a better understanding:
% Assuming 'opticFlow' is your computed optical flow object and 'I' is the current frame
flow = estimateFlow(opticFlow, I);
% Get the horizontal and vertical flow components
Vx = flow.Vx;
Vy = flow.Vy;
% Calculate the magnitude of displacement
displacementMagnitude = sqrt(Vx.^2 + Vy.^2);
% Define your maximum displacement threshold
maxDisplacement = 5;
% Find pixels where the displacement exceeds the maximum allowed
exceedsThreshold = displacementMagnitude > maxDisplacement;
% Scale down the Vx and Vy components for these pixels
Vx(exceedsThreshold) = Vx(exceedsThreshold) .* (maxDisplacement ./ displacementMagnitude(exceedsThreshold));
Vy(exceedsThreshold) = Vy(exceedsThreshold) .* (maxDisplacement ./ displacementMagnitude(exceedsThreshold));
% Now, Vx and Vy have been adjusted to ensure no displacement exceeds the maximum threshold
For more information on the "estimateFlow" function, refer to the below documentation:

카테고리

Help CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by