Skip to content

Commit e916b89

Browse files
committed
👷 add black formatter and CI hook
1 parent 90e7275 commit e916b89

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

Diff for: .github/workflows/black.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-python@v2
11+
- uses: psf/black@stable

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,5 @@ img/output/
163163
*.mtc1
164164
*.out
165165
*.synctex.gz
166+
167+
.vscode/

Diff for: .pre-commit-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/psf/black
5+
rev: 19.10b0 # Replace by any tag/version: https://github.com/psf/black/tags
6+
hooks:
7+
- id: black
8+
language_version: python
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v2.0.0
11+
hooks:
12+
- id: flake8

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
21
<h1 align="center">Quantization - team project</h1>
32

3+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4+
45
## Development
56

67
1. Create virtual environment with `virtualenv .venv`.

Diff for: pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.black]
2+
line-length = 119
3+
target-version = ['py37']
4+
include = '\.pyi?$'

Diff for: vector_quantization/image_noiser.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
import numpy as np
33
import math
44

5-
def PSNR(original, compressed):
6-
mse = np.mean((original - compressed) ** 2)
7-
if(mse == 0): # MSE is zero means no noise is present in the signal .
8-
# Therefore PSNR have no importance.
5+
6+
def PSNR(original, compressed):
7+
mse = np.mean((original - compressed) ** 2)
8+
if mse == 0: # MSE is zero means no noise is present in the signal .
9+
# Therefore PSNR have no importance.
910
return 100
1011
max_pixel = 255.0
11-
psnr = 20 * math.log10(max_pixel / math.sqrt(mse))
12-
return psnr
12+
psnr = 20 * math.log10(max_pixel / math.sqrt(mse))
13+
return psnr
14+
1315

14-
img = Image.open('../img/input/balloon.bmp')
16+
img = Image.open("./img/input/balloon.bmp")
1517

1618
img_arr = np.array(img)
17-
img_arr_noise = img_arr & 254
19+
img_arr_noise = img_arr & 254
1820

1921
img_noise = Image.fromarray(img_arr_noise)
20-
img_noise.save("../img/input/balloon_noise.bmp")
22+
img_noise.save("./img/input/balloon_noise.bmp")
2123

2224
print(f"PSNR: {PSNR(img_arr, img_arr_noise)}")
23-

0 commit comments

Comments
 (0)