Skip to content

Commit

Permalink
feat: version 0.3.0 (#25)
Browse files Browse the repository at this point in the history
* chore: deps upgrade

* chore: deps upgrade

* fix: mypy complains about types

* chore: adds `make fmt`

To run black on all python files.

* test: updates to images

After make test

* feat: bump version to 0.3.0

* ci: Drop python 3.8
  • Loading branch information
dilawar authored Jul 14, 2024
1 parent 0a57b2c commit 5b74dd3
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 868 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Unreleased

# [0.3.0] 2024-07-14

It is a maintenance release. The minimum supported version is 3.9.

- Update to dependencies.

# [0.2.3] 2022-11-06

- Removed loguru. #11
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON := $(shell which python)
POETRY := $(PYTHON) -m poetry
POETRY := poetry

all : test

Expand All @@ -17,3 +17,6 @@ install:

lint:
$(POETRY) run mypy --ignore-missing-imports --install-types --non-interactive plotdigitizer tests

fmt:
black plotdigitizer/* tests/*
Binary file modified figures/ECGImage.result.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 modified figures/graph_with_grid.result.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 modified figures/graphs_1.result.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 modified figures/trimmed.result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions plotdigitizer/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
__email__ = "[email protected]"

from pathlib import Path
import typing as T
import cv2 as cv
import numpy as np
import numpy.typing as npt

import tempfile

Expand Down Expand Up @@ -31,18 +33,21 @@ def heal(orig):


def remove_grid(
orig, num_iter=3, background_color: int = 255, grid_size: int = 2
orig: npt.ArrayLike,
num_iter: int = 3,
background_color: T.Sequence[int] = (255, 255, 255),
grid_size: int = 2,
) -> np.ndarray:
img = orig.copy()
img = np.array(orig, copy=True)
thres = cv.threshold(img, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
# Remove horizontal lines
horizontal_kernel = cv.getStructuringElement(cv.MORPH_RECT, (40, 1))
remove_horizontal = cv.morphologyEx(
thres, cv.MORPH_OPEN, horizontal_kernel, iterations=num_iter
)
cnts = cv.findContours(remove_horizontal, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
contours = cnts[0] if len(cnts) == 2 else cnts[1]
for c in contours:
cv.drawContours(img, [c], -1, background_color, grid_size)

# Remove vertical lines
Expand All @@ -51,8 +56,8 @@ def remove_grid(
thres, cv.MORPH_OPEN, vertical_kernel, iterations=num_iter
)
cnts = cv.findContours(remove_vertical, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
contours = cnts[0] if len(cnts) == 2 else cnts[1]
for c in contours:
cv.drawContours(img, [c], -1, background_color, grid_size)
return img

Expand Down
8 changes: 5 additions & 3 deletions plotdigitizer/plotdigitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
locations_: T.List[geometry.Point] = []
points_: T.List[geometry.Point] = []

img_: np.ndarray = np.zeros((1, 1))
img_: npt.NDArray[np.float64] = np.zeros((1, 1))


def cache() -> Path:
Expand All @@ -52,7 +52,7 @@ def save_img_in_cache(
if filename is None:
filename = Path(f"{data_to_hash(img)}.png")
outpath = cache() / filename
cv.imwrite(str(outpath), img)
cv.imwrite(str(outpath), np.array(img))
logging.debug(f" Saved to {outpath}")


Expand All @@ -66,7 +66,9 @@ def plot_traj(traj, outfile: Path):

for p in locations_:
csize = img_.shape[0] // 40
cv.circle(img_, (p.x, img_.shape[0] - p.y), csize, 128, -1)
cv.circle(
img_, (int(p.x), int(img_.shape[0] - p.y)), int(csize), (128, 128, 128), -1
)

plt.imshow(img_, interpolation="none", cmap="gray")
plt.axis(False)
Expand Down
1,687 changes: 839 additions & 848 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "plotdigitizer"
version = "0.2.3"
version = "0.3.0"
description = "Extract raw data from plots images"
authors = ["Dilawar Singh <[email protected]>"]
maintainers = ["Dilawar Singh <[email protected]>"]
Expand All @@ -9,22 +9,22 @@ repository = "https://github.com/dilawar/PlotDigitizer"
license = "LGPL-3.0-or-later"

[tool.poetry.dependencies]
python = "^3.8"
opencv-python = "^4.5.1"
numpy = "^1.23"
matplotlib = "^3.3.4"
python = ">=3.9,<=4"
opencv-python = "^4.10"
numpy = "^2.0.0"
matplotlib = "^3.9.1"

[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
matplotlib = "^3.4.2"
pytest = "^8.2.2"
matplotlib = "^3.9.1"

[tool.poetry.scripts]
plotdigitizer = 'plotdigitizer.plotdigitizer:main'
plotdigitizer-locate = 'plotdigitizer.locate:main'

[tool.poetry.group.dev.dependencies]
mypy = "^0.982"
pylint = "^2.15.5"
mypy = "^1.10"
pylint = "^3.2.5"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down

0 comments on commit 5b74dd3

Please sign in to comment.