How to analyse optical flow information (2024)

15 views (last 30 days)

Show older comments

Life is Wonderful on 2 Aug 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information

Commented: Life is Wonderful on 24 Aug 2023

Accepted Answer: Praveen Reddy

Open in MATLAB Online

Hi there,

I have acquired the output from the optical fow in a structure and would like to learn how to use the data to say there are defects - using magnitude and Orientation, as well as how to use Vector motion Vx and Vy in my analysis.As an example, consider determining the peak and obtaining the wavelength measurement per unit time.

Is it possible to extract the output vectors? I'd like to use static analysis to determine the quality in terms of flicker, blink, and blur. Any suggestions would be highly appreciated.

The information in my sample data structure is as follows:

Vx: [360×640 single]

Vy: [360×640 single]

Orientation: [360×640 single]

Magnitude: [360×640 single]

3 Comments

Show 1 older commentHide 1 older comment

Image Analyst on 3 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2837647

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2837647

If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

TUTORIAL: How to ask a question (on Answers) and get a fast answer

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2837767

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2837767

Edited: Life is Wonderful on 3 Aug 2023

Open in MATLAB Online

Sure, please accept my apologies. I am using code that is mostly available in the example paper. It would be great if you could offer your thoughts on how to proceed with the problem stated above.

vidReader = VideoReader('visiontraffic.avi');

opticFlow = opticalFlowHS

h = figure;

movegui(h);

hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');

hPlot = axes(hViewPanel);

fprintf('%15s| %15s| %15s| %15s|\n---------------+----------------+----------------+-----------------+\n', ...

'VidCurrentTime','Magnitude','Orientation','Algexecutiontime' );

while hasFrame(vidReader)

frameRGB = readFrame(vidReader);

frameGray = im2gray(frameRGB);

t1 =tic;

flow = estimateFlow(opticFlow,frameGray);

t2 = toc(t1);

fprintf('%15.4f|%15.8f | %15.8f| %16.8f|\n',vidReader.CurrentTime,std2(sqrt(flow.Magnitude)),std2(angle(flow.Orientation)),t2 );

imshow(frameRGB)

hold on

plot(flow,'DecimationFactor',[5 5],'ScaleFactor',60,'Parent',hPlot);

q = findobj(gca,'type','Quiver');

% Change the color of the arrows to red

q.Color = 'r';

drawnow

hold off

pause(10^-3)

end

Life is Wonderful on 8 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2842497

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2842497

Could you please show me how to use the above code to generate spatial image gradients in grey levels per pixel and temporal gradients in grey levels per frame and export the results?

Thank you very much

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Praveen Reddy on 23 Aug 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#answer_1291852

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#answer_1291852

Edited: Praveen Reddy on 23 Aug 2023

Open in MATLAB Online

Hi,

I understand that you want to compute spatial image gradients, temporal gradients and export the results. You can compute the spatial gradient using the flow obtained and temporal gradient as the difference between current frame and previous frame. Please find the modified code below where the results are exported as “.mat” files.

vidReader = VideoReader('visiontraffic.avi');

opticFlow = opticalFlowHS;

h = figure;

movegui(h);

hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow Vectors');

hPlot = axes(hViewPanel);

% Create arrays to store spatial and temporal gradients

spatial_gradients = [];

temporal_gradients = [];

fprintf('%15s| %15s| %15s| %15s|\n---------------+----------------+----------------+-----------------+\n', ...

'VidCurrentTime','Magnitude','Orientation','Algexecutiontime' );

% Initialize previous frame variables

prevFrameRGB = readFrame(vidReader);

prevFrameGray = im2gray(prevFrameRGB);

while hasFrame(vidReader)

frameRGB = readFrame(vidReader);

frameGray = im2gray(frameRGB);

t1 = tic;

flow = estimateFlow(opticFlow,frameGray);

t2 = toc(t1);

fprintf('%15.4f|%15.8f | %15.8f| %16.8f|\n',vidReader.CurrentTime,std2(sqrt(flow.Magnitude)),std2(angle(flow.Orientation)),t2 );

% Calculate spatial gradient (per pixel) using the magnitude of flow

spatial_gradient = sqrt(flow.Magnitude);

spatial_gradients = [spatial_gradients; spatial_gradient(:)];

% Calculate temporal gradient (per frame) using the difference between current and previous frame

temporal_gradient = abs(frameGray - prevFrameGray);

temporal_gradients = [temporal_gradients; temporal_gradient(:)];

imshow(frameRGB)

hold on

plot(flow,'DecimationFactor',[5 5],'ScaleFactor',60,'Parent',hPlot);

q = findobj(gca,'type','Quiver');

q.Color = 'r';

drawnow

hold off

pause(10^-3)

% Store current frame for the next iteration

prevFrameRGB = frameRGB;

prevFrameGray = frameGray;

end

% Export the spatial and temporal gradients as data files

save('spatial_gradients.mat', 'spatial_gradients');

save('temporal_gradients.mat', 'temporal_gradients');

I hope this helps.

1 Comment

Show -1 older commentsHide -1 older comments

Life is Wonderful on 24 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2859497

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2003522-how-to-analyse-optical-flow-information#comment_2859497

Hi @Praveen Reddy,

could you kindly advise on how to rotate the angular component for both temporal and spatial gradients?

I am really grateful.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

Image Processing and Computer VisionComputer Vision ToolboxTracking and Motion Estimation

Find more on Tracking and Motion Estimation in Help Center and File Exchange

Tags

  • opticalflow
  • opticalestimae
  • imageprocessing

Products

  • Image Processing Toolbox
  • Computer Vision Toolbox

Release

R2022b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to analyse optical flow information (7)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How to analyse optical flow information (2024)

FAQs

What is optical flow analysis? ›

Optical flow is a technique used to describe image motion. It is usually applied to a series of images that have a small time step between them, for example, video frames. Optical flow calculates a velocity for points within the images, and provides an estimation of where points could be in the next image sequence.

What are the method for estimation of optical flow? ›

There are various approaches concerning the estimation of optical flow. Differential, region-based, energy-based, and phased-based methods are the main groups of approaches [25].

What are the metrics for optical flow? ›

The metrics to compare the performance of the optical flow methods are EPE, EndPoint Error over the complete frames, and Fl-all, percentage of outliers averaged over all pixels, that inliers are defined as EPE < 3 pixels or < 5%.

What is the basic equation for optical flow? ›

Ixu + Iyv + It = 0, where the partial derivatives of I are denoted by subscripts, and u and v are the x and y components of the optical flow vector. This last equation is called the optical flow constraint equation since it expresses a constraint on the components u and v of the optical flow.

What is optical analysis method? ›

Optical Analysis Method refers to a technique that utilizes light to understand and interpret the dynamics of bacterial motion. It involves using optical methods to analyze and study the movement of bacteria. AI generated definition based on: TrAC Trends in Analytical Chemistry, 2023.

What does optic flow tell us? ›

It is widely accepted that this information, termed optic flow, is used to encode self-motion, orientation, visual navigation in three-dimensional space, perception of object movement, collision avoidance, visual stabilization, and control of posture and locomotion.

How accurate is optical flow? ›

Optic flow requires an accurate measurement of the distance to the ground and also assumes a planar surface. If both of those are met then optic flow can be just as accurate and more reliable than VIO. Ideally one would use a combination of both.

What is the principle of optical flow? ›

Optical flow or optic flow is the pattern of apparent motion of objects, surfaces, and edges in a visual scene caused by the relative motion between an observer and a scene. Optical flow can also be defined as the distribution of apparent velocities of movement of brightness pattern in an image.

What are the optical methods of flow visualization? ›

Optical methods: Some flows reveal their patterns by way of changes in their optical refractive index. These are visualized by optical methods known as the shadowgraph, schlieren photography, and interferometry.

What are the three methods of measuring flow? ›

A Venturi meter, an orifice plate meter and a rotameter that demonstrates typical methods of measuring the flow of an incompressible fluid and shows applications of Bernoulli's equation.

What is the optical flow ratio? ›

1 The quantitative flow ratio (QFR) was developed to derive coronary physiology from angiographic images, whereas the optical flow ratio (OFR) is a more recent approach for the rapid and automated assessment of coronary physiology from intracoronary optical coherence tomography (OCT).

What is the optical flow estimation task? ›

Let us remind you that the Optical Flow task consists of estimating per-pixel motion between two consecutive frames. Our goal is to find the displacement of a sparse feature set or all image pixels to calculate their motion vectors.

What is U and V in optical flow? ›

Optical Flow (OF) is the 2D motion field, u(x, y), v(x, y), for each point (x, y) in an image. First note that the OF does not directly tell us about the real 3D motion of the object, it only gives us the projection of the motion in 2D.

What is the optical flow method? ›

Optical flow is the pattern of apparent motion of image objects between two consecutive frames caused by the movement of object or camera. It is 2D vector field where each vector is a displacement vector showing the movement of points from first frame to second.

What is the aperture problem in optical flow? ›

In an essential part of optical flow algorithms, information must be aggregated from nearby image locations in order to estimate all components of motion. This limitation of local evidence for estimating optical flow is called “the aperture problem”.

What is an optical flow sensor used for? ›

Optical flow sensors are used extensively in computer optical mice, as the main sensing component for measuring the motion of the mouse across a surface.

What is the goal of optical flow? ›

The goal of optical flow estimation is to determine the movement of pixels or features in the image, which can be used for various applications such as object tracking, motion analysis, and video compression.

What are the benefits of optical flow? ›

“Optic flow” provides another lens into the walking-thinking dynamic. As you walk, your eyes make constant lateral movements to continuously update your brain on where you are in space.

Is optical flow good? ›

Several content creators and video editors affirm optical flow is the best method to add slow motion. But others say it can do wonders if you can make it work. For video footage with low frame rates and shutter speeds, video editing software will try to fill in missing frames with different methods.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Roderick King

Last Updated:

Views: 6447

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.