mergechannels 0.1.0__cp311-cp311-macosx_11_0_arm64.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.
- mergechannels/__init__.py +13 -0
- mergechannels/__init__.pyi +21 -0
- mergechannels/_blending.py +3 -0
- mergechannels/_internal.py +56 -0
- mergechannels/_luts.py +81 -0
- mergechannels/mergechannels.cpython-311-darwin.so +0 -0
- mergechannels/py.typed +0 -0
- mergechannels-0.1.0.dist-info/METADATA +63 -0
- mergechannels-0.1.0.dist-info/RECORD +11 -0
- mergechannels-0.1.0.dist-info/WHEEL +4 -0
- mergechannels-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
) -> np.ndarray:
|
|
13
|
+
...
|
|
14
|
+
|
|
15
|
+
def apply_color_map(arr: np.ndarray, cmap_name: COLORMAPS) -> np.ndarray: ...
|
|
16
|
+
|
|
17
|
+
def apply_colors_and_merge_nc(
|
|
18
|
+
arrs: Sequence[np.ndarray],
|
|
19
|
+
colors: Sequence[COLORMAPS] = (),
|
|
20
|
+
blending: Literal[BLENDING_OPTIONS] = 'max',
|
|
21
|
+
) -> np.ndarray: ...
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
n_arrs = len(arrs)
|
|
21
|
+
n_colors = len(colors)
|
|
22
|
+
if n_arrs > 0 and n_colors == 0:
|
|
23
|
+
arr_shapes = [arr.shape for arr in arrs]
|
|
24
|
+
if not all([len(arr_shape) == 3 for arr_shape in arr_shapes]):
|
|
25
|
+
raise ValueError(
|
|
26
|
+
'Expected a sequence of pre-colorized arrays, '
|
|
27
|
+
f'got {n_arrs} arrays of shapes {arr_shapes}'
|
|
28
|
+
)
|
|
29
|
+
# call merge rgb arrs here
|
|
30
|
+
return np.zeros((3,3))
|
|
31
|
+
if not n_arrs == n_colors:
|
|
32
|
+
raise ValueError(
|
|
33
|
+
'Expected an equal number of arrays to colorize and colormap names to apply. '
|
|
34
|
+
f'Got {n_arrs} arrays and {n_colors} colors'
|
|
35
|
+
)
|
|
36
|
+
arr_shapes = [arr.shape for arr in arrs]
|
|
37
|
+
if not len(set(arr_shapes)) == 1:
|
|
38
|
+
raise ValueError(
|
|
39
|
+
f'Expected every array to have the same shape, got {arr_shapes}'
|
|
40
|
+
)
|
|
41
|
+
# call apply and merge rgb arrs here
|
|
42
|
+
match n_arrs:
|
|
43
|
+
case 1:
|
|
44
|
+
return apply_color_map(arr=arrs[0], cmap_name=colors[0])
|
|
45
|
+
case _:
|
|
46
|
+
return apply_colors_and_merge_nc(arrs, colors, blending)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
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
|
+
]
|
|
Binary file
|
mergechannels/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mergechannels
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
7
|
+
Requires-Dist: numpy>=1.24.4
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.8, <3.13
|
|
10
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
11
|
+
|
|
12
|
+
# mergechannels
|
|
13
|
+
|
|
14
|
+
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), so I was interested in seeing if I could at least match matplotlib's colormapping performance with my own hand-rolled colorizer in Rust.
|
|
15
|
+
|
|
16
|
+
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 projecting on your needs, but which don't address the my goals. My hope is that this project can fill and un-met niche and otherwise maintain full compatibility with these and similar libraries.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install pre-compiled binaries from [PyPI](https://pypi.org/project/mergechannels/):
|
|
21
|
+
```bash
|
|
22
|
+
pip install mergechannels
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Build from source on your own machine:
|
|
26
|
+
```bash
|
|
27
|
+
pip install git+https://github.com/zacswider/mergechannels.git
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
*NOTE*: scikit-image is not a dependency of this project, but is used in the examples below to fetch images.
|
|
32
|
+
|
|
33
|
+
### colorize a single image
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from skimage import data
|
|
37
|
+
import matplotlib.pyplot as plt
|
|
38
|
+
import mergechannels as mc
|
|
39
|
+
|
|
40
|
+
img = data.camera()
|
|
41
|
+
fig, ax = plt.subplots()
|
|
42
|
+
ax.imshow(mc.apply_colormap(img, 'Orange Hot'))
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### apply a different colormap to each channel
|
|
46
|
+
```python
|
|
47
|
+
from skimage import data
|
|
48
|
+
import matplotlib.pyplot as plt
|
|
49
|
+
import mergechannels as mc
|
|
50
|
+
|
|
51
|
+
cells, nuclei = data.cells3d().max(axis=0)
|
|
52
|
+
cells = to_uint8(cells / cells.max()) <- broken until normalization is handled
|
|
53
|
+
nuclei = to_uint8(nuclei / nuclei.max()) <- broken until normalization is handled
|
|
54
|
+
fig, (a, b, c) = plt.subplots(1, 3)
|
|
55
|
+
a.imshow(cells, cmap='gray')
|
|
56
|
+
b.imshow(nuclei, cmap='gray')
|
|
57
|
+
|
|
58
|
+
import mergechannels as mc
|
|
59
|
+
c.imshow(mc.merge([cells, nuclei], ['Orange Hot', 'Cyan Hot']))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Acknowledgements
|
|
63
|
+
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
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mergechannels-0.1.0.dist-info/METADATA,sha256=tK_250ZwpjXLerJFVfX5GcLBgbLRcwCGpExsDb9ebtg,2677
|
|
2
|
+
mergechannels-0.1.0.dist-info/WHEEL,sha256=wsVBlw9xyAuHecZeOYqJ_tA7emUKfXYOn-_180uZRi4,104
|
|
3
|
+
mergechannels-0.1.0.dist-info/licenses/LICENSE,sha256=R5es2fadg5bQoUJCJlcU36nDOAG6Te2XtsfysfTT_xY,1070
|
|
4
|
+
mergechannels/_internal.py,sha256=UrR1K-JYbg8BS7wbmtxcOLWnWuoxmKJztlWT3TQ-Pyk,1300
|
|
5
|
+
mergechannels/__init__.pyi,sha256=Z4dmA6TQydClHHVU_wje6X4CD0xh8l_b9D2imN4pLzI,524
|
|
6
|
+
mergechannels/__init__.py,sha256=Tj-1QoMYkvDi-Bew6N2kbKrOhtgo4kq61_vmnHacp3o,224
|
|
7
|
+
mergechannels/_luts.py,sha256=DxwCMBnAAJc1ZX-D4cq8HabW-sLuBQpUqOWMWXqt_84,1035
|
|
8
|
+
mergechannels/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
mergechannels/_blending.py,sha256=mE5Cr9wvVJRcwfymg_UUZUjdIKx2mldfLU8QJT95bVM,84
|
|
10
|
+
mergechannels/mergechannels.cpython-311-darwin.so,sha256=GKUfHavebuAc_qSI3Kayol7aT8y2rP625kWw9fLq_ZY,711560
|
|
11
|
+
mergechannels-0.1.0.dist-info/RECORD,,
|
|
@@ -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.
|