Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spatial-temporal-denoising-B/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
局部降噪B组

conda env create --file environment.yml

conda install --file requirements.txt -y

pip install -e .

测试方法:
pytest --cov-report=html --cov=temporal_denoising --ignore=temporal_denoising.py test_denoising.py
根据输出的html可知覆盖率达到100%
不过依旧是个很简单的实现
还有待进一步优化
有一些备用图像可以测试看看
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spatial-temporal-denoising-B/backup_images/90.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spatial-temporal-denoising-B/cover_rate.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spatial-temporal-denoising-B/result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spatial-temporal-denoising-B/source.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions spatial-temporal-denoising-B/temporal_denoising.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#coding:utf-8
#测试用库
import unittest

import sys,os
from PIL import Image,ImageDraw

#使用二值判断方法,如果确认是噪声,用该点周围灰度的均值进行替换
def getPixel(image,x,y,G,N):
L = image.getpixel((x,y))
if L > G:
L = True
else:
L = False

nearDots = 0
if L == (image.getpixel((x - 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y + 1)) > G):
nearDots += 1
if nearDots < N:
a = (image.getpixel((x - 1,y - 1)) +
image.getpixel((x - 1,y)) +
image.getpixel((x - 1,y + 1)) +
image.getpixel((x,y - 1)) +
image.getpixel((x,y + 1)) +
image.getpixel((x + 1,y - 1)) +
image.getpixel((x + 1,y)) +
image.getpixel((x + 1,y + 1)))/8
return int(a)
# return image.getpixel((x,y-1))
else:
return None

# 根据一个点A的灰度值,与周围的8个点的灰度值比较,设定一个值N(0 <N <8),当A的灰度值与周围8个点的灰度相等数小于N时,此点为噪点
# G:图像二值化阀值
# N:降噪率 0 <N <8
# Z:降噪次数

def deNoise(image,G,N,Z):
draw = ImageDraw.Draw(image)
for i in range(0,Z):
for x in range(1,image.size[0] - 1):
for y in range(1,image.size[1] - 1):
color = getPixel(image,x,y,G,N)
if color != None:
draw.point((x,y),color)

# 测试段1
def main():

#打开图片
image = Image.open("./source.jpg")

#将图片转换成灰度图片
image1 = image.convert("L")

#去噪,G = 50,N = 4,Z = 4
deNoise(image1,50,4,4)

#保存图片
image1.save("./result.jpg")
print(image.size[0])
print(image.size[1])
print(image1.size[0])
print(image1.size[1])
print("done")

Binary file added spatial-temporal-denoising-B/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions spatial-temporal-denoising-B/test_denoising.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#测试用库
import unittest

import temporal_denoising as td
import sys,os
from PIL import Image,ImageDraw

#测试代码
class Test_denoising(unittest.TestCase):
def test_denoising(self):
#先按照源代码自带的main函数生成一个结果图像result.jpg
td.main()
#测试段2:再次生成一个图像test.jpg以供比较
image_source = Image.open("./source.jpg")
image_source = image_source.convert("L")
image_result = Image.open("./result.jpg")
image_result = image_result.convert("L")
td.deNoise(image_source,50,4,4)
image_source.save("./test.jpg")
image_test = Image.open("./test.jpg")
for x in range(1,image_source.size[0] - 1):
for y in range(1,image_source.size[1] - 1):
self.assertEqual(image_test.getpixel((x,y)),image_result.getpixel((x,y)))