matlab练习程序(使用DCT图像增强)

close all;
clear all;
clc;
img=imread('1.jpg');
imshow(img);
[m n]=size(img);
img_re=zeros(m,n);
tmp=zeros(8,8);
for i=1:8:m
for j=1:8:n
tmp=mc(img(i:i+7,j:j+7));
img_re(i:i+7,j:j+7)=tmp;
end
end

figure,imshow(uint8(img_re));
figure,imshow(histeq(img));
%{
a=[238 238 236 237 236 228 227 234; ...
238 238 237 237 226 228 226 229; ...
238 238 237 238 238 232 227 226; ...
237 239 238 239 239 237 232 227; ...
237 237 237 239 240 240 236 231; ...
237 236 238 238 238 239 239 237; ...
238 237 238 238 237 238 239 237; ...
238 236 238 239 237 239 240 238];
%
}
function re=mc(a)
b=dct2(a);
c=zeros(15,1);
E=zeros(15,1);

for i=1:8
for j=1:8
E(i+j-1)=E(i+j-1)+abs(b(i,j));
end
end

N=[1 2 3 4 5 6 7 8 7 6 5 4 3 2 1];
for i=1:15
E(i)=E(i)/N(i);
end

for i=1:15
c(i)=E(i)/(sum(E(1:i)));
end

lambda=2;
E_pa=zeros(15,1);
H=zeros(15,1);
E_pa(1)=E(1);
H(1)=E_pa(1)/E(1);
re_dct(1,1)=b(1,1);

for i=2:15
r=sum(E(1:i));
beta=lambda*E(i);
alpha=sum(E_pa(1:i-1));
H(i)=alpha/(r-beta);
tmp=0;
for j=1:8
for k=1:8
if (k+j==i+1)
re_dct(j,k)=lambda*H(i)*b(j,k);
tmp=tmp+re_dct(j,k);
end
end
end
E_pa(i)=tmp/N(i);

end

%{
for i=2:15
alpha=sum(E_pa(1:i-1));
beta=lambda*E(i);
r=sum(E(1:i));
H(i)=alpha/(r-beta);
end

re_dct=zeros(8,8);
for k=1:8
for l=1:8
re_dct(k,l)=lambda*H(k+l-1)*b(k,l);
end
end
re_dct(1,1)=b(1,1);
%
}
re=idct2(re_dct);

暂时按自己的理解实现的,效果不好。

参考文献:Image Enhancement Using a Contrast Measure

posted @ 2012-04-02 09:47  Dsp Tian  阅读(3282)  评论(0编辑  收藏  举报