I've been studying to smoothing image with average of k- nearest neighbor filter.Here my code,but it has something wrong. Please help me or give me code for this algorithm? Many thanks...

조회 수: 7 (최근 30일)
I=uigetfile({'*.jpg';'*.png';'*.tif';'*.bmp'},'Select Image');
Img=imread(I);
a = rgb2gray(Img);
figure, imshow(a)
an=imnoise(a,'gaussian');
[m,n]=size(an);
figure, imshow(uint8(an))
b=input('Enter Averaging Mask size: ');
z=ones(b);
[p,q]=size(z);
w=1:p;
x=round(median(w));
anz=zeros(m+2*(x-1),n+2*(x-1));
for i=x:(m+(x-1))
for j=x:(n+(x-1))
anz(i,j)=an(i-(x-1),j-(x-1));
end
end
figure, imshow(uint8(anz))
% tính điểm ảnh trung bình
k=input('Enter k value:');
E = zeros(1, b*b);
sum=0;
w =1;
for i=1:m
for j=1:n
for x=1:p
for l=1:q
E(1,w)= anz(x,l);
w = w + 1;
end
end
for y=1:k
A = sort(E,'descend');
sum = sum + A(1,y);
T = sum/k;
an(i,j) = T;
end
end
end
figure, imshow(uint8(anz));

답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by