生成matlab图像平滑代码
时间: 2023-09-30 16:10:01 浏览: 50
以下是一个简单的Matlab代码示例,使用平均滤波器来平滑图像:
```
% 读取图像
img = imread('example.jpg');
% 创建一个 5x5 的平均滤波器
filter = fspecial('average', [5 5]);
% 应用平均滤波器
img_smooth = imfilter(img, filter);
% 显示原始图像和平滑后的图像
subplot(1,2,1), imshow(img), title('原始图像');
subplot(1,2,2), imshow(img_smooth), title('平滑后的图像');
```
你可以根据需要修改平均滤波器的大小,以及选择不同类型的滤波器来实现不同的平滑效果。
相关问题
matlab生成一段图像加噪平滑处理的代码
以下是MATLAB生成一段图像加噪平滑处理的代码:
```MATLAB
% 加载图像
img = imread('image.jpg');
% 添加高斯噪声
noise = randn(size(img)).*20;
img_noise = uint8(double(img)+noise);
% 中值滤波平滑处理
img_smooth = medfilt2(img_noise);
% 显示处理后的图像
subplot(1,3,1);
imshow(img);
title('原图');
subplot(1,3,2);
imshow(img_noise);
title('加噪后');
subplot(1,3,3);
imshow(img_smooth);
title('平滑后');
```
希望这能帮助到你!
matlab 图像平滑算法
以下是MATLAB中常用的图像平滑算法:
1. 均值滤波
```matlab
img = imread('image.jpg');
img_smoothed = imfilter(img, fspecial('average', [3 3]));
imshow(img_smoothed);
```
2. 中值滤波
```matlab
img = imread('image.jpg');
img_smoothed = medfilt2(img, [3 3]);
imshow(img_smoothed);
```
3. 高斯滤波
```matlab
img = imread('image.jpg');
img_smoothed = imgaussfilt(img, 2);
imshow(img_smoothed);
```
其中,`imread`函数用于读取图像,`imshow`函数用于显示图像,`fspecial`函数用于生成滤波器,`imfilter`函数用于对图像进行滤波,`medfilt2`函数用于进行中值滤波,`imgaussfilt`函数用于进行高斯滤波。