您好,登錄后才能下訂單哦!
小編給大家分享一下Python怎么實(shí)現(xiàn)中值濾波、均值濾波,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
python常用的庫(kù):1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。
紅包:
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()
運(yùn)行結(jié)果截圖:
以上是“Python怎么實(shí)現(xiàn)中值濾波、均值濾波”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。