当前位置:网站首页>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);
实现效果

边栏推荐
- Explain knative cloud function framework in simple terms!
- Metasploit-永恒之蓝攻击
- Redis 为什么这么快?Redis 的线程模型与 Redis 多线程
- Concurrent Park and unpark description
- Example of ICP registration for PCL
- Discussion on a problem
- Brush the title "sword finger offer" day04
- Case of burr (bulge) notch (depression) detection of circular workpiece
- pytorch的安装(非常详细)
- 二叉树习题总结
猜你喜欢

About new_ Online_ Judge_ 1081_ Thoughts on Goldbach's conjecture

Snowflake vs. Databricks谁更胜一筹?2022年最新战报

Robotframework+eclispe environment installation

卸载CUDA11.1

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

去 OPPO 面试,被问麻了

Discussion on a problem

Review of in vivo detection

3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks

Switch port mirroring Configuration Guide
随机推荐
数据库性能系列之子查询
Nacos configuration center dynamically refreshes the data source
Looking for a job for 4 months, interviewing 15 companies and getting 3 offers
open3d库的安装,conda常用指令,导入open3d时报这个错误Solving environment: failed with initial frozen solve. Retrying w
hdu5289(Assignment)
邮件服务器
超赞的卡尔曼滤波详解文章
Shell integrated application cases, archiving files, sending messages
面试必备:虾皮服务端15连问
Metasploit-永恒之蓝攻击
Pygame: alien invasion
Pyautogui realizes automatic office -rpa small case
Matlab-实时编辑器介绍
Fsm onehot 答题记录
达梦 PARTGROUPDEF是自定义的对象吗?
找工作 4 个月, 面试 15 家,拿到 3 个 offer
Ant advanced task
Metaaploit-后渗透技知识
Come on, chengxujun
Matlab-离散事件系统仿真实验