numpyimage 2.8.0__tar.gz → 3.0.0__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.
Files changed (26) hide show
  1. numpyimage-3.0.0/LICENSE +21 -0
  2. numpyimage-3.0.0/PKG-INFO +87 -0
  3. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/utils.py +20 -3
  4. numpyimage-3.0.0/npimage/vidio.py +866 -0
  5. numpyimage-3.0.0/numpyimage.egg-info/PKG-INFO +87 -0
  6. {numpyimage-2.8.0 → numpyimage-3.0.0}/numpyimage.egg-info/SOURCES.txt +1 -1
  7. {numpyimage-2.8.0 → numpyimage-3.0.0}/pyproject.toml +2 -2
  8. numpyimage-3.0.0/tests/test_video_writers.py +170 -0
  9. numpyimage-2.8.0/LICENSE +0 -674
  10. numpyimage-2.8.0/PKG-INFO +0 -740
  11. numpyimage-2.8.0/npimage/vidio.py +0 -651
  12. numpyimage-2.8.0/numpyimage.egg-info/PKG-INFO +0 -740
  13. numpyimage-2.8.0/tests/test_video.py +0 -31
  14. {numpyimage-2.8.0 → numpyimage-3.0.0}/README.md +0 -0
  15. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/__init__.py +0 -0
  16. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/align.py +0 -0
  17. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/graphics.py +0 -0
  18. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/imageio.py +0 -0
  19. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/nrrd_utils.py +0 -0
  20. {numpyimage-2.8.0 → numpyimage-3.0.0}/npimage/operations.py +0 -0
  21. {numpyimage-2.8.0 → numpyimage-3.0.0}/numpyimage.egg-info/dependency_links.txt +0 -0
  22. {numpyimage-2.8.0 → numpyimage-3.0.0}/numpyimage.egg-info/requires.txt +0 -0
  23. {numpyimage-2.8.0 → numpyimage-3.0.0}/numpyimage.egg-info/top_level.txt +0 -0
  24. {numpyimage-2.8.0 → numpyimage-3.0.0}/setup.cfg +0 -0
  25. {numpyimage-2.8.0 → numpyimage-3.0.0}/tests/test_heic.py +0 -0
  26. {numpyimage-2.8.0 → numpyimage-3.0.0}/tests/test_pbm.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jasper Phelps
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.4
2
+ Name: numpyimage
3
+ Version: 3.0.0
4
+ Summary: Load, save, & manipulate image files as numpy arrays
5
+ Author-email: Jasper Phelps <jasper.s.phelps@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Jasper Phelps
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Repository, https://github.com/jasper-tms/npimage
29
+ Keywords: images,pixel arrays,image formats,convert,graphics,draw simple shapes
30
+ Classifier: Programming Language :: Python :: 3
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Development Status :: 5 - Production/Stable
34
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
35
+ Requires-Python: >=3.6
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: numpy
39
+ Requires-Dist: pillow
40
+ Requires-Dist: pillow-heif
41
+ Requires-Dist: tifffile
42
+ Requires-Dist: pynrrd
43
+ Requires-Dist: matplotlib
44
+ Requires-Dist: opencv-python-headless
45
+ Provides-Extra: all
46
+ Requires-Dist: tqdm; extra == "all"
47
+ Requires-Dist: av; extra == "all"
48
+ Dynamic: license-file
49
+
50
+ # npimage
51
+ Need to load pixel values from image files as numpy arrays, and hate having to remember whether you should use PIL, tifffile, matplotlib, or something else? Hate having to deal with the fact that those libraries all use different function names and syntaxes? Wish you could just provide a filename and get back a numpy array? This library's `imageio.py` does that, with `array = npimage.load(filename)`, `npimage.save(array, filename)`, and `npimage.show(array)` functions that let you easily handle a number of common image file formats without having to remember library-specific syntax. Additionally, `vidio.py` provides `array = npimage.load_video(filename)` and `npimage.save_video(array, filename)` for videos as well. (Another similar library to consider using is [imageio](https://pypi.org/project/imageio/).)
52
+
53
+ Want to draw simple shapes like lines, triangles, and circles into 3D numpy arrays? Frustrated that the python libraries you can find online like `opencv` and `skimage.draw` work on 2D arrays but not 3D? I wrote some functions in `graphics.py` that do the trick in 3D. (If you know of another library that can do this, please let me know!)
54
+
55
+
56
+ ### Documentation
57
+ - `imageio.py`: load, save, or show images.
58
+ - `vidio.py`: load or save videos.
59
+ - `graphics.py`: draw points, lines, triangles, circles, or spheres into 2D or 3D numpy arrays representing image volumes.
60
+ - `nrrd_utils.py`: compress or read metadata from `.nrrd` files.
61
+ - `operations.py`: perform operations on images.
62
+
63
+ Check each function's docstring for more details.
64
+
65
+
66
+ ### Installation
67
+
68
+ As is always the case in python, consider making a virtual environment (using your preference of conda, virtualenv, or virtualenvwrapper) before installing.
69
+
70
+ **Option 1:** `pip install` from PyPI:
71
+
72
+ pip install numpyimage
73
+
74
+ (Unfortunately the name `npimage` was already taken on PyPI, so `pip install npimage` will get you a different package.)
75
+
76
+ **Option 2:** `pip install` directly from GitHub:
77
+
78
+ pip install git+https://github.com/jasper-tms/npimage.git
79
+
80
+ **Option 3:** First `git clone` this repo and then `pip install` it from your clone:
81
+
82
+ cd ~/repos # Or wherever on your computer you want to download this code to
83
+ git clone https://github.com/jasper-tms/npimage.git
84
+ cd npimage
85
+ pip install .
86
+
87
+ **After installing,** you can import this package in python using `import npimage` (not `import numpyimage`!)
@@ -11,8 +11,9 @@ Function list:
11
11
  - transpose_metadata (reverse the order of all per-axis metadata values)
12
12
  """
13
13
 
14
- from typing import Union
14
+ from typing import Union, Optional
15
15
  from collections import OrderedDict
16
+ from fractions import Fraction
16
17
 
17
18
  import numpy as np
18
19
 
@@ -111,8 +112,8 @@ def find_channel_axis(data,
111
112
  return None
112
113
 
113
114
 
114
- def transpose_metadata(metadata: dict or OrderedDict,
115
- inplace: bool = True) -> dict or OrderedDict or None:
115
+ def transpose_metadata(metadata: Union[dict, OrderedDict],
116
+ inplace: bool = True) -> Optional[Union[dict, OrderedDict]]:
116
117
  """
117
118
  Reverse the order of all metadata values that have a separate entry
118
119
  for each axis of the data.
@@ -202,3 +203,19 @@ def remove_out_of_bounds(coords, shape, allow_negative_wrapping=False,
202
203
  convention='corner'):
203
204
  in_bounds = is_in_bounds(coords, shape, allow_negative_wrapping, convention)
204
205
  return coords[in_bounds]
206
+
207
+
208
+ def limit_fraction(fraction: Union[Fraction, float], to: int = 2**31) -> Fraction:
209
+ """
210
+ Limit a Fraction to ensure both numerator and denominator are smaller than a given value.
211
+
212
+ This is useful for ensuring compatibility with FFmpeg, which expresses framerates
213
+ as ratios of two 32-bit signed integers.
214
+ """
215
+ fraction = Fraction(fraction)
216
+ new_fraction = fraction
217
+ limit = to
218
+ while abs(new_fraction.numerator) >= to or abs(new_fraction.denominator) >= to:
219
+ new_fraction = fraction.limit_denominator(limit)
220
+ limit = limit // 2
221
+ return new_fraction