function wiener_main
close all;
%OrigImage = imread('leonard.jpg');%lenna %B2 %briefcase %coffeemaker %car
OrigImage = imread('lenna.jpg');%storm %B2 %briefcase %coffeemaker %car
%OrigImage = OrigImage(1:768,1:1024);
%OrigImage = OrigImage(1:1000,1:785);
%OrigImage = im2double(OrigImage);


Blur1 = fspecial('motion');
Blur2 = fspecial('motion',25,5);

Noise1 = 0.05;
Noise2 = 0.25;
Noise3 = 0;

Noised_Image1 = imnoise(OrigImage,'gaussian',0,Noise1); 
Noised_Image2 = imnoise(OrigImage,'gaussian',0,Noise2); 

Noised_Blurred_Image1 = imfilter(Noised_Image1,Blur1,'replicate','conv'); %Blur1 Noise1
Noised_Blurred_Image2 = imfilter(Noised_Image2,Blur1,'replicate','conv'); %Blur1 Noise2
Noised_Blurred_Image3 = imfilter(Noised_Image1,Blur2,'replicate','conv'); %Blur1 Noise1
Noised_Blurred_Image4 = imfilter(Noised_Image2,Blur2,'replicate','conv'); %Blur1 Noise2
Noised_Blurred_Image5 = imfilter(OrigImage,Blur2,'replicate','conv'); %Blur1 Noise2

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Noised_Blurred_Image12 = imnoise(BlurredImage1,'gaussian',0,Noise2); 
% Noised_Blurred_Image21 = imnoise(BlurredImage2,'gaussian',0,Noise1);
% Noised_Blurred_Image22 = imnoise(BlurredImage2,'gaussian',0,Noise2); 

[snr1,ResIm1] = wiener_laplacian(OrigImage, Noised_Blurred_Image2, Blur1, Noise2, 2 , 9); % Run wiener_laplacian with case 2
imwrite(ResIm1,'res1.jpg');
% [snr2,ResIm2] = wiener_laplacian(OrigImage, Noised_Blurred_Image2, Blur1, Noise2, 3 , 9);
% imwrite(ResIm2,'res2.jpg');
% [snr3,ResIm3] = wiener_laplacian(OrigImage, Noised_Blurred_Image3, Blur2, Noise1, 3 , 25);
% imwrite(ResIm3,'res3.jpg');
% [snr4,ResIm4] = wiener_laplacian(OrigImage, Noised_Blurred_Image4, Blur2, Noise2, 3 , 25);
% imwrite(ResIm4,'res4.jpg');

% [snr5,ResIm5] = wiener_laplacian(OrigImage, Noised_Blurred_Image5, Blur2, Noise3, 1 , 25);
% imwrite(ResIm5,'res4.jpg');

% figure
% tmp = sprintf('Motion = %d pixel , Noise = %0.3g', 9 , Noise1);
% subplot(2,2,1);imshow(ResIm1); title(tmp);
% tmp = sprintf('Motion = %d pixel , Noise = %0.3g', 9 , Noise2);
% subplot(2,2,2);imshow(ResIm2); title(tmp);
% tmp = sprintf('Motion = %d pixel , Noise = %0.3g', 25 , Noise1);
% subplot(2,2,3);imshow(ResIm3); title(tmp);
% tmp = sprintf('Motion = %d pixel , Noise = %0.3g', 25 , Noise2);
% subplot(2,2,4);imshow(ResIm4); title(tmp);

%[snr2,ResIm2] = wiener_laplacian(OrigImage, Noised_Blurred_Image1, Blur1, Noise1, 3 );
%[snr5,ResIm5] = wiener_laplacian(OrigImage, Noised_Blurred_Image11, Blur1, Noise1, 5 );
% 

% OrigImage = im2double(OrigImage);
% p = OrigImage(1,1);

%[snr3,ResIm3] = wiener_laplacian(OrigImage, Noised_Blurred_Image12, Blur1, Noise2, 2 , OrigImage);
% [snr4,ResIm4] = wiener_laplacian(OrigImage, Noised_Blurred_Image12, Blur1, Noise2, 4 , ResIm3);
%[snr6,ResIm6] = wiener_laplacian(OrigImage, Noised_Blurred_Image12, Blur1, Noise2, 5 , ResIm3);

% A = zeros(3,3);
% A = double(A);
% %A = [0 Noise1 Noise2 ; Blur1 snr1 snr2 ; Blur2 snr3 snr4]
% snr1 
% snr2
% snr3
% snr4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
