课后作业,实现:均值、谐波均值、中值、中点等滤波器。对应《数字图像处理》第三版,5.1-5.9课后题。
代码基于Matlab实现。完整代码及处理结果见:GitHub
步骤
- 加载图像
- 向外拓展一个像素的大小
- 与滤波器做卷积操作
- 输出图像
5.1 算数均值滤波
代码实现
close all
clear all
image=imread('filtering.tif');
figure();
subplot(2,2,1);
imshow(image);
xlabel('Raw image');
image_mean_3 = arithmetic_mean_filter(image,3);
subplot(2,2,2);
imshow(image_mean_3)
xlabel('arithmetic mean filter/3');
image_mean_5 = arithmetic_mean_filter(image,5);
subplot(2,2,3);
imshow(image_mean_5)
xlabel('arithmetic mean filter/5');
image_mean_9 = arithmetic_mean_filter(image,9);
subplot(2,2,4);
imshow(image_mean_9)
xlabel('arithmetic mean/9');
%%
function [result_imag]= arithmetic_mean_filter(image,filter_size)
Ex_image = extend_imag(image);
result_imag = image;
[M,N]=size(Ex_image);
helf_size = (filter_size-1)/2;
for x=1+helf_size:1:M-helf_size
for y=1+helf_size:1:N-helf_size
slid=Ex_image(x-helf_size: