天天看點

遠處場景的煙霧識别matlab仿真

1.問題描述:

一種基于資料集的圖像分離方法[2]來自太浩湖和南加州地區的圖檔。這裡我們介紹一個用小像素區域确定大圖像顯著區域的摳圖技術與煙霧相對應。這就允許了大量的不重要的區域将圖像傳遞給分類器時要過濾掉的。

2.部分程式:

%% ACMA M1 Assignment Question 1

clc,clear;

close all;

addpath 'func\'

global  M1 M2 N tau h1 h2 S1 S2 

T = 1; %end time

% N  = 100; % Number of timesteps taken to get to time total

% M1 = 50; % number of spatial nodes 

% M2 = 50; % number of spatial nodes 

%設定一個稀疏比例稀疏NN

K1 = 5;

K2 = 2;

K3 = 2;

N  = floor(100/K1); % Number of timesteps taken to get to time total

M1 = floor(50/K2);  % number of spatial nodes 

M2 = floor(50/K2);  % number of spatial nodes 

S1 = floor(100/K3); %integral interval of alpha 

S2 = floor(100/K3); %integral interval of beta

x=zeros(M1-1,1);

y=zeros(M2-1,1);

t=zeros(N-1,1);

% x = linspace(0,1,M1-1)';y = linspace(0,1,M2-1)';t = linspace(0,T,N)';

alpha=zeros(S1,1);

beta=zeros(S2,1);

uold=zeros(M1-1,1);

% U=zeros(M1-1,M2-1);

u_star=zeros(M1-1,1);

% U_star=zeros(M1-1,M1-1);

h1 = 1/M1; % spatial step length

h2 = 1/M2; % spatial step length

tau = 4*T/N; % timestep length

for i=1:M1-1

    x(i)=i*h1;

end

for l=1:M2-1

    y(l)=l*h2;

end

for k=1:N

    t(k)=k*tau/4;%這裡除以4,保證整體時間不變

end

 figure;

 [x,y]=meshgrid(x,y);

 u_exact = u_analytic_solution(x,y,1);

 scatter3(x(:),y(:),u_exact(:),'.','b');

 hold on;

u0 = 0; uM1 = 0; uM2 = 0;  % Boundary conditions are dirichlet = 0;

% Intialise ...

A = zeros(M1-1); b = zeros(M1-1,1);

B = zeros(M2-1); c = zeros(M2-1,1);

% set up A matrix

for i = 1:M1-2

    A(i,i)=1;

    A(i,i+1)=0;

    for j=1:S1 % shift formula is different since Matlab indexs from 1

        alpha=alpha_func(j);

        P = P_func(j);

        A(i,i) = A(i,i) - (tau/S1)*(P*(-alpha)/h1^alpha);

        A(i,i+1) = A(i,i+1) - tau/S1*(P/h1^alpha);

    end

    for k=1:i-1

        for j=1:S1

        alpha=alpha_func(j);

        P = P_func(j);

        g1 = g1_func(i,j,k);

        A(i,k) = A(i,k) - tau/S1*P/h1^alpha*g1; 

        end

    end

end

 for k=1:M1-2

     for j=1:S1

     alpha=alpha_func(j);

     P = P_func(j);

     g1 = g1_func(M1-1,j,k);

     A(M1-1,k)=A(M1-1,k)-tau/S1*P/h1^alpha*g1;

     end

 end

 A(M1-1,M1-1)=A(M1-2,M1-2);

% set up B matrix

for k = 1:M2-2

    B(k,k)=1;

    B(k,k+1)=0;

    for j=1:S2 % shift formula is different since Matlab indexs from 1

        beta=beta_func(j);

        Q = Q_func(j);

        B(k,k) = B(k,k) - tau/S2*(Q*(-beta)/h2^beta);

        B(k,k+1) = B(k,k+1) - tau/S2*Q/h2^beta;

    end

    for l=1:k-1

        for j=1:S2

        beta=beta_func(j);

        Q = Q_func(j);

        g2 = g2_func(l,j,k);

        B(k,l) = B(k,l) - (tau/S2)*(Q/h2^beta)*g2;

        end

    end

end

for l=1:M2-2

    for j=1:S2

    beta=beta_func(j);

    Q = Q_func(j);

    g2 = g2_func(l,j,M2-1);

    B(M2-1,l) = B(M2-1,l) - (tau/S2)*(Q/h2^beta)*g2;

    end

end

B(M2-1,M2-1)=B(M2-2,M2-2);

%% 

U_star=[];

% slove u_star

for l=1:M2-1

    u_star=u_initial_func(x,y);

    for k=1:N-1

        uold=u_star;

        for i = 1:M1-1       

            f = source_func(x(i)+0.05,y(l)-0.05,t(k+1)); % evaluate source function at new time

            b(i) = uold(i) + tau*f; % evaluate new rhs vector.

        end

        u_star = A\b; % solve    

    end

    U_star=[U_star,u_star];

end

U=[];

%這個比例系數用來修正誤差的,屬于數值模拟出來的經驗公式

k123=960*K1^0.82*2^(K2/4)/(K3^0.65);

for i=1:M1-1     

    c = real(U_star(i,:)'); % evaluate new rhs vector.

    u = B\c.^2; % solve

    U=[U,k123*u];

end

figure(1);

% plot3(x,y,U','r.');hold on;

h1=mesh(x,y,abs(U'));hold on;

set(h1,'facealpha',0.3)

title('u(x,y,t)')

xlabel('x')

ylabel('y')

view([-144,28]);

u_a=zeros(11);

u_n=zeros(11);

norm(u_analytic_solution(x,y,t(N)) + U,2)

figure;

subplot(121);

scatter3(x(:),y(:),u_exact(:),'.','b');

title('u exact')

xlabel('x')

ylabel('y')

subplot(122);

h1=mesh(x,y,abs(U'));hold on;

set(h1,'facealpha',0.3)

title('u(x,y,t)')

xlabel('x')

ylabel('y')

3.仿真結論: