Python 实现中值滤波、均值滤波的方法
程序员文章站
2022-07-19 13:13:02
红包:
lena椒盐噪声图片:
# -*- coding: utf-8 -*-
"""
created on sat oct 14 22:16:47...
红包:
lena椒盐噪声图片:
# -*- coding: utf-8 -*- """ created on sat oct 14 22:16:47 2017 @author: don """ from tkinter import * from skimage import io import numpy as np im=io.imread('lena_sp.jpg', as_grey=true) im_copy_med = io.imread('lena_sp.jpg', as_grey=true) im_copy_mea = io.imread('lena_sp.jpg', as_grey=true) #io.imshow(im) for i in range(0,im.shape[0]): for j in range(0,im.shape[1]): im_copy_med[i][j]=im[i][j] im_copy_mea[i][j]=im[i][j] #ui root = tk() root.title("lena") root.geometry('300x200') medl = label(root, text="中值滤波:") medl.pack() med_text = stringvar() med = entry(root, textvariable = med_text) med_text.set("") med.pack() meal = label(root, text="均值滤波:") meal.pack() mea_text = stringvar() mea = entry(root, textvariable = mea_text) mea_text.set("") mea.pack() def m_filter(x, y, step): sum_s=[] for k in range(-int(step/2),int(step/2)+1): for m in range(-int(step/2),int(step/2)+1): sum_s.append(im[x+k][y+m]) sum_s.sort() return sum_s[(int(step*step/2)+1)] def mean_filter(x, y, step): sum_s = 0 for k in range(-int(step/2),int(step/2)+1): for m in range(-int(step/2),int(step/2)+1): sum_s += im[x+k][y+m] / (step*step) return sum_s def on_click(): if(med_text): medstep = int(med_text.get()) for i in range(int(medstep/2),im.shape[0]-int(medstep/2)): for j in range(int(medstep/2),im.shape[1]-int(medstep/2)): im_copy_med[i][j] = m_filter(i, j, medstep) if(mea_text): meastep = int(mea_text.get()) for i in range(int(meastep/2),im.shape[0]-int(meastep/2)): for j in range(int(meastep/2),im.shape[1]-int(meastep/2)): im_copy_mea[i][j] = mean_filter(i, j, meastep) io.imshow(im_copy_med) io.imsave(str(medstep) + 'med.jpg', im_copy_med) io.imshow(im_copy_mea) io.imsave(str(meastep) + 'mea.jpg', im_copy_mea) button(root, text="filtergo", command = on_click).pack() root.mainloop()
运行结果截图:
以上这篇python 实现中值滤波、均值滤波的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: 谁能比我糗
推荐阅读
-
AU音频怎么添加滤波效果? au柔和窄小的滤波效果的实现方法
-
图像的灰度化处理(Python实现三种方法——最大值法、平均值法、加权均值法、gamma校正)
-
python-opencv 中值滤波{cv2.medianBlur(src, ksize)}的用法
-
Python 实现中值滤波、均值滤波的方法
-
初学python实现OpenCV之边缘保留滤波:高斯双边、均值迁移
-
python+opencv均值滤波,高斯滤波,中值滤波,双边滤波
-
基于OpenCV+Python的均值滤波,高斯滤波,中值滤波,双边滤波
-
python3 利用opencv 添加中值滤波,均值滤波,高斯滤波,高斯双边滤波
-
【计算机视觉】卷积、均值滤波、高斯滤波、Sobel算子、Prewitt算子(Python实现)
-
基于OpenCV+Python的均值滤波,高斯滤波,中值滤波,双边滤波