tripoliguy
Newbie level 4

Hi all,
please can any one help me to find the problem with this code
i want to restore an image with it but the result is a black image
please can any one help me to find the problem with this code
i want to restore an image with it but the result is a black image
Code:
Img = imread('C:\images\lena.jpg');
%Img= rgb2gray(Img);
Img=im2double(Img);
V =0.001;
clc;
x_N=V ;
x_R=V *2;
NImg=imnoise(Img,'gaussian'); % it was NImg=imnoise(Img,'gaussian',Var);
subplot(1,3,1);imshow(Img);title('Original Image');
subplot(1,3,2);imshow(NImg);title('Noisy Gaussian Image');
[r, c] =size(Img);
EImg=zeros(r,c);
EImg(1,:) =Img(1,:);
EImg(:,1)=Img(:,1);
A=[0.35 0.35 0.3;0 1 0;0 0 1];
%Initial state
Xkposeterior=[EImg(2, 1);EImg(1,2);EImg(1,1)];
X_prior = A*Xkposeterior;
%particles
N=100;
X_Particle=[];
X_P_wi=[];
for i = 1:N
X_Particle(i) = X_prior(1) + sqrt(V) * randn;
end
%%Xkposeterior=[EImg(2,1);EImg(1,2);EImg(1,1)];
for i=2:r
for j=2:c
Zk=NImg(i,j);
Xkposeterior=[EImg(i,j-1);EImg(i-1,j);EImg(i-1,j-1)];
X_prior = A*Xkposeterior;
for k_particle=1:N
X_Particle(k_particle)=X_prior(1) + sqrt(V) * randn;
X_P_wi(k_particle)=(1/sqrt(2*pi*x_R)) * exp(-(Zk - X_Particle(k_particle))^2/(2*x_R));
end
X_P_wi = X_P_wi./sum(X_P_wi);
for m = 1 : N
X_Particle(m) = X_Particle(find(rand <= cumsum( X_P_wi),1));
end
% EImg= mean(X_Particle);
end
end
subplot(1,3,3);imshow(EImg, []);title(' Particle Denoised Image');
Last edited by a moderator: