mergechannels 0.1.2__cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl → 0.2.0__cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.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 +5 -5
- mergechannels/__init__.pyi +20 -17
- mergechannels/_internal.py +25 -7
- mergechannels/mergechannels.cpython-39-powerpc64le-linux-gnu.so +0 -0
- {mergechannels-0.1.2.dist-info → mergechannels-0.2.0.dist-info}/METADATA +52 -22
- mergechannels-0.2.0.dist-info/RECORD +11 -0
- {mergechannels-0.1.2.dist-info → mergechannels-0.2.0.dist-info}/WHEEL +1 -1
- mergechannels-0.1.2.dist-info/RECORD +0 -11
- {mergechannels-0.1.2.dist-info → mergechannels-0.2.0.dist-info}/licenses/LICENSE +0 -0
mergechannels/__init__.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Import Rust functions
|
|
2
2
|
from .mergechannels import ( # type: ignore
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
dispatch_single_channel,
|
|
4
|
+
dispatch_multi_channel,
|
|
5
5
|
)
|
|
6
|
-
|
|
7
6
|
from ._internal import merge
|
|
8
7
|
|
|
8
|
+
|
|
9
9
|
__all__ = [
|
|
10
|
-
'
|
|
11
|
-
'
|
|
10
|
+
'dispatch_single_channel',
|
|
11
|
+
'dispatch_multi_channel',
|
|
12
12
|
'merge',
|
|
13
13
|
]
|
mergechannels/__init__.pyi
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
from typing import Sequence, Literal
|
|
2
1
|
|
|
2
|
+
from typing import Literal, Sequence
|
|
3
3
|
import numpy as np
|
|
4
4
|
|
|
5
|
-
from .
|
|
6
|
-
from .
|
|
5
|
+
from python.mergechannels._blending import BLENDING_OPTIONS
|
|
6
|
+
from python.mergechannels._luts import COLORMAPS
|
|
7
|
+
|
|
7
8
|
|
|
8
9
|
def merge(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
arrs: np.ndarray | Sequence[np.ndarray],
|
|
11
|
+
colors: Sequence[COLORMAPS] = (),
|
|
12
|
+
blending: Literal[BLENDING_OPTIONS] = 'max',
|
|
12
13
|
saturation_limits: tuple[float, float] = (0.2, 99.8),
|
|
13
14
|
) -> np.ndarray:
|
|
14
15
|
...
|
|
15
16
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
cmap_name:
|
|
19
|
-
|
|
20
|
-
) -> np.ndarray:
|
|
17
|
+
def dispatch_single_channel(
|
|
18
|
+
array_reference: np.ndarray,
|
|
19
|
+
cmap_name: str,
|
|
20
|
+
limits: tuple[float, float],
|
|
21
|
+
) -> np.ndarray:
|
|
22
|
+
...
|
|
21
23
|
|
|
22
|
-
def
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
blending: Literal[BLENDING_OPTIONS]
|
|
26
|
-
|
|
27
|
-
) -> np.ndarray:
|
|
24
|
+
def dispatch_multi_channel(
|
|
25
|
+
array_references: Sequence[np.ndarray],
|
|
26
|
+
cmap_names: Sequence[str],
|
|
27
|
+
blending: Literal[BLENDING_OPTIONS],
|
|
28
|
+
limits: Sequence[tuple[float, float]],
|
|
29
|
+
) -> np.ndarray:
|
|
30
|
+
...
|
mergechannels/_internal.py
CHANGED
|
@@ -3,8 +3,8 @@ from typing import Sequence
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
|
|
5
5
|
from mergechannels import (
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
dispatch_single_channel,
|
|
7
|
+
dispatch_multi_channel,
|
|
8
8
|
)
|
|
9
9
|
from ._luts import COLORMAPS
|
|
10
10
|
from ._blending import BLENDING_OPTIONS
|
|
@@ -13,6 +13,7 @@ def merge(
|
|
|
13
13
|
arrs: Sequence[np.ndarray],
|
|
14
14
|
colors: Sequence[COLORMAPS],
|
|
15
15
|
blending: BLENDING_OPTIONS = 'max',
|
|
16
|
+
saturation_limits: tuple[float, float] = (0.011, 0.999),
|
|
16
17
|
) -> np.ndarray:
|
|
17
18
|
'''
|
|
18
19
|
apply cmaps to arrays and blend the colors
|
|
@@ -30,9 +31,9 @@ def merge(
|
|
|
30
31
|
raise ValueError(
|
|
31
32
|
f'Expected every array to have the same shape, got {arr_shapes}'
|
|
32
33
|
)
|
|
33
|
-
if
|
|
34
|
+
if len(arr_shapes[0]) not in (2, 3):
|
|
34
35
|
raise ValueError(
|
|
35
|
-
f'Expected every array to be 2D, got {arr_shapes[0]}'
|
|
36
|
+
f'Expected every array to be 2D or 3D, got {arr_shapes[0]}'
|
|
36
37
|
)
|
|
37
38
|
arr_dtypes = [arr.dtype for arr in arrs]
|
|
38
39
|
if not len(set(arr_dtypes)) == 1:
|
|
@@ -40,8 +41,25 @@ def merge(
|
|
|
40
41
|
f'Expected every array to have the same dtype, got {arr_dtypes}'
|
|
41
42
|
)
|
|
42
43
|
# endregion
|
|
43
|
-
|
|
44
44
|
if n_arrs == 1:
|
|
45
|
-
|
|
45
|
+
if arrs[0].dtype == 'uint8':
|
|
46
|
+
limits = (0, 255)
|
|
47
|
+
else:
|
|
48
|
+
low, high = np.percentile(arrs[0], np.array(saturation_limits) * 100)
|
|
49
|
+
limits = (low, high)
|
|
50
|
+
return dispatch_single_channel(
|
|
51
|
+
array_reference=arrs[0],
|
|
52
|
+
cmap_name=colors[0],
|
|
53
|
+
limits=limits,
|
|
54
|
+
)
|
|
46
55
|
else:
|
|
47
|
-
|
|
56
|
+
if all(arr.dtype == 'uint8' for arr in arrs):
|
|
57
|
+
limits = (0, 255)
|
|
58
|
+
else:
|
|
59
|
+
limits = tuple(np.percentile(arr, np.array(saturation_limits) * 100) for arr in arrs)
|
|
60
|
+
return dispatch_multi_channel(
|
|
61
|
+
array_references=arrs,
|
|
62
|
+
cmap_names=colors,
|
|
63
|
+
blending=blending,
|
|
64
|
+
limits=limits, # type: ignore
|
|
65
|
+
)
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mergechannels
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -12,7 +12,10 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.13
|
|
14
14
|
Requires-Dist: numpy>1.25.0
|
|
15
|
+
Provides-Extra: nvim
|
|
15
16
|
License-File: LICENSE
|
|
17
|
+
Summary: Apply and merge colormaps
|
|
18
|
+
Author-email: Zac Swider <zac.swider@gmail.com>
|
|
16
19
|
License: MIT
|
|
17
20
|
Requires-Python: >=3.9, <=3.13
|
|
18
21
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
@@ -60,8 +63,7 @@ plt.show()
|
|
|
60
63
|
print(colorized.shape, colorized.dtype)
|
|
61
64
|
>> (512, 512, 3) uint8
|
|
62
65
|
```
|
|
63
|
-

|
|
66
|
+

|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
### apply a different colormap to each channel
|
|
@@ -71,38 +73,66 @@ import matplotlib.pyplot as plt
|
|
|
71
73
|
import mergechannels as mc
|
|
72
74
|
|
|
73
75
|
cells, nuclei = data.cells3d().max(axis=0)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
assert cells.dtype == 'uint16' and nuclei.dtype == 'uint16'
|
|
77
|
+
fig, axes = plt.subplots(1, 2, figsize=(3, 6), dpi=300)
|
|
78
|
+
for ax in axes.ravel(): ax.axis('off')
|
|
79
|
+
(a, b) = axes.ravel()
|
|
80
|
+
a.imshow(mc.merge([cells, nuclei],['Orange Hot', 'Cyan Hot']))
|
|
81
|
+
b.imshow(mc.merge([cells, nuclei],['I Blue', 'I Forest'], blending='min'))
|
|
82
|
+
fig.tight_layout()
|
|
83
|
+
plt.show()
|
|
84
|
+
```
|
|
85
|
+

|
|
76
86
|
|
|
77
|
-
|
|
87
|
+
### apply a colormap to a whole stack
|
|
88
|
+
```python
|
|
89
|
+
from skimage import data
|
|
90
|
+
from matplotlib import pyplot as plt
|
|
91
|
+
import mergechannels as mc
|
|
92
|
+
|
|
93
|
+
volume = data.cells3d()
|
|
94
|
+
cells = volume[:, 0]
|
|
95
|
+
nuclei = volume[:, 1]
|
|
96
|
+
merged = mc.merge([cells, nuclei],['Orange Hot', 'Cyan Hot'])
|
|
97
|
+
plt.imshow(merged[24]); plt.show()
|
|
98
|
+
```
|
|
99
|
+

|
|
100
|
+
|
|
101
|
+
### adjust the saturation limits when applying colormaps
|
|
102
|
+
``` python
|
|
103
|
+
from skimage import data
|
|
104
|
+
import matplotlib.pyplot as plt
|
|
105
|
+
import mergechannels as mc
|
|
106
|
+
|
|
107
|
+
cells, nuclei = data.cells3d().max(axis=0)
|
|
108
|
+
channels = [cells, nuclei]
|
|
109
|
+
colormaps = ['I Blue', 'I Forest']
|
|
110
|
+
fig, axes = plt.subplots(1, 2, figsize=(3, 6), dpi=300)
|
|
78
111
|
for ax in axes.ravel(): ax.axis('off')
|
|
79
|
-
(a, b
|
|
80
|
-
a.imshow(
|
|
81
|
-
b.imshow(
|
|
82
|
-
c.imshow(
|
|
83
|
-
mc.merge(
|
|
84
|
-
[cells, nuclei],
|
|
85
|
-
['Orange Hot', 'Cyan Hot'], # maximum blending is the default
|
|
86
|
-
),
|
|
87
|
-
)
|
|
88
|
-
d.imshow(
|
|
112
|
+
(a, b) = axes.ravel()
|
|
113
|
+
a.imshow(mc.merge(channels, colormaps, blending='min'))
|
|
114
|
+
b.imshow(
|
|
89
115
|
mc.merge(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
blending='min',
|
|
116
|
+
channels,
|
|
117
|
+
colormaps,
|
|
118
|
+
blending='min',
|
|
119
|
+
saturation_limits=(
|
|
120
|
+
0.01, # bottom 1% of pixels set to black point
|
|
121
|
+
0.97, # top 3% of pixels set to white point
|
|
122
|
+
),
|
|
93
123
|
),
|
|
94
124
|
)
|
|
95
125
|
fig.tight_layout()
|
|
96
126
|
plt.show()
|
|
97
127
|
```
|
|
98
|
-

|
|
99
129
|
|
|
100
130
|
|
|
101
131
|
## 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.
|
|
132
|
+
mergechannels is currently incredibly simple. It can apply one or more colormaps to one or more 2D and 3D 8-bit or 16-bit images and that's it.
|
|
103
133
|
- Add support for any numerical dtype
|
|
104
|
-
- Add support for 3D images
|
|
105
134
|
- Add option to return any colormap as a matplotlib colormap
|
|
135
|
+
- Add option to pass external colormaps to mergechannels
|
|
106
136
|
- Add support for directly passing matplotlib colormaps instead of colormap names
|
|
107
137
|
- Parallelize colormap application on large images (if it's helpful)
|
|
108
138
|
- Add option to overlay binary or instance masks onto colorized images
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mergechannels-0.2.0.dist-info/METADATA,sha256=t-okrnqyvIiZxuLqTlubmCkXCxKz9U43u7bhSIEiNBc,5725
|
|
2
|
+
mergechannels-0.2.0.dist-info/WHEEL,sha256=AgRYdierwji5LMigdvW4USDs9NpHbQb5qmtuwZjCN3o,129
|
|
3
|
+
mergechannels-0.2.0.dist-info/licenses/LICENSE,sha256=csvD60rgtSorbYEM3f8867qNyPCzmIXyFNj8h01Bd6c,1071
|
|
4
|
+
mergechannels/__init__.py,sha256=TTNiDGOOJ6_-yR-qvX_nXph646Sz6-MEORc8ItksCRE,232
|
|
5
|
+
mergechannels/__init__.pyi,sha256=tiDx6v14J0cedFdk6fzVRRyA21b4Z8eB_rtSTUjI804,749
|
|
6
|
+
mergechannels/_blending.py,sha256=mE5Cr9wvVJRcwfymg_UUZUjdIKx2mldfLU8QJT95bVM,84
|
|
7
|
+
mergechannels/_internal.py,sha256=ZcdBUFEq8k2Ve_ASOZLTuPBaFEEPqadc9LqAGmBqOas,1773
|
|
8
|
+
mergechannels/_luts.py,sha256=DxwCMBnAAJc1ZX-D4cq8HabW-sLuBQpUqOWMWXqt_84,1035
|
|
9
|
+
mergechannels/mergechannels.cpython-39-powerpc64le-linux-gnu.so,sha256=pV91QYI7yq11iMpUHnjuzMLFUicyGAUtmpmiUBA3D-o,1340768
|
|
10
|
+
mergechannels/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
mergechannels-0.2.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
mergechannels-0.1.2.dist-info/METADATA,sha256=fdx3XuAlrCeScx655leoDJJEMtrZQ2-K2tX--JalIAI,4676
|
|
2
|
-
mergechannels-0.1.2.dist-info/WHEEL,sha256=oHq2myGwhjJ6JrE1Jw2TjjLc2CT3Tv2ynezcCNAu8so,129
|
|
3
|
-
mergechannels-0.1.2.dist-info/licenses/LICENSE,sha256=csvD60rgtSorbYEM3f8867qNyPCzmIXyFNj8h01Bd6c,1071
|
|
4
|
-
mergechannels/_luts.py,sha256=DxwCMBnAAJc1ZX-D4cq8HabW-sLuBQpUqOWMWXqt_84,1035
|
|
5
|
-
mergechannels/_internal.py,sha256=Abzeacre5CQOcWn9WDIVuxFdEjTLIudEWQn8EsiH3oE,1243
|
|
6
|
-
mergechannels/__init__.pyi,sha256=lSMX8eip_zkzoJPJKvxvAhOsewwagoAhS9H5gXJ2Da8,711
|
|
7
|
-
mergechannels/__init__.py,sha256=jy8Qd3TOQ0mm-K64snjOqjdDQiSJ3gWjOjGZrliYy6k,222
|
|
8
|
-
mergechannels/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
mergechannels/_blending.py,sha256=mE5Cr9wvVJRcwfymg_UUZUjdIKx2mldfLU8QJT95bVM,84
|
|
10
|
-
mergechannels/mergechannels.cpython-39-powerpc64le-linux-gnu.so,sha256=BxmSZAxNEXb9drcthkG8kDYOyOZULxBdCXjP-yjMaOA,1024896
|
|
11
|
-
mergechannels-0.1.2.dist-info/RECORD,,
|
|
File without changes
|