15 views (last 30 days)
Show older comments
Life is Wonderful on 2 Aug 2023
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
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
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
Life is Wonderful on 3 Aug 2023
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
Hi @Image Analyst,
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
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
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
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
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.
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