📄 matlabjuanji.txt
字号:
%main function
%--------------------
img = imread( 'gh2.bmp ');
image = rgb2gray(img);
theta_input = 240.0;
additional_theta = theta_input + 90;
w = 2*pi;
t = 0.5;
[G2a, G2b, G2c] = imgG2Init(image);
[H2a, H2b, H2c, H2d] = imgH2Init(image);
[G2_theta] = imgG2theta(G2a, G2b, G2c, theta_input);
[H2_theta] = imgH2theta(H2a, H2b, H2c, H2d, theta_input);
[G2_additional_theta] = imgG2theta(G2a, G2b, G2c, additional_theta);
for frame = 1:60
result = cos(w*t)*G2_theta + sin(w*t)*H2_theta-G2_additional_theta;
imshow(result);
for j=1:9999
a = j;
end;
t = t + 0.09;
end
以上是主函数,下面贴出几个用到的函数:
% Interpolation functions (note that theta is in radians):
% G2_ka = cos(theta)^2;
% G2_kb = -2*cos(theta)*sin(theta);
% G2_kc = sin(theta)^2;
%
% G2 at theta is defined as follows:
% G_2 = G2_ka*G2a + G2_kb*G2b + G2_kc*G2c
function [G2a, G2b, G2c] = imgG2Init(img)
F1_G2 = [ 0.0094 0.1148 0.3964 -0.0601 -0.9213 -0.0601 0.3964 0.1148 0.0094];
F2_G2 = [ 0.0008 0.0176 0.1660 0.6383 1.0 0.6383 0.1660 0.0176 0.0008];
F3_G2 = [-0.0028 -0.0480 -0.3020 -0.5806 0.0 0.5806 0.3020 0.0480 0.0028];
G2a = conv2(F1_G2,F2_G2,img, 'same ');
G2b = conv2(F3_G2,F3_G2,img, 'same ');
G2c = conv2(F2_G2,F1_G2,img, 'same ');
% - Assumption: theta given in degrees
function [G2_theta] = imgG2theta(G2a, G2b, G2c, theta_input)
syms theta
% --- G2 interpolation functions ---
G2_ka = cos((pi/180)*theta)^2;
G2_kb = -2*cos((pi/180)*theta)*sin((pi/180)*theta);
G2_kc = sin((pi/180)*theta)^2;
% ---
G2_theta = subs(G2_ka,theta_input)*G2a...
+ subs(G2_kb,theta_input)*G2b...
+ subs(G2_kc,theta_input)*G2c;
% Interpolation functions (note that theta is in radians):
% H2_ka = cos(theta)^3;
% H2_kb = -3*(cos(theta)^2)*sin(theta);
% H2_kc = 3*cos(theta)*(sin(theta)^2);
% H2_kd = -sin(theta)^3;
%
% H2 at theta is defined as follows:
% H_2 = H2_ka*H2a + H2_kb*H2b + H2_kc*H2c
function [H2a, H2b, H2c, H2d] = imgH2Init(img)
F1_H2 = [-0.0098 -0.0618 0.0998 0.7551 0.0 -0.7551 -0.0998 0.0618 0.0098];
F2_H2 = [ 0.0008 0.0176 0.1660 0.6383 1.0 0.6383 0.1660 0.0176 0.0008];
F3_H2 = [-0.0020 -0.0354 -0.2225 -0.4277 0.0 0.4277 0.2225 0.0354 0.0020];
F4_H2 = [ 0.0048 0.0566 0.1695 -0.1889 -0.7349 -0.1889 0.1695 0.0566 0.0048];
H2a = conv2(F2_H2,F1_H2,img, 'same ');
H2b = conv2(F3_H2,F4_H2,img, 'same ');
H2c = conv2(F4_H2,F3_H2,img, 'same ');
H2d = conv2(F1_H2,F2_H2,img, 'same ');
% - Assumption: theta given in degrees
function [H2_theta] = imgH2theta(H2a, H2b, H2c, H2d, theta_input)
syms theta
% --- H2 interpolation functions ---
H2_ka = cos((pi/180)*theta)^3;
H2_kb = -3*(cos((pi/180)*theta)^2)*sin((pi/180)*theta);
H2_kc = 3*cos((pi/180)*theta)*(sin((pi/180)*theta)^2);
H2_kd = -sin((pi/180)*theta)^3;
% ---
H2_theta = subs(H2_ka,theta_input)*H2a...
+ subs(H2_kb,theta_input)*H2b...
+ subs(H2_kc,theta_input)*H2c...
+ subs(H2_kd,theta_input)*H2d;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -