I = imread('1.jpg'); I_gray = rgb2gray(I); I_norm = imadjust(I_gray, stretchlim(I_gray)); I = imresize(I_norm, size(I_norm(:,:,1))); % 将图像进行归一化 I_normalized = mat2gray(I); % 构造高斯滤波器 hsize = 6; % 高斯滤波器大小 sigma =2; % 高斯滤波器标准差 G = fspecial('gaussian', hsize, sigma); % 将高斯滤波器应用到图像中 I_filtered = imfilter(I_normalized, G, 'symmetric'); I_norm = imadjust(I_filtered, stretchlim(I_filtered)); I_filtered = imresize(I_norm, size(I_norm(:,:,1))); % 显示图像 I_norm = imadjust(I_filtered, stretchlim(I_filtered)); I_filtered = imresize(I_norm, size(I_norm(:,:,1))); % 显示图像 I_sharpened = imsharpen(I_filtered,'Amount', 35); % 图像锐化 I_recon = imresize(I_sharpened, size(I(:,:,1))); imshow(I_recon);在这段代码中加入双边滤波器
时间: 2023-09-08 07:08:50 浏览: 85
LearnEpitome.rar_gray_gray2rgb
可以使用 MATLAB 中的 `bilateralFilter` 函数来实现双边滤波器。修改后的代码如下:
```
I = imread('1.jpg');
I_gray = rgb2gray(I);
I_norm = imadjust(I_gray, stretchlim(I_gray));
I = imresize(I_norm, size(I_norm(:,:,1)));
% 将图像进行归一化
I_normalized = mat2gray(I);
% 构造高斯滤波器
hsize = 6; % 高斯滤波器大小
sigma = 2; % 高斯滤波器标准差
G = fspecial('gaussian', hsize, sigma);
% 将高斯滤波器应用到图像中
I_filtered = imfilter(I_normalized, G, 'symmetric');
I_norm = imadjust(I_filtered, stretchlim(I_filtered));
I_filtered = imresize(I_norm, size(I_norm(:,:,1)));
% 添加双边滤波器
I_filtered = bilateralFilter(I_filtered, 5, 10, 10);
% 图像锐化
I_sharpened = imsharpen(I_filtered,'Amount', 35);
I_recon = imresize(I_sharpened, size(I(:,:,1)));
imshow(I_recon);
```
其中 `bilateralFilter` 函数中的参数含义分别为:输入图像、邻域大小、空间标准差和灰度值标准差。可以根据实际情况调整这些参数以达到更好的滤波效果。
阅读全文