GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

test_fail_tau_2d_hard_param()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
1
#!/usr/bin/env python
2
# coding=utf-8
3
"""Tests for BM3D image denoising."""
4
5
import pytest
6
import numpy as np
7
import skimage.data
8
from skimage.measure import compare_psnr
9
10
import pybm3d
11
12
13
@pytest.fixture
14
def noise_data():
15
    """Provide grayscale data for denoising."""
16
    noise_std_dev = 40.0
17
    img = skimage.data.camera()
18
19
    noise = np.random.normal(0, noise_std_dev, img.shape).astype(img.dtype)
20
    noisy_img = np.clip(img + noise, 0, 255)
21
    return img, noisy_img, noise_std_dev
22
23
24
@pytest.fixture
25
def color_noise_data():
26
    """Provide color data for denoising."""
27
    noise_std_dev = 40.0
28
    img = skimage.data.astronaut()
29
30
    noise = np.random.normal(0, noise_std_dev, img.shape).astype(img.dtype)
31
    noisy_img = np.clip(img + noise, 0, 255)
32
    return img, noisy_img, noise_std_dev
33
34
35
def test_import():
36
    """Tests for BM3D function availability."""
37
    import pybm3d
38
    assert callable(pybm3d.bm3d.bm3d)
39
40
41
def test_bm3d(noise_data):
42
    """Tests BM3D grayscale image denoising."""
43
    img, noisy_img, noise_std_dev = noise_data
44
45
    out = pybm3d.bm3d.bm3d(noisy_img, noise_std_dev)
46
47
    noise_psnr = compare_psnr(img, noisy_img)
48
    out_psnr = compare_psnr(img, out)
49
50
    assert out_psnr > noise_psnr
51
52
53
def test_bm3d_color(color_noise_data):
54
    """Tests BM3D color image denoising."""
55
    img, noisy_img, noise_std_dev = color_noise_data
56
57
    out = pybm3d.bm3d.bm3d(noisy_img, noise_std_dev)
58
59
    noise_psnr = compare_psnr(img, noisy_img)
60
    out_psnr = compare_psnr(img, out)
61
62
    assert out_psnr > noise_psnr
63
64
65
def test_fail_patch_size_param(noise_data):
66
    """Tests expected failure for wrong patch_size parameter value."""
67
    _, noisy_img, noise_std_dev = noise_data
68
69
    with pytest.raises(ValueError):
70
        pybm3d.bm3d.bm3d(noisy_img, noise_std_dev, patch_size=-1)
71
72
73
def test_fail_tau_2d_hard_param(noise_data):
74
    """Tests expected failure for wrong tau_2D_hard parameter value."""
75
    _, noisy_img, noise_std_dev = noise_data
76
77
    with pytest.raises(ValueError):
78
        pybm3d.bm3d.bm3d(noisy_img, noise_std_dev, tau_2D_hard="not_supported")
79
80
81
def test_fail_tau_2d_wien_param(noise_data):
82
    """Tests expected failure for wrong tau_2D_wien parameter value."""
83
    _, noisy_img, noise_std_dev = noise_data
84
85
    with pytest.raises(ValueError):
86
        pybm3d.bm3d.bm3d(noisy_img, noise_std_dev, tau_2D_wien="not_supported")
87
88
89
def test_fail_color_space_param(noise_data):
90
    """Tests expected failure for wrong tau_2D_wien parameter value."""
91
    _, noisy_img, noise_std_dev = noise_data
92
93
    with pytest.raises(ValueError):
94
        pybm3d.bm3d.bm3d(noisy_img, noise_std_dev, color_space="not_supported")
95