【视频抖动程度检测】基于LK光流算法的视频图像序列抖动程度计算matlab仿真
2023-09-11 14:15:33 时间
1.软件版本
matlab2021a
2.算法原理概述
根据LK光流提取算法,得到视频前后两帧图像的光流,假设,
X(t),Y(t)
表示t时刻光流场的X分量和Y分量;
那么晃动计算公为:
其中R为光流场这个图片的变长。
3.部分源码
function varargout = tops(varargin)
% TOPS MATLAB code for tops.fig
% TOPS, by itself, creates a new TOPS or raises the existing
% singleton*.
%
% H = TOPS returns the handle to a new TOPS or the handle to
% the existing singleton*.
%
% TOPS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TOPS.M with the given input arguments.
%
% TOPS('Property','Value',...) creates a new TOPS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tops_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tops_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help tops
% Last Modified by GUIDE v2.5 22-Dec-2018 15:47:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tops_OpeningFcn, ...
'gui_OutputFcn', @tops_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before tops is made visible.
function tops_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to tops (see VARARGIN)
% Choose default command line output for tops
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tops wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tops_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
NAME=0;
[filename filepath]=uigetfile('*.*','请选择文件');
SamplePath1 =[filepath,'\']; %存储图像的路径
fileExt = '*.jpg'; %待读取图像的后缀名
%获取所有路径
files = dir(fullfile(SamplePath1,fileExt));
for kk = 1:length(files)
fileName = strcat(SamplePath1,files(kk).name);
I0{kk} = imread(fileName);
end
axes(handles.axes1);
imshow(I0{1});
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
global dist;%
dist=[];
global x_;%
global y_;%
global hor_;%
global ver_;%
global R;%
global blkSize;%
for kk = 1:length(files)-2
kk
[R,C,K] = size(I0{kk});
%分块
blkSize = floor(R/50);
R1 = blkSize*floor(R/blkSize);
C1 = blkSize*floor(C/blkSize);
I1 = double(rgb2gray(I0{kk}));
I2 = double(rgb2gray(I0{kk+1}));
I1s = imresize(I1,[C1,R1]);
I2s = imresize(I2,[C1,R1]);
[row,col] = size(I1s);
blkr = row/blkSize;
blkc = col/blkSize;
%光流算法
%hor为水平运动矢量,ver为垂直运动矢量
[hor,ver] = func_Soptflow(I1s,I2s,blkSize);
x =(1:1:blkc);
y =(1:1:blkr);
hor_{kk} = hor;
ver_{kk} = ver;
%晃动指标
if kk>=2
dist(kk) = sqrt(mean(mean((hor_{kk}-hor_{kk-1}).^2 + (ver_{kk}-ver_{kk-1}).^2)))/floor(R/blkSize)/sqrt(2);
else
% dist(kk) = 0;
end
axes(handles.axes1);
imshow(uint8(I0{kk}));
axes(handles.axes2);
quiver(x,y,hor,ver);
axis([0,R/blkSize,0,R/blkSize]);
set(gca,'ydir','reverse');
axes(handles.axes3);
if kk>=2
plot([0:kk-2],[dist(2:end)],'b-o');
end
xlim([0,length(files)-1]);
xlabel('time (s)');
ylabel('Sloshing Index');
x_{kk} = x;
y_{kk} = y;
pause(0.001);
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
global dist;%
times = [1:length(files)-2]';
data1 = [dist'];
%构建数据组
data = [times,data1];
[m, n] = size(data);
data_cell = mat2cell(data, ones(m,1), ones(n,1));
title = {'Frame','Sloshing Index'};
result = [title;data_cell];
NAME = NAME+1;
%保存到excel中
s = xlswrite(['Save',num2str(NAME),'.xls'], result);
msgbox('Save Success');
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
parameter;
global x_;%
global y_;%
global hor_;%
global ver_;%
global R;%
global blkSize;%
global dist;%
%以下全部是保存图片语句
for kk = 1:length(files)-2
figure(4);
quiver(x_{kk},y_{kk},hor_{kk},ver_{kk});
axis([0,R/blkSize,0,R/blkSize]);
set(gca,'ydir','reverse');
saveas(gcf,['flow_images/flow_images',num2str(kk),'.jpg'])
end
close(figure(4))
tt = 0:length(dist);
figure(5);
plot(tt(1:end-2),dist(2:end),'b-o');
xlim([0,length(files)-1]);
xlabel('time (s)');
ylabel('Sloshing Index');
saveas(gcf,'sloshing_images/sloshing_images.jpg')
close(figure(5))
msgbox('Save Success');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
clear;
close all;
4.仿真结论
A09-55
相关文章
- Matlab中textread函数用法
- 超市火灾烟气蔓延及人员疏散的matlab仿真模拟
- 【MATLAB教程案例94】基于Matlab的IHS图像融合算法仿真案例
- 【MATLAB教程案例92】基于parfor的matlab并行运行机制
- 【MATLAB教程案例85】通过matlab实现有限差分法求解微分方程
- 【MATLAB教程案例81】matlab在大学数学中的应用——线性代数
- 【MATLAB教程案例46】三维数据的插值和滤波处理matlab仿真
- 【MATLAB教程案例38】语音信号的去噪方法matlab仿真学习——LMS自适应滤波,谱减法去噪滤波及维纳滤波等
- 【MATLAB教程案例32】基于matlab的交通标志检测分割算法的仿真——形态学处理,膨胀,腐蚀,形状检测,颜色模型,小波滤波等知识的综合应用
- 【MATLAB教程案例11~20总结】优化类算法matlab仿真经验和技巧总结
- 【MATLAB教程案例8】基于LS算法的OFDM调制解调系统信道估计和均衡算法的matlab仿真
- 【MATLAB教程案例6】基于Costas环的载波同步matlab仿真
- MATLAB、C++、OpenCV、Python、Python-Numpy近似值(取整)求取函数总结【round()、ceil()、floor()、fix()】
- 《数字图像处理与机器视觉——Visual C++与Matlab实现(第2版)》——2.2 MATLAB图像类型及其存储方式
- 【Matlab 六自由度机器人】运动学逆解(附MATLAB机器人逆解代码)
- 【Matlab 六自由度机器人】运动学正解(附MATLAB机器人正解完整代码)
- 【Matlab算法】进退法迭代求解无约束一维极值问题(附进退法MATLAB代码)
- Matlab ------ 打开MATLAB,设置默认打开的文件夹
- Matlab中的DSP应用中的tf2zp函数及zplane(z,p)