Skip to content

Commit

Permalink
Merge pull request #130 from sbrunner/dependabot/pip/scikit-image-0.19.0
Browse files Browse the repository at this point in the history
Bump scikit-image from 0.18.3 to 0.19.0
  • Loading branch information
sbrunner authored Dec 8, 2021
2 parents 5b775b3 + 1a3137d commit ee28a0b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 197 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "pypi"

[packages]
numpy = "==1.21.4"
scikit-image = "==0.18.3"
scikit-image = "==0.19.0"

[dev-packages]
pytest = "==6.2.5"
Expand Down
196 changes: 28 additions & 168 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions deskew/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import numpy as np
from skimage.color import rgb2gray, rgba2rgb
from skimage.feature import canny
from skimage.transform import hough_line, hough_line_peaks

Expand Down Expand Up @@ -55,11 +56,14 @@ def determine_skew_dev(
Tuple[ImageTypeUint64, List[List[np.float64]], ImageTypeFloat64],
]:
"""Calculate skew angle."""
img = image
imagergb = rgba2rgb(image) if len(image.shape) == 3 and image.shape[2] == 4 else image
img = rgb2gray(imagergb) if len(imagergb.shape) == 3 else imagergb
edges = canny(img, sigma=sigma)
out, angles, distances = hough_line(edges, np.linspace(-np.pi / 2, np.pi / 2, num_angles, endpoint=False))

_, angles_peaks, _ = hough_line_peaks(out, angles, distances, num_peaks=num_peaks)
_, angles_peaks, _ = hough_line_peaks(
out, angles, distances, num_peaks=num_peaks, threshold=0.05 * np.max(out)
)

absolute_deviations = [_calculate_deviation(k) for k in angles_peaks]
average_deviation: np.float64 = np.mean(np.rad2deg(absolute_deviations))
Expand Down
15 changes: 0 additions & 15 deletions deskew/plot.py

This file was deleted.

3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ ignore_missing_imports = True

[mypy-skimage.*]
ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True
13 changes: 5 additions & 8 deletions tests/test_deskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
from skimage import io
from skimage.color import rgb2gray

from deskew import determine_skew

Expand All @@ -14,7 +13,7 @@
("2", pytest.approx(-2.0, abs=0.01)),
("3", pytest.approx(-6.0, abs=0.01)),
("4", pytest.approx(7.0, abs=0.01)),
("5", pytest.approx(4.0, abs=0.01)),
("5", pytest.approx(3.0, abs=0.01)),
("6", pytest.approx(-3.0, abs=0.01)),
("7", pytest.approx(3.0, abs=0.01)),
("8", pytest.approx(15.0, abs=0.01)),
Expand All @@ -26,8 +25,7 @@ def test_deskew(image, expected_angle):
os.makedirs(root_folder)

image = io.imread(os.path.join(os.path.dirname(__file__), f"deskew-{image}.png"))
grayscale = rgb2gray(image)
angle = determine_skew(grayscale)
angle = determine_skew(image)
print(angle - expected_angle.expected)
assert angle == expected_angle

Expand All @@ -37,8 +35,8 @@ def test_deskew(image, expected_angle):
[
("1", pytest.approx(-1.4, abs=0.01)),
("2", pytest.approx(-2.1, abs=0.01)),
("3", pytest.approx(-6.2, abs=0.01)),
("4", pytest.approx(7.1, abs=0.01)),
("3", pytest.approx(-6.3, abs=0.01)),
("4", pytest.approx(7.0, abs=0.01)),
("5", pytest.approx(3.4, abs=0.01)),
("6", pytest.approx(-2.8, abs=0.01)),
("7", pytest.approx(3.7, abs=0.01)),
Expand All @@ -51,7 +49,6 @@ def test_deskew_higher_pressision(image, expected_angle):
os.makedirs(root_folder)

image = io.imread(os.path.join(os.path.dirname(__file__), f"deskew-{image}.png"))
grayscale = rgb2gray(image)
angle = determine_skew(grayscale, num_angles=1800)
angle = determine_skew(image, num_angles=1800)
print(angle - expected_angle.expected)
assert angle == expected_angle

0 comments on commit ee28a0b

Please sign in to comment.