Lms filter

السلام عليكم ورحمة الله…

انا ابستخدم فلتر lms لـ إزالة التشويش من الصور …

هذا العمل …


I = imread('c1.jpg');
subplot(2,2,1); imshow(I);title('orignal image');
 
J = imnoise(I,'salt & pepper',0.02);
subplot(2,2,2); imshow(J);title('add noise salt&pepper');
[x1,y1]=size(I);
new=zeros(x1,y1);
sum=0;
mu = 0.008; 
 
h = adaptfilt.lms(32,mu);
 
Des=I+J;% d
 
si=1;
sj=1;
 
 
%==============
row=1;
w=zeros(3,3);
%=================== 
 
ss='true';
while (ss=='true') 
for i=si:(si+3-1)
for j=sj : (sj+3-1)
% 
%
%
 
end % j
end % i
 
if (j<y1) %shift one pixcel to right
sj=j-1;
si=row;
elseif (i<x1) %move to another row
tempI=I(:,i);
tempDes=Des(:,i);
[y,e] = filter(h,tempI,tempDes);
new(:,i)=y;
 
row=row+1;
si=i-1;
sj=1;
 
 
else
ss='fals';
break
end % if
 
end % while 
 
subplot(2,2,3); imshow(new);title('denoise');

فالنتيجة وضعتها بالمرفق ، فالخطأ هو ان الصوره بعد الفلتره لاتظهر الألوان وتدرجاته
فقط اسود وابيض على شكل نقط…

ياليت احد يصحح لنا الخطأ في كتابة عمل هذا الفلتر…

الكود به بعض الاشياء الغير منطقية
ما فائدة هذا

for i=si:(si+3-1)
for j=sj : (sj+3-1)
% 
%
%
 
end % j
end % i

وبعد ذلك انت تستخدم i
هذا فقط سياخد أخر قيمة لى i

tempI=I(:,i);
tempDes=Des(:,i);

صححت هذا الخطأ فظهرت لي النتجية متغيره ووضعتها بالمرفق…


[FONT=Courier New][SIZE=2]I = imread([/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'c1.jpg'[/color][/size][/font][FONT=Courier New][SIZE=2]);
subplot(2,2,1); imshow(I);title([/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'orignal image'[/color][/size][/font][FONT=Courier New][SIZE=2]);

J = imnoise(I,[/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'salt & pepper'[/color][/size][/font][FONT=Courier New][SIZE=2],0.02);
subplot(2,2,2); imshow(J);title([/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'add noise salt&pepper'[/color][/size][/font][FONT=Courier New][SIZE=2]);
[x1,y1]=size(I);
new=zeros(x1,y1);
sum=0;
mu = 0.008; 

h = adaptfilt.lms(32,mu);

Des=I+J;[/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% d
[/color][/size][/font][FONT=Courier New][SIZE=2]
si=1;
sj=1;


[/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%==============
[/color][/size][/font][FONT=Courier New][SIZE=2]row=1;
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%w=zeros(3,3);
[/color][/size][/font][FONT=Courier New][SIZE=2][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%=================== 

[/color][/size][/font][FONT=Courier New][SIZE=2]ss=[/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'true'[/color][/size][/font][FONT=Courier New][SIZE=2];
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]while[/color][/size][/font][FONT=Courier New][SIZE=2] (ss==[/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'true'[/color][/size][/font][FONT=Courier New][SIZE=2]) 
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] i=si:(si+3-1)[/color]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][FONT=Courier New][SIZE=2] j=sj : (sj+3-1)
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% 
[/color][/size][/font][FONT=Courier New][SIZE=2][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%
[/color][/size][/font][FONT=Courier New][SIZE=2][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%

[/color][/size][/font][FONT=Courier New][SIZE=2]

[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] (j<y1) [/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%shift one pixcel to right
[/color][/size][/font][FONT=Courier New][SIZE=2]sj=j-1;
si=row;
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]elseif[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] (i<x1) [/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]%move to another row
[/color][/size][/font][FONT=Courier New][SIZE=2]tempI=I(:,i);
tempDes=Des(:,i);
[y,e] = filter(h,tempI,tempDes);
new(:,i)=y;

row=row+1;
si=i-1;
sj=1;


[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
[/color][/size][/font][FONT=Courier New][SIZE=2]ss=[/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'fals'[/color][/size][/font][FONT=Courier New][SIZE=2];
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]break
end[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] [/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% if

[/color][/size][/font][FONT=Courier New][SIZE=2][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font][FONT=Courier New][SIZE=2] [/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% j
[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] [/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% i
[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#000000] [/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22]% while 

[/color][/size][/font][FONT=Courier New][SIZE=2]subplot(2,2,3); imshow(new);title([/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0]'denoise'[/color][/size][/font][FONT=Courier New][SIZE=2]);
[/size][/font] 

هل تعرف عن lms…وطريقته بالفلترة…؟

لا معنديش فكرة عن هذا الفلتر لكن هل هذه النتيجة بعد التعديل صحيحة أم لا ؟

لا مو صحيحه…لازم تكون نفس الصوره الأصليه…:frowning:

أخى العزيز هذا الفلتر يستخدم فى معالجة الاشارة وليس خاص بمعالجة الصور
ولاستخدامه بشكل صحيح راجع المثال الموجود فى الهيلب

x  = randn(1,500);     % Input to the filter 
b  = fir1(31,0.5);     % FIR system to be identified 
n  = 0.1*randn(1,500); % Observation noise signal 
d  = filter(b,1,x)+ n;  % Desired signal 
mu = 0.008;            % LMS step size. 
ha = adaptfilt.lms(32,mu); 
[y,e] = filter(ha,x,d); 
subplot(2,1,1); plot(1:500,[d;y;e]); 
title('System Identification of an FIR Filter'); 
legend('Desired','Output','Error'); 
xlabel('Time Index'); ylabel('Signal Value'); 
subplot(2,1,2); stem([b.',ha.coefficients.']); 
legend('Actual','Estimated'); 
xlabel('Coefficient #'); ylabel('Coefficient Value');  grid on;