Last active
April 1, 2019 05:36
-
-
Save enzoftware/80e5e6a2ba1ef0172f806e838101606e to your computer and use it in GitHub Desktop.
Median filter in python 🐍
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
path = "noise.png" # Your image path | |
img = Image.open(path) | |
members = [(0,0)] * 9 | |
newimg = Image.new("RGB",(width,height),"white") | |
for i in range(1,width-1): | |
for j in range(1,height-1): | |
members[0] = img.getpixel((i-1,j-1)) | |
members[1] = img.getpixel((i-1,j)) | |
members[2] = img.getpixel((i-1,j+1)) | |
members[3] = img.getpixel((i,j-1)) | |
members[4] = img.getpixel((i,j)) | |
members[5] = img.getpixel((i,j+1)) | |
members[6] = img.getpixel((i+1,j-1)) | |
members[7] = img.getpixel((i+1,j)) | |
members[8] = img.getpixel((i+1,j+1)) | |
members.sort() | |
newimg.putpixel((i,j),(members[4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
width and height are not defined in your code
you need to add