mapchete-eo 2025.8.2__tar.gz → 2025.8.3__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 (91) hide show
  1. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/PKG-INFO +5 -1
  2. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/README.rst +3 -0
  3. mapchete_eo-2025.8.3/mapchete_eo/__init__.py +1 -0
  4. mapchete_eo-2025.8.3/mapchete_eo/image_operations/blend_functions.py +579 -0
  5. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/compositing.py +33 -28
  6. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/fillnodata.py +1 -1
  7. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/pyproject.toml +1 -0
  8. mapchete_eo-2025.8.2/mapchete_eo/__init__.py +0 -1
  9. mapchete_eo-2025.8.2/mapchete_eo/image_operations/blend_modes/blending_functions.py +0 -198
  10. mapchete_eo-2025.8.2/mapchete_eo/image_operations/blend_modes/type_checks.py +0 -99
  11. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/.gitignore +0 -0
  12. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/LICENSE +0 -0
  13. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/archives/__init__.py +0 -0
  14. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/archives/base.py +0 -0
  15. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/array/__init__.py +0 -0
  16. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/array/buffer.py +0 -0
  17. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/array/color.py +0 -0
  18. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/array/convert.py +0 -0
  19. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/base.py +0 -0
  20. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/blacklist.txt +0 -0
  21. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/__init__.py +0 -0
  22. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/bounds.py +0 -0
  23. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/options_arguments.py +0 -0
  24. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_brdf.py +0 -0
  25. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_cat_results.py +0 -0
  26. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_find_broken_products.py +0 -0
  27. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_jp2_static_catalog.py +0 -0
  28. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_mask.py +0 -0
  29. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_mgrs.py +0 -0
  30. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_rgb.py +0 -0
  31. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/s2_verify.py +0 -0
  32. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/cli/static_catalog.py +0 -0
  33. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/eostac.py +0 -0
  34. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/exceptions.py +0 -0
  35. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/geometry.py +0 -0
  36. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/__init__.py +0 -0
  37. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/color_correction.py +0 -0
  38. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/dtype_scale.py +0 -0
  39. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/filters.py +0 -0
  40. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/linear_normalization.py +0 -0
  41. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/image_operations/sigmoidal.py +0 -0
  42. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/__init__.py +0 -0
  43. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/assets.py +0 -0
  44. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/items.py +0 -0
  45. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/levelled_cubes.py +0 -0
  46. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/path.py +0 -0
  47. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/products.py +0 -0
  48. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/io/profiles.py +0 -0
  49. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/known_catalogs.py +0 -0
  50. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/__init__.py +0 -0
  51. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/archives.py +0 -0
  52. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/bandpass_adjustment.py +0 -0
  53. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/__init__.py +0 -0
  54. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/config.py +0 -0
  55. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/correction.py +0 -0
  56. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/hls.py +0 -0
  57. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/models.py +0 -0
  58. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/protocols.py +0 -0
  59. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/ross_thick.py +0 -0
  60. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/brdf/sun_angle_arrays.py +0 -0
  61. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/config.py +0 -0
  62. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/driver.py +0 -0
  63. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/masks.py +0 -0
  64. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/metadata_parser.py +0 -0
  65. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/path_mappers/__init__.py +0 -0
  66. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/path_mappers/base.py +0 -0
  67. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/path_mappers/earthsearch.py +0 -0
  68. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/path_mappers/metadata_xml.py +0 -0
  69. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/path_mappers/sinergise.py +0 -0
  70. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/preprocessing_tasks.py +0 -0
  71. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/processing_baseline.py +0 -0
  72. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/product.py +0 -0
  73. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/platforms/sentinel2/types.py +0 -0
  74. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/processes/__init__.py +0 -0
  75. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/processes/config.py +0 -0
  76. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/processes/dtype_scale.py +0 -0
  77. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/processes/eo_to_xarray.py +0 -0
  78. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/processes/merge_rasters.py +0 -0
  79. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/product.py +0 -0
  80. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/protocols.py +0 -0
  81. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/__init__.py +0 -0
  82. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/base.py +0 -0
  83. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/config.py +0 -0
  84. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/s2_mgrs.py +0 -0
  85. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/stac_search.py +0 -0
  86. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/stac_static.py +0 -0
  87. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/search/utm_search.py +0 -0
  88. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/settings.py +0 -0
  89. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/sort.py +0 -0
  90. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/time.py +0 -0
  91. {mapchete_eo-2025.8.2 → mapchete_eo-2025.8.3}/mapchete_eo/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapchete-eo
3
- Version: 2025.8.2
3
+ Version: 2025.8.3
4
4
  Summary: mapchete EO data reader
5
5
  Project-URL: Homepage, https://gitlab.eox.at/maps/mapchete_eo
6
6
  Author-email: Joachim Ungar <joachim.ungar@eox.at>, Petr Sevcik <petr.sevcik@eox.at>
@@ -12,6 +12,7 @@ Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
15
16
  Classifier: Topic :: Scientific/Engineering :: GIS
16
17
  Requires-Dist: click
17
18
  Requires-Dist: croniter
@@ -43,6 +44,9 @@ Earth Observation–specific driver extensions for `Mapchete <https://github.com
43
44
  .. image:: https://img.shields.io/pypi/v/mapchete-eo.svg
44
45
  :target: https://pypi.org/project/mapchete-eo/
45
46
 
47
+ .. image:: https://img.shields.io/conda/v/conda-forge/mapchete-eo
48
+ :target: https://anaconda.org/conda-forge/mapchete-eo
49
+
46
50
  .. image:: https://img.shields.io/pypi/l/mapchete-eo.svg
47
51
  :target: https://github.com/mapchete/mapchete-eo/blob/main/LICENSE
48
52
 
@@ -5,6 +5,9 @@ Earth Observation–specific driver extensions for `Mapchete <https://github.com
5
5
  .. image:: https://img.shields.io/pypi/v/mapchete-eo.svg
6
6
  :target: https://pypi.org/project/mapchete-eo/
7
7
 
8
+ .. image:: https://img.shields.io/conda/v/conda-forge/mapchete-eo
9
+ :target: https://anaconda.org/conda-forge/mapchete-eo
10
+
8
11
  .. image:: https://img.shields.io/pypi/l/mapchete-eo.svg
9
12
  :target: https://github.com/mapchete/mapchete-eo/blob/main/LICENSE
10
13
 
@@ -0,0 +1 @@
1
+ __version__ = "2025.8.3"
@@ -0,0 +1,579 @@
1
+ """
2
+
3
+ Original LICENSE:
4
+
5
+ MIT License
6
+
7
+ Copyright (c) 2016 Florian Roscheck
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation th
11
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
12
+ persons to whom the Software is furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15
+ Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ """
24
+
25
+ import numpy as np
26
+
27
+
28
+ def _compose_alpha(fg: np.ndarray, bg: np.ndarray, opacity: float):
29
+ """Calculate alpha composition ratio between two images."""
30
+
31
+ comp_alpha = np.minimum(fg[:, :, 3], bg[:, :, 3]) * opacity
32
+ new_alpha = fg[:, :, 3] + (1.0 - fg[:, :, 3]) * comp_alpha
33
+ np.seterr(divide="ignore", invalid="ignore")
34
+ ratio = comp_alpha / new_alpha
35
+ ratio[np.isnan(ratio)] = 0.0
36
+ return ratio
37
+
38
+
39
+ def normal(fg: np.ndarray, bg: np.ndarray, opacity: float):
40
+ """Apply "normal" blending mode of a layer on an image.
41
+
42
+ See Also:
43
+ Find more information on `Wikipedia <https://en.wikipedia.org/wiki/Alpha_compositing#Description>`__.
44
+
45
+ Args:
46
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
47
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
48
+ opacity(float): Desired opacity of layer for blending
49
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
50
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
51
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
52
+
53
+ Returns:
54
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
55
+ """
56
+
57
+ # Extract alpha-channels and apply opacity
58
+ fg_alp = np.expand_dims(fg[:, :, 3], 2) # alpha of b, prepared for broadcasting
59
+ bg_alp = (
60
+ np.expand_dims(bg[:, :, 3], 2) * opacity
61
+ ) # alpha of a, prepared for broadcasting
62
+
63
+ # Blend images
64
+ with np.errstate(divide="ignore", invalid="ignore"):
65
+ img_out = (bg[:, :, :3] * bg_alp + fg[:, :, :3] * fg_alp * (1 - bg_alp)) / (
66
+ bg_alp + fg_alp * (1 - bg_alp)
67
+ )
68
+ img_out[np.isnan(img_out)] = 0 # replace NaNs with 0
69
+
70
+ # Blend alpha
71
+ cout_alp = bg_alp + fg_alp * (1 - bg_alp)
72
+
73
+ # Combine image and alpha
74
+ img_out = np.dstack((img_out, cout_alp))
75
+
76
+ np.nan_to_num(img_out, copy=False)
77
+
78
+ return img_out
79
+
80
+
81
+ def soft_light(fg: np.ndarray, bg: np.ndarray, opacity: float):
82
+ """Apply soft light blending mode of a layer on an image.
83
+
84
+ See Also:
85
+ Find more information on
86
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Soft_Light>`__.
87
+
88
+ Args:
89
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
90
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
91
+ opacity(float): Desired opacity of layer for blending
92
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
93
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
94
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
95
+
96
+ Returns:
97
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
98
+
99
+ """
100
+
101
+ ratio = _compose_alpha(fg, bg, opacity)
102
+
103
+ # The following code does this:
104
+ # multiply = fg[:, :, :3]*bg[:, :, :3]
105
+ # screen = 1.0 - (1.0-fg[:, :, :3])*(1.0-bg[:, :, :3])
106
+ # comp = (1.0 - fg[:, :, :3]) * multiply + fg[:, :, :3] * screen
107
+ # ratio_rs = np.reshape(np.repeat(ratio,3),comp.shape)
108
+ # img_out = comp*ratio_rs + fg[:, :, :3] * (1.0-ratio_rs)
109
+
110
+ comp = (1.0 - fg[:, :, :3]) * fg[:, :, :3] * bg[:, :, :3] + fg[:, :, :3] * (
111
+ 1.0 - (1.0 - fg[:, :, :3]) * (1.0 - bg[:, :, :3])
112
+ )
113
+
114
+ ratio_rs = np.reshape(
115
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
116
+ )
117
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
118
+ img_out = np.nan_to_num(
119
+ np.dstack((img_out, fg[:, :, 3]))
120
+ ) # add alpha channel and replace nans
121
+ return img_out
122
+
123
+
124
+ def lighten_only(fg: np.ndarray, bg: np.ndarray, opacity: float):
125
+ """Apply lighten only blending mode of a layer on an image.
126
+
127
+ See Also:
128
+ Find more information on
129
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Lighten_Only>`__.
130
+
131
+ Args:
132
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
133
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
134
+ opacity(float): Desired opacity of layer for blending
135
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
136
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
137
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
138
+
139
+ Returns:
140
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
141
+
142
+ """
143
+
144
+ ratio = _compose_alpha(fg, bg, opacity)
145
+
146
+ comp = np.maximum(fg[:, :, :3], bg[:, :, :3])
147
+
148
+ ratio_rs = np.reshape(
149
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
150
+ )
151
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
152
+ img_out = np.nan_to_num(
153
+ np.dstack((img_out, fg[:, :, 3]))
154
+ ) # add alpha channel and replace nans
155
+ return img_out
156
+
157
+
158
+ def screen(fg: np.ndarray, bg: np.ndarray, opacity: float):
159
+ """Apply screen blending mode of a layer on an image.
160
+
161
+ See Also:
162
+ Find more information on
163
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Screen>`__.
164
+
165
+ Args:
166
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
167
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
168
+ opacity(float): Desired opacity of layer for blending
169
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
170
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
171
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
172
+
173
+ Returns:
174
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
175
+
176
+ """
177
+
178
+ ratio = _compose_alpha(fg, bg, opacity)
179
+
180
+ comp = 1.0 - (1.0 - fg[:, :, :3]) * (1.0 - bg[:, :, :3])
181
+
182
+ ratio_rs = np.reshape(
183
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
184
+ )
185
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
186
+ img_out = np.nan_to_num(
187
+ np.dstack((img_out, fg[:, :, 3]))
188
+ ) # add alpha channel and replace nans
189
+ return img_out
190
+
191
+
192
+ def dodge(fg: np.ndarray, bg: np.ndarray, opacity: float):
193
+ """Apply dodge blending mode of a layer on an image.
194
+
195
+ See Also:
196
+ Find more information on
197
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Dodge_and_burn>`__.
198
+
199
+ Args:
200
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
201
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
202
+ opacity(float): Desired opacity of layer for blending
203
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
204
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
205
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
206
+
207
+ Returns:
208
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
209
+
210
+ """
211
+
212
+ ratio = _compose_alpha(fg, bg, opacity)
213
+
214
+ comp = np.minimum(fg[:, :, :3] / (1.0 - bg[:, :, :3]), 1.0)
215
+
216
+ ratio_rs = np.reshape(
217
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
218
+ )
219
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
220
+ img_out = np.nan_to_num(
221
+ np.dstack((img_out, fg[:, :, 3]))
222
+ ) # add alpha channel and replace nans
223
+ return img_out
224
+
225
+
226
+ def addition(fg: np.ndarray, bg: np.ndarray, opacity: float):
227
+ """Apply addition blending mode of a layer on an image.
228
+
229
+ See Also:
230
+ Find more information on
231
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Addition>`__.
232
+
233
+ Args:
234
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
235
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
236
+ opacity(float): Desired opacity of layer for blending
237
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
238
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
239
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
240
+
241
+ Returns:
242
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
243
+
244
+ """
245
+
246
+ ratio = _compose_alpha(fg, bg, opacity)
247
+
248
+ comp = fg[:, :, :3] + bg[:, :, :3]
249
+
250
+ ratio_rs = np.reshape(
251
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
252
+ )
253
+ img_out = np.clip(comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs), 0.0, 1.0)
254
+ img_out = np.nan_to_num(
255
+ np.dstack((img_out, fg[:, :, 3]))
256
+ ) # add alpha channel and replace nans
257
+ return img_out
258
+
259
+
260
+ def darken_only(fg: np.ndarray, bg: np.ndarray, opacity: float):
261
+ """Apply darken only blending mode of a layer on an image.
262
+
263
+ See Also:
264
+ Find more information on
265
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Darken_Only>`__.
266
+
267
+ Args:
268
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
269
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
270
+ opacity(float): Desired opacity of layer for blending
271
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
272
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
273
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
274
+
275
+ Returns:
276
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
277
+
278
+ """
279
+
280
+ ratio = _compose_alpha(fg, bg, opacity)
281
+
282
+ comp = np.minimum(fg[:, :, :3], bg[:, :, :3])
283
+
284
+ ratio_rs = np.reshape(
285
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
286
+ )
287
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
288
+ img_out = np.nan_to_num(
289
+ np.dstack((img_out, fg[:, :, 3]))
290
+ ) # add alpha channel and replace nans
291
+ return img_out
292
+
293
+
294
+ def multiply(fg: np.ndarray, bg: np.ndarray, opacity: float):
295
+ """Apply multiply blending mode of a layer on an image.
296
+
297
+ See Also:
298
+ Find more information on
299
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Multiply>`__.
300
+
301
+ Args:
302
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
303
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
304
+ opacity(float): Desired opacity of layer for blending
305
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
306
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
307
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
308
+
309
+ Returns:
310
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
311
+
312
+ """
313
+
314
+ ratio = _compose_alpha(fg, bg, opacity)
315
+
316
+ comp = np.clip(bg[:, :, :3] * fg[:, :, :3], 0.0, 1.0)
317
+
318
+ ratio_rs = np.reshape(
319
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
320
+ )
321
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
322
+ img_out = np.nan_to_num(
323
+ np.dstack((img_out, fg[:, :, 3]))
324
+ ) # add alpha channel and replace nans
325
+ return img_out
326
+
327
+
328
+ def hard_light(fg: np.ndarray, bg: np.ndarray, opacity: float):
329
+ """Apply hard light blending mode of a layer on an image.
330
+
331
+ See Also:
332
+ Find more information on
333
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Hard_Light>`__.
334
+
335
+ Args:
336
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
337
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
338
+ opacity(float): Desired opacity of layer for blending
339
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
340
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
341
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
342
+
343
+ Returns:
344
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
345
+
346
+ """
347
+
348
+ ratio = _compose_alpha(fg, bg, opacity)
349
+
350
+ comp = np.greater(bg[:, :, :3], 0.5) * np.minimum(
351
+ 1.0 - ((1.0 - fg[:, :, :3]) * (1.0 - (bg[:, :, :3] - 0.5) * 2.0)),
352
+ 1.0,
353
+ ) + np.logical_not(np.greater(bg[:, :, :3], 0.5)) * np.minimum(
354
+ fg[:, :, :3] * (bg[:, :, :3] * 2.0), 1.0
355
+ )
356
+
357
+ ratio_rs = np.reshape(
358
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
359
+ )
360
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
361
+ img_out = np.nan_to_num(
362
+ np.dstack((img_out, fg[:, :, 3]))
363
+ ) # add alpha channel and replace nans
364
+ return img_out
365
+
366
+
367
+ def difference(fg: np.ndarray, bg: np.ndarray, opacity: float):
368
+ """Apply difference blending mode of a layer on an image.
369
+
370
+ See Also:
371
+ Find more information on
372
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Difference>`__.
373
+
374
+ Args:
375
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
376
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
377
+ opacity(float): Desired opacity of layer for blending
378
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
379
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
380
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
381
+
382
+ Returns:
383
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
384
+
385
+ """
386
+
387
+ ratio = _compose_alpha(fg, bg, opacity)
388
+
389
+ comp = fg[:, :, :3] - bg[:, :, :3]
390
+ comp[comp < 0.0] *= -1.0
391
+
392
+ ratio_rs = np.reshape(
393
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
394
+ )
395
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
396
+ img_out = np.nan_to_num(
397
+ np.dstack((img_out, fg[:, :, 3]))
398
+ ) # add alpha channel and replace nans
399
+ return img_out
400
+
401
+
402
+ def subtract(fg: np.ndarray, bg: np.ndarray, opacity: float):
403
+ """Apply subtract blending mode of a layer on an image.
404
+
405
+ See Also:
406
+ Find more information on
407
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Subtract>`__.
408
+
409
+ Args:
410
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
411
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
412
+ opacity(float): Desired opacity of layer for blending
413
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
414
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
415
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
416
+
417
+ Returns:
418
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
419
+
420
+ """
421
+
422
+ ratio = _compose_alpha(fg, bg, opacity)
423
+
424
+ comp = fg[:, :, :3] - bg[:, :, :3]
425
+
426
+ ratio_rs = np.reshape(
427
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
428
+ )
429
+ img_out = np.clip(comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs), 0.0, 1.0)
430
+ img_out = np.nan_to_num(
431
+ np.dstack((img_out, fg[:, :, 3]))
432
+ ) # add alpha channel and replace nans
433
+ return img_out
434
+
435
+
436
+ def grain_extract(fg: np.ndarray, bg: np.ndarray, opacity: float):
437
+ """Apply grain extract blending mode of a layer on an image.
438
+
439
+ See Also:
440
+ Find more information in the `GIMP Documentation <https://docs.gimp.org/en/gimp-concepts-layer-modes.html>`__.
441
+
442
+ Args:
443
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
444
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
445
+ opacity(float): Desired opacity of layer for blending
446
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
447
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
448
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
449
+
450
+ Returns:
451
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
452
+
453
+ """
454
+
455
+ ratio = _compose_alpha(fg, bg, opacity)
456
+
457
+ comp = np.clip(fg[:, :, :3] - bg[:, :, :3] + 0.5, 0.0, 1.0)
458
+
459
+ ratio_rs = np.reshape(
460
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
461
+ )
462
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
463
+ img_out = np.nan_to_num(
464
+ np.dstack((img_out, fg[:, :, 3]))
465
+ ) # add alpha channel and replace nans
466
+ return img_out
467
+
468
+
469
+ def grain_merge(fg: np.ndarray, bg: np.ndarray, opacity: float):
470
+ """Apply grain merge blending mode of a layer on an image.
471
+
472
+ See Also:
473
+ Find more information in the `GIMP Documentation <https://docs.gimp.org/en/gimp-concepts-layer-modes.html>`__.
474
+
475
+ Args:
476
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
477
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
478
+ opacity(float): Desired opacity of layer for blending
479
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
480
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
481
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
482
+
483
+ Returns:
484
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
485
+
486
+ """
487
+
488
+ ratio = _compose_alpha(fg, bg, opacity)
489
+
490
+ comp = np.clip(fg[:, :, :3] + bg[:, :, :3] - 0.5, 0.0, 1.0)
491
+
492
+ ratio_rs = np.reshape(
493
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
494
+ )
495
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
496
+ img_out = np.nan_to_num(
497
+ np.dstack((img_out, fg[:, :, 3]))
498
+ ) # add alpha channel and replace nans
499
+ return img_out
500
+
501
+
502
+ def divide(fg: np.ndarray, bg: np.ndarray, opacity: float):
503
+ """Apply divide blending mode of a layer on an image.
504
+
505
+ See Also:
506
+ Find more information on
507
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=747749280#Divide>`__.
508
+
509
+ Args:
510
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
511
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
512
+ opacity(float): Desired opacity of layer for blending
513
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
514
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
515
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
516
+
517
+ Returns:
518
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
519
+
520
+ """
521
+
522
+ ratio = _compose_alpha(fg, bg, opacity)
523
+
524
+ comp = np.minimum(
525
+ (256.0 / 255.0 * fg[:, :, :3]) / (1.0 / 255.0 + bg[:, :, :3]),
526
+ 1.0,
527
+ )
528
+
529
+ ratio_rs = np.reshape(
530
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
531
+ )
532
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
533
+ img_out = np.nan_to_num(
534
+ np.dstack((img_out, fg[:, :, 3]))
535
+ ) # add alpha channel and replace nans
536
+ return img_out
537
+
538
+
539
+ def overlay(fg: np.ndarray, bg: np.ndarray, opacity: float):
540
+ """Apply overlay blending mode of a layer on an image.
541
+
542
+ Note:
543
+ The implementation of this method was changed in version 2.0.0. Previously, it would be identical to the
544
+ soft light blending mode. Now, it resembles the implementation on Wikipedia. You can still use the soft light
545
+ blending mode if you are looking for backwards compatibility.
546
+
547
+ See Also:
548
+ Find more information on
549
+ `Wikipedia <https://en.wikipedia.org/w/index.php?title=Blend_modes&oldid=868545948#Overlay>`__.
550
+
551
+ Args:
552
+ fg(3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0): Image to be blended upon
553
+ bg(3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0): Layer to be blended with image
554
+ opacity(float): Desired opacity of layer for blending
555
+ disable_type_checks(bool): Whether type checks within the function should be disabled. Disabling the checks may
556
+ yield a slight performance improvement, but comes at the cost of user experience. If you are certain that
557
+ you are passing in the right arguments, you may set this argument to 'True'. Defaults to 'False'.
558
+
559
+ Returns:
560
+ 3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0: Blended image
561
+
562
+ """
563
+
564
+ ratio = _compose_alpha(fg, bg, opacity)
565
+
566
+ comp = np.less(fg[:, :, :3], 0.5) * (
567
+ 2 * fg[:, :, :3] * bg[:, :, :3]
568
+ ) + np.greater_equal(fg[:, :, :3], 0.5) * (
569
+ 1 - (2 * (1 - fg[:, :, :3]) * (1 - bg[:, :, :3]))
570
+ )
571
+
572
+ ratio_rs = np.reshape(
573
+ np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]]
574
+ )
575
+ img_out = comp * ratio_rs + fg[:, :, :3] * (1.0 - ratio_rs)
576
+ img_out = np.nan_to_num(
577
+ np.dstack((img_out, fg[:, :, 3]))
578
+ ) # add alpha channel and replace nans
579
+ return img_out