MATLAB图像噪声添加与滤波

news/2024/7/21 5:20:08 标签: matlab, 计算机视觉, 图像处理

在 MATLAB 中添加图像噪声和进行滤波通常使用以下函数:

  1. 添加噪声:可以使用imnoise函数向图像添加各种类型的噪声,如高斯噪声、椒盐噪声等。

  2. 滤波:可以使用各种滤波器对图像进行滤波处理,例如中值滤波、高斯滤波等。

下面是一个示例代码,演示如何在 MATLAB 中添加高斯噪声、椒盐噪声,并使用中值滤波和高斯滤波进行滤波:

% 读取图像
image = imread('lena.png');

% 添加高斯噪声
noisy_image_gaussian = imnoise(image, 'gaussian', 0, 0.02);

% 添加椒盐噪声
noisy_image_salt_and_pepper = imnoise(image, 'salt & pepper', 0.05);

% 中值滤波
filtered_image_median_gaussian = medfilt2(noisy_image_gaussian, [3, 3]);
filtered_image_median_salt_and_pepper = medfilt2(noisy_image_salt_and_pepper, [3, 3]);

% 高斯滤波
filtered_image_gaussian_gaussian = imgaussfilt(noisy_image_gaussian, 2);
filtered_image_gaussian_salt_and_pepper = imgaussfilt(noisy_image_salt_and_pepper, 2);

% 显示结果
subplot(3, 3, 1);
imshow(image);
title('Original Image');

subplot(3, 3, 2);
imshow(noisy_image_gaussian);
title('Gaussian Noisy Image');

subplot(3, 3, 3);
imshow(noisy_image_salt_and_pepper);
title('Salt & Pepper Noisy Image');

subplot(3, 3, 4);
imshow(filtered_image_median_gaussian);
title('Median Filter (Gaussian Noise)');

subplot(3, 3, 5);
imshow(filtered_image_median_salt_and_pepper);
title('Median Filter (Salt & Pepper Noise)');

subplot(3, 3, 6);
imshow(filtered_image_gaussian_gaussian);
title('Gaussian Filter (Gaussian Noise)');

subplot(3, 3, 7);
imshow(filtered_image_gaussian_salt_and_pepper);
title('Gaussian Filter (Salt & Pepper Noise)');

说明:

  1. 添加噪声: 使用imnoise函数向原始图像添加高斯噪声和椒盐噪声。

  2. 滤波: 分别使用medfilt2函数进行中值滤波,使用imgaussfilt函数进行高斯滤波。

  3. 显示结果: 将原始图像、添加噪声后的图像以及经过中值滤波和高斯滤波处理后的图像在多个子图中进行显示,以便进行对比观察。


http://www.niftyadmin.cn/n/5402747.html

相关文章

vue3 vite项目一运行就401(Unauthorized)

问题:项目一执行: pnpm run dev, 启动就出错, Failed to load resource: the server responded with a status of 401 (Unauthorized) 分析: 项目之前是正常运行的,没有问题,回溯刚刚改动,还原…

TypeError: SnakeEnv.reset() got an unexpected keyword argument ‘seed‘

TypeError: SnakeEnv.reset() got an unexpected keyword argument ‘seed’ logger.deprecation( Traceback (most recent call last): File “H:\AILab\RL\Snaker2\snake_train.py”, line 15, in model.learn(total_timesteps10000) File “D:\Anaconda3\envs\lab\lib\sit…

xxl-job异步任务日志打印到调度器任务管理日志

文章目录 1. xxl-job-core模块添加过滤器2. 执行器logback.xml添加过滤器配置3. 测试 1. xxl-job-core模块添加过滤器 package com.xxl.job.core.config;import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.ThrowableProxy; import ch.qos.…

ChatGPT 4.0:革新文献检索与推荐体验

ChatGPT 4.0:革新文献检索与推荐体验 随着信息时代的到来,学术文献的数量急剧增加,如何快速而准确地检索到所需的文献,以及发现潜在有价值的研究,成为了学术界的一大挑战。ChatGPT 4.0作为最新一代的自然语言处理模型…

移动端的React项目中如何配置自适应和px转rem

创建项目 create-react-app project-name 启动项目 npm start 下载自适应和px转rem的插件 自适应的: npm install lib-flexible --save px转rem的:npm install postcss-pxtorem5.1.1 --save-dev 创建craco.config.js配置文件 在package.json中…

Kotlin 中的 with 函数简介

在 Kotlin 中,with 函数是一个非常方便的工具,它可以帮助简化对特定对象的操作。本文将介绍 with 函数的使用方法,并与 Java 中的实现进行对比。 Kotlin 中的 with 函数 with 函数允许在一个对象上执行一系列操作,而无需重复引用…

假如有n个台阶,一次只能上1个台阶或2个台阶,请问走到第n个台阶有几种走法?

说明如下:假如有 3个台阶&#xff0c;那么总计就有3种走法:第一种为每次上1个台阶&#xff0c;上3次;第二种为先上2个台阶&#xff0c;再上1个台阶;第三种为先上1个台阶&#xff0c;再上2个台阶。 解决方法&#xff1a;递归 代码展示&#xff1a; #include <stdio.h> …

React之组件定义和事件处理

一、组件的分类 在react中&#xff0c;组件分为函数组件和class组件&#xff0c;也就是无状态组件和有状态组件。 * 更过时候我们应该区别使用无状态组件&#xff0c;因为如果有状态组件会触发生命周期所对应的一些函数 * 一旦触发他生命周期的函数&#xff0c;它就会影响当前项…