• matlab-均值滤波


    均值滤波

    主要思想为邻域平均法,即用几个像素灰度的平均值来代替每个像素的灰度。有效抑制加性噪声。
    缺点:容易引起图像模糊,可以对其进行改进,主要避开对景物边缘的平滑处理。

    均值滤波器的缺点是存在着边缘模糊的问题。对椒盐噪声不起作用

     P5 = (P1+P2+P3+P4+P5+P6+P7+P8+P9)/9

     P5 = (P1+P2+P3+P4+P6+P7+P8+P9)/8   方便在硬件上做运算 >>3

    matlab代码

     1 clc
     2 clear
     3 clear all 
     4 close all
     5 %%%对图像做均值滤波处理
     6 img = imread('1.png');
     7 figure(1)
     8 subplot(2,2,1),imshow(img),title('原始图像')
     9 %%%将彩色图像转灰度图像
    10 img_gray = rgb2gray(img);
    11 subplot(2,2,2),imshow(img_gray),title('RGB-GRAY灰度图像')
    12 %%%加入椒盐噪声
    13 img_salt=imnoise(img_gray,'salt & pepper',0.05);
    14 subplot(2,2,3),imshow(img_salt),title('加入椒盐噪声后')
    15 %%%系统自带的均值滤波  系统自带的均值滤波输入参数为2维图像
    16 img_mid=filter2(fspecial('average',3),img_salt)/255;
    17 subplot(2,2,4),imshow(img_mid),title('对噪声图像均值滤波后');

    Mean_Img = img_salt;
    [ROW,COL]= size(Mean_Img);
    for r = 2:1:ROW-1
    for c = 2:1:COL-1
    Mean_Img(r,c) = (img_salt(r-1, c-1) + img_salt(r-1, c) + img_salt(r-1, c+1) + img_salt(r, c-1) + img_salt(r, c) + img_salt(r, c+1) + img_salt(r+1, c-1) + img_salt(r+1, c) + img_salt(r+1, c+1)) / 9;
    end
    end
    figure(2)
    imshow(img_mid),title('对噪声图像均值滤波后');

  • 相关阅读:
    SVN中建立项目
    Dojo 学习笔记 之 Dojo hitch&partial
    Javascript的“上下文”(context)
    栅格那点儿事(四E)
    栅格那点儿事(四D)
    栅格那点儿事(四C)
    Sqoop Import数据库时中文乱码解决方案
    Sqoop架构
    Sqoop环境安装
    Sqoop概述
  • 原文地址:https://www.cnblogs.com/wanglinwensi/p/12837719.html
Copyright © 2020-2023  润新知