nv-ingest-api 2025.10.4.dev20251004__py3-none-any.whl → 2025.10.6.dev20251006__py3-none-any.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 nv-ingest-api might be problematic. Click here for more details.

@@ -49,6 +49,68 @@ def _resize_image_opencv(
49
49
  return cv2.resize(array, target_size, interpolation=interpolation)
50
50
 
51
51
 
52
+ def rgba_to_rgb_white_bg(rgba_image):
53
+ """
54
+ Convert RGBA image to RGB by blending with a white background.
55
+
56
+ This function properly handles transparency by alpha-blending transparent
57
+ and semi-transparent pixels with a white background, producing visually
58
+ accurate results that match how the image would appear when displayed.
59
+
60
+ Parameters
61
+ ----------
62
+ rgba_image : numpy.ndarray
63
+ Input image array with shape (height, width, 4) where the channels
64
+ are Red, Green, Blue, Alpha. Alpha values can be in range [0, 1]
65
+ (float) or [0, 255] (uint8).
66
+
67
+ Returns
68
+ -------
69
+ numpy.ndarray
70
+ RGB image array with shape (height, width, 3) and dtype uint8.
71
+ Values are in range [0, 255] representing Red, Green, Blue channels.
72
+
73
+ Notes
74
+ -----
75
+ The alpha blending formula used is:
76
+ RGB_out = RGB_in * alpha + background * (1 - alpha)
77
+
78
+ Where background is white (255, 255, 255).
79
+
80
+ For pixels with alpha = 1.0 (fully opaque), the original RGB values
81
+ are preserved. For pixels with alpha = 0.0 (fully transparent), the
82
+ result is white. Semi-transparent pixels are blended proportionally.
83
+
84
+ Examples
85
+ --------
86
+ >>> import numpy as np
87
+ >>> # Create a sample RGBA image with some transparency
88
+ >>> rgba = np.random.randint(0, 256, (100, 100, 4), dtype=np.uint8)
89
+ >>> rgb = rgba_to_rgb_white_bg(rgba)
90
+ >>> print(rgb.shape) # (100, 100, 3)
91
+ >>> print(rgb.dtype) # uint8
92
+
93
+ >>> # Example with float alpha values [0, 1]
94
+ >>> rgba_float = np.random.rand(50, 50, 4).astype(np.float32)
95
+ >>> rgb_float = rgba_to_rgb_white_bg(rgba_float)
96
+ >>> print(rgb_float.dtype) # uint8
97
+ """
98
+ # Extract RGB and alpha channels
99
+ rgb = rgba_image[:, :, :3] # RGB channels (H, W, 3)
100
+ alpha = rgba_image[:, :, 3:4] # Alpha channel (H, W, 1)
101
+
102
+ # Normalize alpha to [0, 1] range if it's in [0, 255] range
103
+ if alpha.max() > 1.0:
104
+ alpha = alpha / 255.0
105
+
106
+ # Alpha blend with white background using the formula:
107
+ # result = foreground * alpha + background * (1 - alpha)
108
+ rgb_image = rgb * alpha + 255 * (1 - alpha)
109
+
110
+ # Convert to uint8 format for standard image representation
111
+ return rgb_image.astype(np.uint8)
112
+
113
+
52
114
  def scale_image_to_encoding_size(
53
115
  base64_image: str, max_base64_size: int = 180_000, initial_reduction: float = 0.9, format: str = "PNG", **kwargs
54
116
  ) -> Tuple[str, Tuple[int, int]]:
@@ -93,7 +155,7 @@ def scale_image_to_encoding_size(
93
155
 
94
156
  # Check initial size
95
157
  if len(base64_image) <= max_base64_size:
96
- return base64_image, original_size
158
+ return numpy_to_base64(img_array, format=format, **kwargs), original_size
97
159
 
98
160
  # Initial reduction step
99
161
  reduction_step = initial_reduction
@@ -621,6 +683,10 @@ def base64_to_numpy(base64_string: str) -> np.ndarray:
621
683
  if img is None:
622
684
  raise ValueError("OpenCV failed to decode image")
623
685
 
686
+ # Convert 4 channel to 3 channel if necessary
687
+ if img.shape[2] == 4:
688
+ img = rgba_to_rgb_white_bg(img)
689
+
624
690
  # Convert BGR to RGB for consistent processing (OpenCV loads as BGR)
625
691
  # Only convert if it's a 3-channel color image
626
692
  if img.ndim == 3 and img.shape[2] == 3:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nv-ingest-api
3
- Version: 2025.10.4.dev20251004
3
+ Version: 2025.10.6.dev20251006
4
4
  Summary: Python module with core document ingestion functions.
5
5
  Author-email: Jeremy Dyer <jdyer@nvidia.com>
6
6
  License: Apache License
@@ -128,7 +128,7 @@ nv_ingest_api/util/image_processing/__init__.py,sha256=Jiy8C1ZuSrNb_eBM1ZTV9IKFI
128
128
  nv_ingest_api/util/image_processing/clustering.py,sha256=sUGlZI4cx1q8h4Pns1N9JVpdfSM2BOH8zRmn9QFCtzI,9236
129
129
  nv_ingest_api/util/image_processing/processing.py,sha256=LSoDDEmahr7a-qSS12McVcowRe3dOrAZwa1h-PD_JPQ,6554
130
130
  nv_ingest_api/util/image_processing/table_and_chart.py,sha256=idCIjiLkY-usI2EARchg3omWLtIYmYA-1tdUUV2lbno,16338
131
- nv_ingest_api/util/image_processing/transforms.py,sha256=ygIBf-EWm4mqi1qcnLb-l6TZps8gjotZakxj8ktxdYU,27730
131
+ nv_ingest_api/util/image_processing/transforms.py,sha256=Mj0ry3DzCKY83ZNfvNuAIQBSkRvsxHPe0VAHRJb2BfA,30136
132
132
  nv_ingest_api/util/imports/__init__.py,sha256=wQSlVx3T14ZgQAt-EPzEczQusXVW0W8yynnUaFFGE3s,143
133
133
  nv_ingest_api/util/imports/callable_signatures.py,sha256=ipzXNZJpfu7oeTBrQz2h6zrFVIQaqb2KBpzSuIX3u-Y,4138
134
134
  nv_ingest_api/util/imports/dynamic_resolvers.py,sha256=qy7RpmBZrXJarOQl3J7jiCKnbZMNChXTL_Z-H4c9zlc,6170
@@ -164,10 +164,10 @@ nv_ingest_api/util/string_processing/configuration.py,sha256=2HS08msccuPCT0fn_jf
164
164
  nv_ingest_api/util/string_processing/yaml.py,sha256=6SW2O6wbXRhGbhETMbtXjYCZn53HeCNOP6a96AaxlHs,1454
165
165
  nv_ingest_api/util/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
166
166
  nv_ingest_api/util/system/hardware_info.py,sha256=1UFM8XE6M3pgQcpbVsCsqDQ7Dj-zzptL-XRE-DEu9UA,27213
167
- nv_ingest_api-2025.10.4.dev20251004.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
167
+ nv_ingest_api-2025.10.6.dev20251006.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
168
168
  udfs/__init__.py,sha256=pXFqPgXIUqHDfj7SAR1Q19tt8KwGv_iMvhHyziz4AYM,205
169
169
  udfs/llm_summarizer_udf.py,sha256=sIMfcH4GRyciTKUtq4dmhd6fZmAp07X32irIC4k7nEI,7316
170
- nv_ingest_api-2025.10.4.dev20251004.dist-info/METADATA,sha256=we6OaOQesMnj6J87Fg0W5ZdYcsJ6zOE-30dbrVnoLrI,14085
171
- nv_ingest_api-2025.10.4.dev20251004.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
172
- nv_ingest_api-2025.10.4.dev20251004.dist-info/top_level.txt,sha256=I1lseG9FF0CH93SPx4kFblsxFuv190cfzaas_CLNIiw,19
173
- nv_ingest_api-2025.10.4.dev20251004.dist-info/RECORD,,
170
+ nv_ingest_api-2025.10.6.dev20251006.dist-info/METADATA,sha256=4X9GEbUTJZRTkRQkLy9XR6dblOK6BMwkwU64M_wWNYM,14085
171
+ nv_ingest_api-2025.10.6.dev20251006.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
172
+ nv_ingest_api-2025.10.6.dev20251006.dist-info/top_level.txt,sha256=I1lseG9FF0CH93SPx4kFblsxFuv190cfzaas_CLNIiw,19
173
+ nv_ingest_api-2025.10.6.dev20251006.dist-info/RECORD,,