当前位置:网站首页>Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)
Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)
2022-07-27 09:57:00 【手写不期而遇】
理论基础
一幅图像往往受到各种噪声的干扰,噪声常为一些孤立的像素点,往往是叠加在图像上的随机噪点,像雪花一样使图像被污染,而图像灰度应该是相对连续变化的,一般不会突然变大或变小,这种噪声可通过邻域使它得到抑制。
N.N中值滤波算法中,当灰度图像f中以f(i,j)为中心的N.N屏蔽窗口(N为奇数)内中值灰度为a时,无条件将f(i,j)=a处理,N由用户给定。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%N*N中值滤波
%Author:Zhu
%时间:2022.3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
image = imread("E:\\1.jpg");
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
%输入数值,设定的窗口大小(大小必须为奇数)
maskWidth = 5;
maskHeight = 5;
%一般都是奇数
maskCenterX=(maskWidth+1)/2;
maskCenterY=(maskHeight+1)/2;
%寻找数组中中值大小
maskValue=zeros(1,maskHeight*maskWidth);
%数组中间的序号
middleNum = maskHeight*maskWidth/2+0.5;
for i=maskCenterY:1:height-maskHeight+maskCenterY
for j=maskCenterX:1:width-maskWidth+maskCenterX
%计算像素值
pixelResult = 0;
%遍历模板区域
for k=1:1:maskHeight
for p = 1:1:maskWidth
%把数值放入到数组中
maskValue((k-1)*maskHeight+p) = image_matrix(i-(maskHeight+1)/2+k,j-(maskWidth+1)/2+p);
end
end
%找到数组中中值,采用冒泡排序法,把数值从大到小排列
for num = 1:maskHeight*maskWidth
for xx = 1:maskHeight*maskWidth-1
if(maskValue(xx)<maskValue(xx+1))
temp = maskValue(xx);
maskValue(xx) = maskValue(xx+1);
maskValue(xx+1) = temp;
end
end
end
%更新中值赋予当前像素点
image_matrix(i,j)= maskValue(middleNum);
end
end
image_out = uint8(image_matrix);
%显示
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);
实现效果

边栏推荐
- hdu5288(OO’s Sequence)
- Come on, chengxujun
- Shell综合应用案例,归档文件、发送消息
- 01_ Movie recommendation (contentbased)_ Object portrait
- Configuration of pytorch deep learning environment based on cuda10.0
- [cloud native • Devops] master the container management tool rancher
- 安装CUDA失败的情况nsight visual studio edition失败
- NFT system development - Tutorial
- Snowflake vs. databricks who is better? The latest war report in 2022
- Metaaploit-后渗透技知识
猜你喜欢

Nacos configuration center dynamically refreshes the data source

NVIDIA geforce experience login error: the verifier failed to load. Please check your browser settings, such as the advertisement interceptor (solution)

After one year, the paper was finally accepted by the international summit

Pytorch installation (very detailed)
![[SCM]源码管理 - perforce 分支的锁定](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[SCM]源码管理 - perforce 分支的锁定

open3d库的安装,conda常用指令,导入open3d时报这个错误Solving environment: failed with initial frozen solve. Retrying w

Robotframework+eclispe environment installation

pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0
[email protected]、$?、env看所有的全局变量值、set看所有变量"/>Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量

QT learning (II) -- a brief introduction to QT Creator
随机推荐
Food safety | the kitchen board environment is very important. Do you know these use details?
Acl2021 best paper released, from ByteDance
Looking for a job for 4 months, interviewing 15 companies and getting 3 offers
邮件服务器
Understanding of batchnorm2d() function in pytorch
面试京东 T5,被按在地上摩擦,鬼知道我经历了什么?
Leetcode.814. binary tree pruning____ DFS
Pyautogui realizes automatic office -rpa small case
Shell operator, $((expression)) "or" $[expression], expr method, condition judgment, test condition, [condition], comparison between two integers, judgment according to file permission, judgment accor
QT learning (II) -.Pro file explanation
Mysql database experiment training 5, data query YGGL database query (detailed)
Girl fan wants to find a boyfriend, but it's for
Excellent Kalman filter detailed article
学习Typescript(一)
Cannot start after installing MySQL 5.7.27 in CentOS 7? (Language bash)
VS2019+CUDA11.1新建项目里没有CUDA选项
PCL各模块概述(1.6)
视觉SLAM十四讲笔记(一):第一讲+第二讲
Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
文件上传漏洞绕过方法