双边滤波去噪matlab代码
时间: 2023-09-11 19:13:05 浏览: 165
基于双边滤波实现灰度和彩色图像去噪附matlab代码.zip
5星 · 资源好评率100%
Sure! Here's an example of bilateral filtering denoising using MATLAB:
```matlab
% Load the noisy image
noisyImage = imread('noisy_image.png');
% Convert the image to grayscale if needed
if size(noisyImage, 3) > 1
noisyImage = rgb2gray(noisyImage);
end
% Parameters for bilateral filtering
sigmaSpatial = 2; % Spatial standard deviation
sigmaIntensity = 20; % Intensity standard deviation
% Apply bilateral filtering
filteredImage = imbilatfilt(noisyImage, sigmaSpatial, sigmaIntensity);
% Display the results
figure;
subplot(1, 2, 1);
imshow(noisyImage);
title('Noisy Image');
subplot(1, 2, 2);
imshow(filteredImage);
title('Filtered Image');
```
In this code, we first load the noisy image using the `imread` function. If the image is in color, we convert it to grayscale using the `rgb2gray` function.
Next, we define the parameters for bilateral filtering: `sigmaSpatial` controls the spatial standard deviation, which determines the size of the filtering neighborhood, and `sigmaIntensity` controls the intensity standard deviation, which determines how much the pixel values within the neighborhood affect the filtering.
We then apply bilateral filtering using the `imbilatfilt` function. This function takes the noisy image and the sigma values as input and returns the filtered image.
Finally, we display the original noisy image and the filtered image side by side using the `imshow` function and `subplot` to create a figure with two subplots.
Note: Make sure to replace `'noisy_image.png'` with the actual filename and path of your noisy image.
阅读全文