mergechannels 0.1.1__cp313-cp313t-musllinux_1_2_armv7l.whl

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.

Potentially problematic release.


This version of mergechannels might be problematic. Click here for more details.

@@ -0,0 +1,13 @@
1
+ # Import Rust functions
2
+ from .mergechannels import ( # type: ignore
3
+ apply_color_map,
4
+ apply_colors_and_merge_nc,
5
+ )
6
+
7
+ from ._internal import merge
8
+
9
+ __all__ = [
10
+ 'apply_color_map',
11
+ 'apply_colors_and_merge_nc',
12
+ 'merge',
13
+ ]
@@ -0,0 +1,27 @@
1
+ from typing import Sequence, Literal
2
+
3
+ import numpy as np
4
+
5
+ from ._luts import COLORMAPS
6
+ from ._blending import BLENDING_OPTIONS
7
+
8
+ def merge(
9
+ arrs: Sequence[np.ndarray],
10
+ colors: Sequence[COLORMAPS] = (),
11
+ blending: Literal[BLENDING_OPTIONS] = 'max',
12
+ saturation_limits: tuple[float, float] = (0.2, 99.8),
13
+ ) -> np.ndarray:
14
+ ...
15
+
16
+ def apply_color_map(
17
+ arr: np.ndarray,
18
+ cmap_name: COLORMAPS,
19
+ saturation_limits: tuple[float, float] = (0.2, 99.8),
20
+ ) -> np.ndarray: ...
21
+
22
+ def apply_colors_and_merge_nc(
23
+ arrs: Sequence[np.ndarray],
24
+ colors: Sequence[COLORMAPS] = (),
25
+ blending: Literal[BLENDING_OPTIONS] = 'max',
26
+ saturation_limits: Sequence[tuple[float, float]] = (),
27
+ ) -> np.ndarray: ...
@@ -0,0 +1,3 @@
1
+ from typing import Literal
2
+
3
+ BLENDING_OPTIONS = Literal['max', 'sum', 'mean', 'min']
@@ -0,0 +1,47 @@
1
+ from typing import Sequence
2
+
3
+ import numpy as np
4
+
5
+ from mergechannels import (
6
+ apply_color_map,
7
+ apply_colors_and_merge_nc,
8
+ )
9
+ from ._luts import COLORMAPS
10
+ from ._blending import BLENDING_OPTIONS
11
+
12
+ def merge(
13
+ arrs: Sequence[np.ndarray],
14
+ colors: Sequence[COLORMAPS],
15
+ blending: BLENDING_OPTIONS = 'max',
16
+ ) -> np.ndarray:
17
+ '''
18
+ apply cmaps to arrays and blend the colors
19
+ '''
20
+ # region validation
21
+ n_arrs = len(arrs)
22
+ n_colors = len(colors)
23
+ if not n_arrs == n_colors and n_arrs > 0:
24
+ raise ValueError(
25
+ 'Expected an equal number of arrays to colorize and colormap names to apply. '
26
+ f'Got {n_arrs} arrays and {n_colors} colors'
27
+ )
28
+ arr_shapes = [arr.shape for arr in arrs]
29
+ if not len(set(arr_shapes)) == 1:
30
+ raise ValueError(
31
+ f'Expected every array to have the same shape, got {arr_shapes}'
32
+ )
33
+ if not len(arr_shapes[0]) == 2:
34
+ raise ValueError(
35
+ f'Expected every array to be 2D, got {arr_shapes[0]}'
36
+ )
37
+ arr_dtypes = [arr.dtype for arr in arrs]
38
+ if not len(set(arr_dtypes)) == 1:
39
+ raise ValueError(
40
+ f'Expected every array to have the same dtype, got {arr_dtypes}'
41
+ )
42
+ # endregion
43
+
44
+ if n_arrs == 1:
45
+ return apply_color_map(arr=arrs[0], cmap_name=colors[0])
46
+ else:
47
+ return apply_colors_and_merge_nc(arrs, colors, blending)
mergechannels/_luts.py ADDED
@@ -0,0 +1,81 @@
1
+ from typing import Literal
2
+
3
+ COLORMAPS = Literal[
4
+ 'Rainbow RGB',
5
+ '3color-RMB',
6
+ 'Red Hot',
7
+ 'Yellow',
8
+ 'betterRed',
9
+ 'blue_orange_icb',
10
+ 'mpl-inferno',
11
+ 'I Blue',
12
+ 'BOP purple',
13
+ 'betterOrange',
14
+ 'Blue',
15
+ '6_shades',
16
+ 'OIMB3',
17
+ 'Red/Green',
18
+ 'Turbo',
19
+ 'mpl-viridis',
20
+ 'smart',
21
+ 'Thermal',
22
+ 'OIMB2',
23
+ 'glow',
24
+ 'OPF orange',
25
+ 'physics',
26
+ 'OIMB1',
27
+ 'betterCyan',
28
+ 'mpl-magma',
29
+ 'edges',
30
+ 'OPF purple',
31
+ 'I Yellow',
32
+ '16_colors',
33
+ 'sepia',
34
+ 'ICA2',
35
+ 'I Forest',
36
+ 'ICA3',
37
+ 'BOP orange',
38
+ 'I Red',
39
+ '3color-CGY',
40
+ 'I Green',
41
+ 'Fire',
42
+ 'Magenta Hot',
43
+ 'Orange Hot',
44
+ 'unionjack',
45
+ 'I Cyan',
46
+ 'Cyan Hot',
47
+ 'I Magenta',
48
+ 'Grays',
49
+ 'Cyan',
50
+ 'phase',
51
+ 'gem',
52
+ 'OPF fresh',
53
+ 'betterGreen',
54
+ '3color-BMR',
55
+ 'betterBlue',
56
+ 'Magenta',
57
+ 'Red',
58
+ 'I Bordeaux',
59
+ 'glasbey',
60
+ 'glasbey_on_dark',
61
+ 'mpl-plasma',
62
+ '3color-YGC',
63
+ 'Green',
64
+ 'ICA',
65
+ 'Yellow Hot',
66
+ 'thallium',
67
+ 'Spectrum',
68
+ 'royal',
69
+ 'glasbey_inverted',
70
+ 'betterYellow',
71
+ 'HiLo',
72
+ 'cool',
73
+ 'Green Fire Blue',
74
+ 'BOP blue',
75
+ 'thal',
76
+ 'Ice',
77
+ 'brgbcmyw',
78
+ 'I Purple',
79
+ '3-3-2 RGB',
80
+ '5_ramps',
81
+ ]
mergechannels/py.typed ADDED
File without changes
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: mergechannels
3
+ Version: 0.1.1
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: numpy>1.25.0
15
+ License-File: LICENSE
16
+ License: MIT
17
+ Requires-Python: >=3.9, <=3.13
18
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
19
+
20
+ [![CI](https://github.com/zacswider/mergechannels/actions/workflows/CI.yml/badge.svg)](https://github.com/zacswider/mergechannels/actions/workflows/CI.yml)
21
+ ![PyPI - License](https://img.shields.io/pypi/l/mergechannels)
22
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mergechannels)
23
+ ![PyPI](https://img.shields.io/pypi/v/mergechannels)
24
+
25
+ # mergechannels
26
+
27
+ This project was originally conceived because I often find myself wanting to apply and blend colormaps to images while working from Python, and for historical reasons many of my favorite colormaps are distributed as [FIJI](https://imagej.net/software/fiji/) lookup tables. I also care about things likes speed and memory usage (e.g., not casting large arrays to floating point dtypes, not creating multiple whole arrays just to add them together), so I was interested in seeing if I could at least match matplotlib's colormapping performance with my own hand-rolled colorizer in Rust.
28
+
29
+
30
+
31
+ ## Installation
32
+
33
+ Install pre-compiled binaries from [PyPI](https://pypi.org/project/mergechannels/):
34
+ ```bash
35
+ pip install mergechannels
36
+ ```
37
+
38
+ Build from source on your own machine:
39
+ ```bash
40
+ pip install git+https://github.com/zacswider/mergechannels.git
41
+ ```
42
+
43
+ ## Usage
44
+ *NOTE*: scikit-image is not a dependency of this project, but is used in the examples below to fetch images.
45
+
46
+ ### colorize a single image
47
+
48
+ ```python
49
+ from skimage import data
50
+ import mergechannels as mc
51
+
52
+ img = data.camera()
53
+ colorized = mc.apply_color_map(img, 'Red/Green')
54
+ fig, axes = plt.subplots(1, 2, figsize=(6, 3), dpi=150)
55
+ for ax in axes: ax.axis('off')
56
+ (a, b) = axes
57
+ a.imshow(img, cmap='gray')
58
+ b.imshow(colorized)
59
+ plt.show()
60
+ print(colorized.shape, colorized.dtype)
61
+ >> (512, 512, 3) uint8
62
+ ```
63
+ ![colorize a single image](https://raw.githubusercontent.com/zacswider/README_Images/main/camera_red-green.png
64
+ )
65
+
66
+
67
+ ### apply a different colormap to each channel
68
+ ```python
69
+ from skimage import data
70
+ import matplotlib.pyplot as plt
71
+ import mergechannels as mc
72
+
73
+ cells, nuclei = data.cells3d().max(axis=0)
74
+ cells = to_uint8(cells) # normalize your own arrays, mergechannels doesn't currently handle this
75
+ nuclei = to_uint8(nuclei) # normalize your own arrays, mergechannels doesn't currently handle this
76
+
77
+ fig, axes = plt.subplots(2, 2, figsize=(6, 6), dpi=150)
78
+ for ax in axes.ravel(): ax.axis('off')
79
+ (a, b, c, d) = axes.ravel()
80
+ a.imshow(cells, cmap='gray')
81
+ b.imshow(nuclei, cmap='gray')
82
+ c.imshow(
83
+ mc.merge(
84
+ [cells, nuclei],
85
+ ['Orange Hot', 'Cyan Hot'], # maximum blending is the default
86
+ ),
87
+ )
88
+ d.imshow(
89
+ mc.merge(
90
+ [cells, nuclei],
91
+ ['I Blue', 'I Forest'],
92
+ blending='min', # use minimum blending with inverted colormaps
93
+ ),
94
+ )
95
+ fig.tight_layout()
96
+ plt.show()
97
+ ```
98
+ ![max and min multicolor blending](https://raw.githubusercontent.com/zacswider/README_Images/main/cells_multicolor.png)
99
+
100
+
101
+ ## Roadmap
102
+ mergechannels is currently incredibly simple. It can apply one or more colormaps to one or more 2D 8-bit images and that's it.
103
+ - Add support for any numerical dtype
104
+ - Add support for 3D images
105
+ - Add option to return any colormap as a matplotlib colormap
106
+ - Add support for directly passing matplotlib colormaps instead of colormap names
107
+ - Parallelize colormap application on large images (if it's helpful)
108
+ - Add option to overlay binary or instance masks onto colorized images
109
+
110
+ ## Acknowledgements
111
+
112
+ There are other great colormapping libraries available (e.g., [microfilm](https://github.com/guiwitz/microfilm), [cmap](https://github.com/pyapp-kit/cmap)) that are more feature-rich than this one, but which don't address my goals. My hope is that this project can fill an un-met niche and otherwise maintain full compatibility with these and similar libraries.
113
+
114
+ This project incorporates a number of colormaps that were hand-crafted by Christophe Leterrier and were originally distributed here under the MIT license: https://github.com/cleterrier/ChrisLUTs
115
+
@@ -0,0 +1,12 @@
1
+ mergechannels-0.1.1.dist-info/METADATA,sha256=KBR7A0EVV24esr7QQmnL-iFfqQGdjteFHX1z8Cj_6EU,4676
2
+ mergechannels-0.1.1.dist-info/WHEEL,sha256=ZdoLgH9lcmexTAgYo3b2XEYu0Xl03VpVm_oICj2wvZ8,108
3
+ mergechannels-0.1.1.dist-info/licenses/LICENSE,sha256=csvD60rgtSorbYEM3f8867qNyPCzmIXyFNj8h01Bd6c,1071
4
+ mergechannels.libs/libgcc_s-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
5
+ mergechannels/_luts.py,sha256=DxwCMBnAAJc1ZX-D4cq8HabW-sLuBQpUqOWMWXqt_84,1035
6
+ mergechannels/_internal.py,sha256=Abzeacre5CQOcWn9WDIVuxFdEjTLIudEWQn8EsiH3oE,1243
7
+ mergechannels/__init__.pyi,sha256=lSMX8eip_zkzoJPJKvxvAhOsewwagoAhS9H5gXJ2Da8,711
8
+ mergechannels/__init__.py,sha256=jy8Qd3TOQ0mm-K64snjOqjdDQiSJ3gWjOjGZrliYy6k,222
9
+ mergechannels/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ mergechannels/_blending.py,sha256=mE5Cr9wvVJRcwfymg_UUZUjdIKx2mldfLU8QJT95bVM,84
11
+ mergechannels/mergechannels.cpython-313t-arm-linux-musleabihf.so,sha256=bI3d2wKH9ENkNxlK0p2CpA5k8HeanRwIrN1KVsJEQ0k,875057
12
+ mergechannels-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.8.3)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313t-musllinux_1_2_armv7l
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zachary Swider
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.