ialdev-img 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/PKG-INFO +4 -4
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/pyproject.toml +5 -4
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/src/iad/img/tools.py +34 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/README.md +0 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/src/iad/img/__init__.py +0 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/src/iad/img/camera.py +0 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/src/iad/img/regions.py +0 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/src/iad/img/transforms.py +0 -0
- {ialdev_img-0.2.2 → ialdev_img-0.2.4}/tests/test_camera.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ialdev-img
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: iad.img — image transforms, regions, and stereo camera models
|
|
5
5
|
Author: ipcoder
|
|
6
6
|
Requires-Python: >=3.10
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: ialdev-core>=0.2.
|
|
9
|
-
Requires-Dist: ialdev-io>=0.2.
|
|
10
|
-
Requires-Dist: ialdev-maths>=0.2.
|
|
8
|
+
Requires-Dist: ialdev-core>=0.2.6
|
|
9
|
+
Requires-Dist: ialdev-io>=0.2.4
|
|
10
|
+
Requires-Dist: ialdev-maths>=0.2.5
|
|
11
11
|
Requires-Dist: numpy>=1.26.4,<2
|
|
12
12
|
Requires-Dist: xxhash>=3.0.0
|
|
13
13
|
Requires-Dist: toolz>=0.11.0
|
|
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ialdev-img"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.4"
|
|
8
8
|
description = "iad.img — image transforms, regions, and stereo camera models"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -13,9 +13,9 @@ authors = [
|
|
|
13
13
|
{name = "ipcoder"}
|
|
14
14
|
]
|
|
15
15
|
dependencies = [
|
|
16
|
-
"ialdev-core>=0.2.
|
|
17
|
-
"ialdev-io>=0.2.
|
|
18
|
-
"ialdev-maths>=0.2.
|
|
16
|
+
"ialdev-core>=0.2.6",
|
|
17
|
+
"ialdev-io>=0.2.4",
|
|
18
|
+
"ialdev-maths>=0.2.5",
|
|
19
19
|
"numpy>=1.26.4,<2",
|
|
20
20
|
"xxhash>=3.0.0",
|
|
21
21
|
"toolz>=0.11.0",
|
|
@@ -34,5 +34,6 @@ name = "iad.img"
|
|
|
34
34
|
|
|
35
35
|
[tool.pytest.ini_options]
|
|
36
36
|
testpaths = ["tests"]
|
|
37
|
+
addopts = "--import-mode=importlib"
|
|
37
38
|
python_files = ["test_*.py"]
|
|
38
39
|
pythonpath = ["src"]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from typing import Literal
|
|
1
2
|
import numpy as np
|
|
2
3
|
|
|
3
4
|
from .regions import Regions
|
|
@@ -62,6 +63,39 @@ def crop(im, rect):
|
|
|
62
63
|
new_im[trg] = im[src]
|
|
63
64
|
return new_im
|
|
64
65
|
|
|
66
|
+
def resize(im: np.ndarray, *, width: int, height: int,
|
|
67
|
+
keep_pixel_ratio: Literal['pad', 'crop', 'no']='no', interp: str = 'bilinear') -> np.ndarray:
|
|
68
|
+
"""Resize image (2D or 3D array) to given width and height using the given interpolation method.
|
|
69
|
+
|
|
70
|
+
If resizing requires breaking the pixel aspect ratio, and keep_pixel_ratio != 'no', keep pixel ratio by:
|
|
71
|
+
- 'pad': pad the image with zeros to the new aspect ratio
|
|
72
|
+
- 'crop': center-crop the image to the new aspect ratio
|
|
73
|
+
Implement resizing using skimage.transform.resize with the given interpolation method.
|
|
74
|
+
|
|
75
|
+
:param im: input image
|
|
76
|
+
:param width: new width
|
|
77
|
+
:param height: new height
|
|
78
|
+
:param keep_pixel_ratio: 'pad' | 'crop' | 'no' (case insensitive)
|
|
79
|
+
:param interp: interpolation method (case insensitive)
|
|
80
|
+
:return: resized image
|
|
81
|
+
"""
|
|
82
|
+
from skimage.transform import resize as sk_resize
|
|
83
|
+
|
|
84
|
+
order = {'nearest': 0, 'bilinear': 1, 'linear': 1, 'bicubic': 3, 'cubic': 3}[interp.lower()]
|
|
85
|
+
h, w = im.shape[:2]
|
|
86
|
+
target_h, target_w = round(w * height / width), round(h * width / height)
|
|
87
|
+
mode = keep_pixel_ratio.lower()
|
|
88
|
+
if mode == 'pad' and (target_h > h or target_w > w):
|
|
89
|
+
dh, dw = max(0, target_h - h), max(0, target_w - w)
|
|
90
|
+
pads = [(dh // 2, dh - dh // 2), (dw // 2, dw - dw // 2)] + [(0, 0)] * (im.ndim - 2)
|
|
91
|
+
im = np.pad(im, pads)
|
|
92
|
+
elif mode == 'crop' and (target_h < h or target_w < w):
|
|
93
|
+
im = center_crop(im, min(w, target_w), min(h, target_h))
|
|
94
|
+
|
|
95
|
+
out_shape = (height, width) + im.shape[2:]
|
|
96
|
+
resized = sk_resize(im, out_shape, order=order, preserve_range=True, anti_aliasing=(order > 0))
|
|
97
|
+
return resized.astype(im.dtype, copy=False)
|
|
98
|
+
|
|
65
99
|
|
|
66
100
|
def image_2D(im: np.ndarray):
|
|
67
101
|
"""Squeeze dimensions or collapse colors to produce 2D image"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|