mergechannels 0.1.0__cp311-cp311-macosx_11_0_arm64.whl → 0.1.1__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.

@@ -9,13 +9,19 @@ def merge(
9
9
  arrs: Sequence[np.ndarray],
10
10
  colors: Sequence[COLORMAPS] = (),
11
11
  blending: Literal[BLENDING_OPTIONS] = 'max',
12
+ saturation_limits: tuple[float, float] = (0.2, 99.8),
12
13
  ) -> np.ndarray:
13
14
  ...
14
15
 
15
- def apply_color_map(arr: np.ndarray, cmap_name: COLORMAPS) -> np.ndarray: ...
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: ...
16
21
 
17
22
  def apply_colors_and_merge_nc(
18
23
  arrs: Sequence[np.ndarray],
19
24
  colors: Sequence[COLORMAPS] = (),
20
25
  blending: Literal[BLENDING_OPTIONS] = 'max',
26
+ saturation_limits: Sequence[tuple[float, float]] = (),
21
27
  ) -> np.ndarray: ...
@@ -11,24 +11,16 @@ from ._blending import BLENDING_OPTIONS
11
11
 
12
12
  def merge(
13
13
  arrs: Sequence[np.ndarray],
14
- colors: Sequence[COLORMAPS] = (),
14
+ colors: Sequence[COLORMAPS],
15
15
  blending: BLENDING_OPTIONS = 'max',
16
16
  ) -> np.ndarray:
17
17
  '''
18
18
  apply cmaps to arrays and blend the colors
19
19
  '''
20
+ # region validation
20
21
  n_arrs = len(arrs)
21
22
  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:
23
+ if not n_arrs == n_colors and n_arrs > 0:
32
24
  raise ValueError(
33
25
  'Expected an equal number of arrays to colorize and colormap names to apply. '
34
26
  f'Got {n_arrs} arrays and {n_colors} colors'
@@ -38,7 +30,17 @@ def merge(
38
30
  raise ValueError(
39
31
  f'Expected every array to have the same shape, got {arr_shapes}'
40
32
  )
41
- # call apply and merge rgb arrs here
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
+
42
44
  match n_arrs:
43
45
  case 1:
44
46
  return apply_color_map(arr=arrs[0], cmap_name=colors[0])
@@ -0,0 +1,112 @@
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.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: numpy>=1.24.4
15
+ License-File: LICENSE
16
+ License: MIT
17
+ Requires-Python: >=3.8, <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
+ ![License](https://img.shields.io/badge/license-MIT-blue.svg)
22
+ ![PyPI](https://img.shields.io/pypi/v/mergechannels)
23
+
24
+ # mergechannels
25
+
26
+ 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.
27
+
28
+
29
+
30
+ ## Installation
31
+
32
+ Install pre-compiled binaries from [PyPI](https://pypi.org/project/mergechannels/):
33
+ ```bash
34
+ pip install mergechannels
35
+ ```
36
+
37
+ Build from source on your own machine:
38
+ ```bash
39
+ pip install git+https://github.com/zacswider/mergechannels.git
40
+ ```
41
+
42
+ ## Usage
43
+ *NOTE*: scikit-image is not a dependency of this project, but is used in the examples below to fetch images.
44
+
45
+ ### colorize a single image
46
+
47
+ ```python
48
+ from skimage import data
49
+ import mergechannels as mc
50
+
51
+ img = data.camera()
52
+ colorized = mc.apply_color_map(img, 'Red/Green')
53
+ fig, axes = plt.subplots(1, 2, figsize=(6, 3), dpi=150)
54
+ for ax in axes: ax.axis('off')
55
+ (a, b) = axes
56
+ a.imshow(img, cmap='gray')
57
+ b.imshow(colorized)
58
+ plt.show()
59
+ print(colorized.shape, colorized.dtype)
60
+ >> (512, 512, 3) uint8
61
+ ```
62
+ ![colorize a single image](assets/readme_images/camera_red-green.png)
63
+
64
+
65
+ ### apply a different colormap to each channel
66
+ ```python
67
+ from skimage import data
68
+ import matplotlib.pyplot as plt
69
+ import mergechannels as mc
70
+
71
+ cells, nuclei = data.cells3d().max(axis=0)
72
+ cells = to_uint8(cells) # normalize your own arrays, mergechannels doesn't currently handle this
73
+ nuclei = to_uint8(nuclei) # normalize your own arrays, mergechannels doesn't currently handle this
74
+
75
+ fig, axes = plt.subplots(2, 2, figsize=(6, 6), dpi=150)
76
+ for ax in axes.ravel(): ax.axis('off')
77
+ (a, b, c, d) = axes.ravel()
78
+ a.imshow(cells, cmap='gray')
79
+ b.imshow(nuclei, cmap='gray')
80
+ c.imshow(
81
+ mc.merge(
82
+ [cells, nuclei],
83
+ ['Orange Hot', 'Cyan Hot'], # maximum blending is the default
84
+ ),
85
+ )
86
+ d.imshow(
87
+ mc.merge(
88
+ [cells, nuclei],
89
+ ['I Blue', 'I Forest'],
90
+ blending='min', # use minimum blending with inverted colormaps
91
+ ),
92
+ )
93
+ fig.tight_layout()
94
+ plt.show()
95
+ ```
96
+ ![apply a different colormap to each channel](assets/readme_images/cells_multicolor.png)
97
+
98
+
99
+ ## Roadmap
100
+ mergechannels is currently incredibly simple. It can apply one or more colormaps to one or more 2D 8-bit images and that's it.
101
+ - Add support for any numerical dtype
102
+ - Add support for 3D images
103
+ - Add option to return any colormap as a matplotlib colormap
104
+ - Add support for directly passing matplotlib colormaps instead of colormap names
105
+ - Parallelize colormap application on large images (if it's helpful)
106
+ - Add option to overlay binary or instance masks onto colorized images
107
+
108
+ ## Acknowledgements
109
+
110
+ 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.
111
+
112
+ 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.1.dist-info/METADATA,sha256=SBF12qNSkvavAvXpnM0ej--oF_wZFwGaKqJo7aC5d8U,4520
2
+ mergechannels-0.1.1.dist-info/WHEEL,sha256=wsVBlw9xyAuHecZeOYqJ_tA7emUKfXYOn-_180uZRi4,104
3
+ mergechannels-0.1.1.dist-info/licenses/LICENSE,sha256=R5es2fadg5bQoUJCJlcU36nDOAG6Te2XtsfysfTT_xY,1070
4
+ mergechannels/_internal.py,sha256=61RV6adhxkdqevanP06lpmONweppc6z5j8HTNkZq3uo,1267
5
+ mergechannels/__init__.pyi,sha256=yKPkFwpgY2pMlEXj6LvwLr7f9t0bcGnu5i9eMSeSlWo,710
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=uKy-VrPCwnX-QPaVHSiIaPIhomKSfuo02_a4x8pJJIs,726208
11
+ mergechannels-0.1.1.dist-info/RECORD,,
@@ -1,63 +0,0 @@
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
@@ -1,11 +0,0 @@
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,,