我编写了以下代码作为注册算法的实现,该文章名为:" 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