基于matlab的粒子滤波配准

基于matlab的粒子滤波配准,matlab,particle-filter,Matlab,Particle Filter,我编写了以下代码作为一篇文章中介绍的配准算法的实现:“E.Arce Santana,D.Campos Delgado和A.Alba,粒子滤波引导的仿射图像配准,IET图像处理。6(2012)” 问题1:当我运行代码时,无论我选择了多少粒子或迭代,输出仍然不准确。我不知道是什么问题 问题2:我评论了一个用于更新粒子重量的公式,我的问题是,我是否实现了所写的公式,或者上面出现的公式(依赖于熵)是正确的,因此删除了评论的公式并保留基于熵的公式 代码如下: %% clear everything cle

我编写了以下代码作为一篇文章中介绍的配准算法的实现:“E.Arce Santana,D.Campos Delgado和A.Alba,粒子滤波引导的仿射图像配准,IET图像处理。6(2012)”

问题1:当我运行代码时,无论我选择了多少粒子或迭代,输出仍然不准确。我不知道是什么问题

问题2:我评论了一个用于更新粒子重量的公式,我的问题是,我是否实现了所写的公式,或者上面出现的公式(依赖于熵)是正确的,因此删除了评论的公式并保留基于熵的公式

代码如下:

%% clear everything
clear all
close all
clc

%% Read the image data

% I1: Reference Image
I1=imread('cameraman.tif');
I1=double(imresize(I1,[256 256]));
figure,imshow(I1)
[I1r I1c I1d]=size(I1);

%I2: Target image
I2=randomtransform(I1); %user-defined function to generate random transformation 
% I2=double(imresize(I2,[I1r I1c]));
figure,imshow(I2)

%% Particle Filter Steps:
%%%%% Input:
n=4;         % Related to the initialization
m=256;       % Related to the initialization
N=20;       %(no. of iteration)
M=100;       %(no. of particles)
phai=[];     %(state vector of the affine transformation parameters)
w=[];        %(the vector of the phai weights)
%k: iteration no.
%i: particle no.
Vk=1;        % noise variance in the system (Used in the predection state)
w_v=1;       % weights update equation related variance
beta=0.99;   % annealing factor
%%%%% Output
phai_est=[]; %(Final estimated state vector of affine parameters)

%%%%% Steps:
%%% Step 1: Random generation of the particles
% The ranges are obtained from the paper
    rotationAngle=double(int8(unifrnd(-pi/4,pi/4,1,1)));
    scalingCoefX = double(unifrnd(0.5,2,1,1));
    scalingCoefY = double(unifrnd(0.5,2,1,1));
    shearingCoefX = double(unifrnd(0.5,2,1,1));
    shearingCoefY = double(unifrnd(0.5,2,1,1));
    translationCoefX = double(int8(unifrnd(-I1r/2,I1r/2,1,1)));
    translationCoefY = double(int8(unifrnd(-I1c/2,I1c/2,1,1)));
    %The initialization of the first phai
    phai(1,:)=[round(rotationAngle*10^n)/10^n, round(scalingCoefX*10^n)/10^n, round(scalingCoefY*10^n)/10^n, round(shearingCoefX*10^n)/10^n, round(shearingCoefY*10^n)/10^n, round(translationCoefX*10^n)/10^n, round(translationCoefY*10^n)/10^n]';
    %Make the randomly generated particles from the initial prior gaussian distribution
    for i = 1:M
    phai(i,:) = phai(1,:) + sqrt(2) * randn; %2: the variance of the initial esimate
    w(i,:)=1/M;
    end
    % Normalize the weights:
    w = w./sum(w);

%%% Step2: Resample process
for k=1:N
   for i=1:M
       % rand: u (Uniform random value between 0 and 1
       j=find((cumsum(w) >= max(w)),1,'first');
       phai_select(i,:)=phai(j,:);
       phai(i,:)=phai_select(i,:)+(sqrt(Vk^2)*randn);
       I2_new=targettransform(I2,phai(i,:)); %user-defined function to apply the generated transformation to the target image 
       E_I1=entropy(I1);
       I=E_I1+entropy(I2_new)-joint_entropy(I1,I2_new); %joint_entropy: user defined function to calculate joint entropy of the two images
       w(i)=(1/sqrt(2*pi*w_v))*exp(-((E_I1-I)^2)/(2*w_v));
%        w(i)=prod(prod(((1/sqrt(2*pi*w_v))*exp(-((I2_new-I1)^2)/(2*w_v)))));
   end
       % Normalize the weights
       w = w./sum(w);
       % Reduce the noise standard deviation
       Vk=beta*Vk;
       phai_est=mean(phai);
end

“输出不准确”是什么意思?粒子过滤器的一个特点是,当粒子数接近无穷大时,通常无法保证收敛特性超过渐近性。因此,如果运气不好,你可能永远也得不到“正确”的解决方案,不管这意味着什么。我的意思是,即使根据算法增加粒子数,也会提高性能,但我无法做到这一点。因此,我发布代码询问我在实现中是否有错误