请编写MATLAB代码,能够完成以下功能: 导入图片作为原图像,对原图像分别进行理想高通滤波、巴特沃斯高通滤波以及高斯高通滤波,并在同一窗口中分别生成理想高通滤波后的透视图、理想高通滤波后的函数图像、理想高通后的滤波横截面图、巴特沃斯高通滤波后的透视图、巴特沃斯高通滤波后的函数图像、巴特沃斯高通滤波后的滤波横截面图、高斯高通滤波后的透视图、高斯高通滤波后的函数图像、高斯高通滤波后的滤波横截面图。
时间: 2023-11-19 08:04:58 浏览: 108
以下是使用MATLAB实现对图片进行理想高通滤波、巴特沃斯高通滤波以及高斯高通滤波,并在同一窗口中生成透视图、函数图像、滤波横截面图的代码。请注意,由于每张图片的大小和分辨率不同,可能需要对代码进行一些修改才能得到最佳效果。
```matlab
% 导入原图像
img = imread('image.jpg');
% 转换为灰度图像
gray_img = rgb2gray(img);
% 理想高通滤波
D0 = 50;
h = hpfilter('ideal', size(gray_img), D0);
ideal_result = uint8(real(ifft2(ifftshift(h) .* fftshift(fft2(double(gray_img))))));
% 巴特沃斯高通滤波
n = 4;
D0 = 50;
h = hpfilter('btw', size(gray_img), n, D0);
btw_result = uint8(real(ifft2(ifftshift(h) .* fftshift(fft2(double(gray_img))))));
% 高斯高通滤波
D0 = 50;
h = hpfilter('gaussian', size(gray_img), D0);
gaussian_result = uint8(real(ifft2(ifftshift(h) .* fftshift(fft2(double(gray_img))))));
% 生成透视图
figure;
subplot(3,3,1);imshow(img);title('Original Image');
subplot(3,3,2);imshow(ideal_result);title('Ideal Highpass Filtered Image');
subplot(3,3,3);imshow(btw_result);title('Butterworth Highpass Filtered Image');
subplot(3,3,4);imshow(gaussian_result);title('Gaussian Highpass Filtered Image');
% 生成函数图像
subplot(3,3,5);imshow(h,[]);title('Ideal Highpass Filter Function');
subplot(3,3,6);imshow(h,[]);title('Butterworth Highpass Filter Function');
subplot(3,3,7);imshow(h,[]);title('Gaussian Highpass Filter Function');
% 生成滤波横截面图
ideal_row = round(size(h,1)/2);
ideal_col = round(size(h,2)/2);
subplot(3,3,8);plot(1:size(gray_img,2),gray_img(ideal_row,:),'b',1:size(ideal_result,2),ideal_result(ideal_row,:),'r');title('Ideal Highpass Filtered Image Horizontal Cross Section');
btw_row = round(size(h,1)/2);
btw_col = round(size(h,2)/2);
subplot(3,3,9);plot(1:size(gray_img,2),gray_img(btw_row,:),'b',1:size(btw_result,2),btw_result(btw_row,:),'r');title('Butterworth Highpass Filtered Image Horizontal Cross Section');
gaussian_row = round(size(h,1)/2);
gaussian_col = round(size(h,2)/2);
subplot(3,3,10);plot(1:size(gray_img,2),gray_img(gaussian_row,:),'b',1:size(gaussian_result,2),gaussian_result(gaussian_row,:),'r');title('Gaussian Highpass Filtered Image Horizontal Cross Section');
```
阅读全文