算术均值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
resultImage(x,y)=sum(is(:))/numel(is);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3算术均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
resultImage(x,y)=sum(is(:))/numel(is);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5算术均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
resultImage(x,y)=sum(is(:))/numel(is);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9算术均值');
几何均值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
resultImage(x,y)=prod(prod(is(:)))^(1/numel(is));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3几何均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
resultImage(x,y)=prod(prod(is(:)))^(1/numel(is));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5几何均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
resultImage(x,y)=prod(prod(is(:)))^(1/numel(is));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9几何均值');
谐波均值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
is=1./is;
resultImage(x,y)=numel(is)/sum(is(:));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3谐波均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
is=1./is;
resultImage(x,y)=numel(is)/sum(is(:));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5谐波均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
is=1./is;
resultImage(x,y)=numel(is)/sum(is(:));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9谐波均值');
逆谐波
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
Q1 = 1.5;
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
resultImage(x,y) = sum(is(:).^(Q1+1))/sum(is(:).^(Q1));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3逆谐波均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
resultImage(x,y) = sum(is(:).^(Q1+1))/sum(is(:).^(Q1));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5逆谐波均值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
resultImage(x,y) = sum(is(:).^(Q1+1))/sum(is(:).^(Q1));
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9逆谐波均值');
中值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
temp = sort(is(:));
resultImage(x,y)= temp((numel(temp)-1)/2);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3中值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
temp = sort(is(:));
resultImage(x,y)= temp((numel(temp)-1)/2);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5中值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
temp = sort(is(:));
resultImage(x,y)= temp((numel(temp)-1)/2);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9中值');
最大值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
temp = is(:);
resultImage(x,y)= max(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3最大值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
temp = is(:);
resultImage(x,y)= max(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5最大值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
temp = is(:);
resultImage(x,y)= max(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9最大值');
最小值
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
temp = is(:);
resultImage(x,y)= min(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3最小值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
temp = is(:);
resultImage(x,y)= min(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5最小值');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
temp = is(:);
resultImage(x,y)= min(temp);
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9最小值');
中点
close all
clear all
f=imread('D:/testData/filtering.tif');
[w,h]=size(f);
image= f(:,:);
fsize1=3;
fsize2=5;
fsize3=9;
fssize1=(fsize1-1)/2;
fssize2=(fsize2-1)/2;
fssize3=(fsize3-1)/2;
figure();
subplot(1,2,1);
imshow(image);
xlabel('原图像');
resultImage = image;
for x=1+fssize1:1:w-fssize1
for y=1+fssize1:1:w-fssize1
is=f(x-fssize1:1:x+fssize1,y-fssize1:1:y+fssize1);
temp = is(:);
resultImage(x,y)= (max(temp) + min(temp))/2;
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('3*3中点');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize2:1:w-fssize2
for y=1+fssize2:1:w-fssize2
%遍历每个点的四周
is=f(x-fssize2:1:x+fssize2,y-fssize2:1:y+fssize2);
temp = is(:);
resultImage(x,y)= (max(temp) + min(temp))/2;
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('5*5中点');
resultImage= f(:,:);
figure();
subplot(1,2,1);
imshow(f);
xlabel('原图像');
for x=1+fssize3:1:w-fssize3
for y=1+fssize3:1:w-fssize3
%遍历每个点的四周
is=f(x-fssize3:1:x+fssize3,y-fssize3:1:y+fssize3);
temp = is(:);
resultImage(x,y)= (max(temp) + min(temp))/2;
end
end
subplot(1,2,2);
imshow(resultImage);
xlabel('9*9中点');