图像处理-从频率角度分析中值滤波

1.均值滤波

对于中值滤波器,就是设定一定大小的核,计算核包含的像素点对应的中值。
m e d i a n [ a 11 a 12 ⋯ a 1 n a 21 a 22 ⋯ a 2 n ⋮ ⋮ ⋱ ⋮ a m 1 a m 2 ⋯ a m n ] median{\begin{bmatrix} {a_{11}}&{a_{12}}&{\cdots}&{a_{1n}}\\ {a_{21}}&{a_{22}}&{\cdots}&{a_{2n}}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {a_{m1}}&{a_{m2}}&{\cdots}&{a_{mn}}\\ \end{bmatrix} } mediana11a21am1a12a22am2a1na2namn
那么对应的中值滤波核如下所示:
F i l t e r = m e d i a n × A Filter=median\times A Filter=median×A

2.代码

import numpy as np
from skimage import io
import cv2
from matplotlib import pyplot as plt
path = "D:/2_project/0_test/median_filter/anr/input/inputfull.jpg"
I = io.imread(path) #R*0.299+G*0.587+B*0.114
def medianfilter(image, winsize):
    rows, cols, channel = image.shape
    winH, winW = winsize
    halfwinH = (winH-1)//2 +1
    halfwinW = (winW-1)//2 +1
    medianfilterimage = np.zeros(image.shape, image.dtype)
    for k in range(channel):
        for i in range(rows):
            for j in range(cols):
                rtop = 0 if i-halfwinH < 0 else i - halfwinH
                rbootom = rows-1 if i + halfwinH > rows -1 else i + halfwinH
                cleft = 0 if j - halfwinW < 0 else j - halfwinW
                cright = cols-1 if j + halfwinW > cols -1 else j + halfwinW
                region = image[rtop:rbootom+1, cleft:cright+1, k]
                medianfilterimage[i][j][k] = np.median(region)
    return medianfilterimage
window = (9, 9)
output = medianfilter(I, window)

3.Kernel 大小分析

不同大小的核对图像进行滤波得到的图像信息不同,随着核的大小的增大,计算的像素点越多,也就意味着滤波后的图像包含了更多的低频信息,这样,随着核大小的增大,高频信息丢失。
对不同大小的图像进行中值滤波,图2是图1缩放四倍,图3是图1缩放16倍。
以下是不同大小的核(包括size=3和size=9)中值滤波后的图像:
图1
图2
图3

4.对比均值滤波和中值滤波

图4
图5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值