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

边栏推荐
- Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号
- 二叉树习题总结
- How to create a.Net image with diagnostic tools
- TFlite 的简单使用
- QT learning (II) -- a brief introduction to QT Creator
- 学习Typescript(一)
- Oracle RAC 19C PDB instance is down
- 3D restoration paper: shape painting using 3D generative advantageous networks and recurrent revolutionary networks
- 达梦 PARTGROUPDEF是自定义的对象吗?
- 活体检测综述
猜你喜欢
[email protected], "/>Shell variables, system predefined variables $home, $pwd, $shell, $user, custom variables, special variables $n, $, $*, [email protected],

Robotframework+eclispe environment installation

面试必备:虾皮服务端15连问

Pytorch installation (very detailed)

Configuration of pytorch deep learning environment based on cuda10.0

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

QT learning (II) -- a brief introduction to QT Creator

安装CUDA失败的情况nsight visual studio edition失败

Data visualization

StyleGAN论文笔记+修改代码尝试3D点云生成
随机推荐
安装CUDA失败的情况nsight visual studio edition失败
[cloud native • Devops] master the container management tool rancher
Word2vec principle and application and article similarity (recommended system method)
DCGAN论文改进之处+简化代码
Anchor Free检测器:CenterNet
3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks
Intermediate and advanced test questions ": what is the implementation principle of mvcc?
C # set different text watermarks for each page of word
Anaconda installation (very detailed)
Leetcode.814. binary tree pruning____ DFS
Girl fan wants to find a boyfriend, but it's for
Ant高级-path和fileset
去 OPPO 面试,被问麻了
Mysql database experiment training 5, data query YGGL database query (detailed)
Simple use of tflite
hdu5288(OO’s Sequence)
Shell的正则表达式入门、常规匹配、特殊字符:^、$、.、*、字符区间(中括号):[ ]、特殊字符:\、匹配手机号
Introduction to Matlab real time editor
Understanding of batchnorm2d() function in pytorch
Open3d library installation, CONDA common instructions, importing open3d times this error solving environment: failed with initial frozen solve Retrying w