tic
clear all
S=imread('lena.png');
S=double(S);
S=Normalized(S);
[p,q]=size(S);
average=zeros(p,q);
rme=zeros(p,q);
beta=zeros(p,q);
heta=zeros(p,q);
u=zeros(p,q);
for i0=2:1:p-1 %此处开始图像循环
for i1=2:1:q-1
V=[S(i0-1,i1-1) S(i0-1,i1) S(i0-1,i1+1);
S(i0,i1-1) S(i0,i1) S(i0,i1+1);
S(i0+1,i1-1) S(i0+1,i1) S(i0+1,i1+1)];
average(i0,i1)=mean(V(: ));%求窗口均值
%%%下面小循环为了求当前窗口的标准差
su=0;
for i=1:1:3
for j=1:1:3
su=(V(i,j)-average(i0,i1))^2+su;
end
end
rme(i0,i1)=sqrt(su/9);%标准差
%%%%下面是最终想要求三个矩阵(应用均值和标准差)
beta(i0,i1)=(rme(i0,i1)/average(i0,i1));
u(i0,i1)=log(1/average(i0,i1));
heta(i0,i1)=average(i0,i1);
end
end
function [normalized_matrix]=Normalized(matrix)
input_matrix=abs(matrix);
Max_input=max(input_matrix(: ));
Min_input=min(input_matrix(: ));
min_matrix=ones(size(input_matrix)).*Min_input;
normalized_matrix=(input_matrix-min_matrix)./(Max_input-Min_input+eps);
Elapsed time is 5.915782 seconds.
(V是一个3x3的窗口,用此窗口遍历整幅图像,求窗口内图像的均值和标准差;应用标准差和均值求三个矩阵beta,u和heta)
需要解决的问题:
1最后求得的图像均值,标准差和最后三个矩阵边界像素都为0。这个边界问题怎么解决?
2运算时间太长,我想这样窗口遍历图像的算法应该有更加高效的程序,精简程序或其他高效程序?
请高手指点,或可以站内和我联系,如果可以解决可以追加BB,呵呵[Last edited by jjdg on 2011-11-16 at 01:49]