Generate the optimum coefficient using optimization filter
Afficher commentaires plus anciens
Dear all
I have a gray image . I convert it to DCT . Then i take 4x4 blocks from this DCT of the gray image . I convert the 4x4 dct blocks to idct . Then i filter this 4x4 using optimization filter . . I chose the coefficient of the filter to be a(1)=1/7; a(2)=1/7; a(3)=1/7; a(4)=1/7; a(5)=1;
However, my supervisor want the optimization filter to generate the optimum coefficient itself .So how i could make the code to chose the optimization filter ?. Is this optimization filter is correct ? I used to m-file one for Global and one for the optimization filter The code for optimization part is as the following :
% clear all
close all
clc
global image1 image2
fname1=input('Enter image file name ? ','s')
[x1]=imread(fname1);
k=input('Enter k? ');
len1=length(x1);
imm = x1;
im = ones(size(imm));
im_1 = uint8(im);
s= 1;
for s=1:3
green1=x1(:,:,s);
gray1=rgb2gray(x1);
% doubel gray2=double(gray1); green2=double(green1);
% Convert to DCT gray3=dct2(gray2);
green3=dct2(green2);
%DCT_green=green3(1:4,1:4);
tred=ones(len1,len1);
for i=1:k
for j=1:k
freqblockred(i,j)=green3(i,j);
freqblockgray(i,j)=gray3(i,j);
end
end
IDCT_Gray=idct2(freqblockgray);
IDCT_green=idct2(freqblockred);
green5=double(IDCT_green);
% The optimization filter coefficients:
a(1)=1/7;
a(2)=1/7;
a(3)=1/7;
a(4)=1/7;
a(5)=1;
image1=IDCT_Gray;
image2=IDCT_green;
[zy,mse]= fminsearch(@routine, a);
h(1)=zy(1);
h(2)=zy(2);
h(3)=zy(3);
h(4)=zy(4);
h(5)=zy(3);
h(6)=zy(2);
h(7)=zy(1);
hh=transpose(h)*h;
yy2=zy(5)+imfilter(IDCT_Gray,hh,'replicate');
yy3=double(yy2); yy4=dct2(yy3);
gray4=gray3; gray4(1:4,1:4) = yy4;
gray5 = idct2(gray4); gray6 = double(gray5); %Calculate MSE between the original red layer & generated one [row1,col1] = size(gray6); diff1=(uint8(gray6)-uint8(green2)).^2; mes1=sum(sum(diff1))/(row1*col1); psnr =10*log10((255*255)/mes1)
imm9 = uint8(gray6);
im_1(:,:,s) = imm9 ;
end
psnr2 = 10*log10((255*255)/((sum(sum((x1-im_1).^2)))));
imshow(uint8(im_1));
while the code for global is as the following :
function mse=routnie(a)
global image1 image2
%--- Filter
% 1D filter
b(1)=a(1); b(2)=a(2); b(3)=a(3); b(4)=a(4); b(5)=a(3); b(6)=a(2); b(7)=a(1);
%2D Filter
hh=transpose(b)*b;
image3=a(5)+imfilter(image1,hh,'replicate');
image4=uint8(image3);
image5=double(image4);
%-------------
mse=((sum(sum((image5-image2).^2))));
return
So please let me know how to solve the problem of finding the optimum coefficients that will give me maximum PSNR .. thanks
1 commentaire
zgrt
le 16 Nov 2013
Réponses (0)
Catégories
En savoir plus sur Matched Filter and Ambiguity Function dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!