pixelflow 0.8.0__tar.gz → 0.9.0__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 (92) hide show
  1. {pixelflow-0.8.0/pixelflow.egg-info → pixelflow-0.9.0}/PKG-INFO +1 -1
  2. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/__init__.py +1 -1
  3. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/media.py +66 -32
  4. {pixelflow-0.8.0 → pixelflow-0.9.0/pixelflow.egg-info}/PKG-INFO +1 -1
  5. {pixelflow-0.8.0 → pixelflow-0.9.0}/LICENSE +0 -0
  6. {pixelflow-0.8.0 → pixelflow-0.9.0}/NOTICE +0 -0
  7. {pixelflow-0.8.0 → pixelflow-0.9.0}/README.md +0 -0
  8. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/__init__.py +0 -0
  9. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/anchors.py +0 -0
  10. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/blur.py +0 -0
  11. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/box.py +0 -0
  12. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/classification.py +0 -0
  13. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/crossing.py +0 -0
  14. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/dot.py +0 -0
  15. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/filled_box.py +0 -0
  16. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/fps_counter.py +0 -0
  17. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/grid_overlay.py +0 -0
  18. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/heatmap.py +0 -0
  19. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/keypoint.py +0 -0
  20. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/keypoint_skeleton.py +0 -0
  21. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/label.py +0 -0
  22. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/mask.py +0 -0
  23. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/motion_dots.py +0 -0
  24. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/motion_trails.py +0 -0
  25. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/oval.py +0 -0
  26. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/pixelate.py +0 -0
  27. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/polygon.py +0 -0
  28. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/scale_bar.py +0 -0
  29. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/utils.py +0 -0
  30. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/annotators/zones.py +0 -0
  31. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/arrays.py +0 -0
  32. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/buffer.py +0 -0
  33. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/classifications/__init__.py +0 -0
  34. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/classifications/classifications.py +0 -0
  35. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/classifications/converters.py +0 -0
  36. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/colors.py +0 -0
  37. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/crossings.py +0 -0
  38. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/detections/__init__.py +0 -0
  39. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/detections/converters.py +0 -0
  40. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/detections/detections.py +0 -0
  41. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/detections/filters.py +0 -0
  42. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/labels.py +0 -0
  43. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/masks.py +0 -0
  44. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/serialization.py +0 -0
  45. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/slicer.py +0 -0
  46. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/smoother.py +0 -0
  47. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/strategies.py +0 -0
  48. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/timer.py +0 -0
  49. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/UPSTREAM.md +0 -0
  50. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/__init__.py +0 -0
  51. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/base.py +0 -0
  52. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/botsort/__init__.py +0 -0
  53. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/botsort/tracker.py +0 -0
  54. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/botsort/tracklet.py +0 -0
  55. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/botsort/utils.py +0 -0
  56. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/bytetrack/__init__.py +0 -0
  57. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/bytetrack/tracker.py +0 -0
  58. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/bytetrack/tracklet.py +0 -0
  59. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/bytetrack/utils.py +0 -0
  60. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/cbiou/__init__.py +0 -0
  61. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/cbiou/tracker.py +0 -0
  62. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/ocsort/__init__.py +0 -0
  63. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/ocsort/tracker.py +0 -0
  64. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/ocsort/tracklet.py +0 -0
  65. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/ocsort/utils.py +0 -0
  66. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/sort/__init__.py +0 -0
  67. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/sort/tracker.py +0 -0
  68. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/sort/tracklet.py +0 -0
  69. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/sort/utils.py +0 -0
  70. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/__init__.py +0 -0
  71. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/base_tracklet.py +0 -0
  72. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/cmc.py +0 -0
  73. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/converters.py +0 -0
  74. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/iou.py +0 -0
  75. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/kalman_filter.py +0 -0
  76. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/matrix.py +0 -0
  77. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/motion_models.py +0 -0
  78. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/predict_timing.py +0 -0
  79. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/scale_aware_tracklet.py +0 -0
  80. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/tracker/utils/state_representations.py +0 -0
  81. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/transforms/__init__.py +0 -0
  82. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/transforms/detections.py +0 -0
  83. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/transforms/image.py +0 -0
  84. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/transforms/inverse.py +0 -0
  85. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/validators.py +0 -0
  86. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow/zones.py +0 -0
  87. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow.egg-info/SOURCES.txt +0 -0
  88. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow.egg-info/dependency_links.txt +0 -0
  89. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow.egg-info/requires.txt +0 -0
  90. {pixelflow-0.8.0 → pixelflow-0.9.0}/pixelflow.egg-info/top_level.txt +0 -0
  91. {pixelflow-0.8.0 → pixelflow-0.9.0}/pyproject.toml +0 -0
  92. {pixelflow-0.8.0 → pixelflow-0.9.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelflow
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Computer vision processing library for visualizing and analyzing detection results from ML models
5
5
  Author-email: Emrah Nazif <emrah@datamarkin.com>
6
6
  License: Apache-2.0
@@ -1,4 +1,4 @@
1
- __version__ = "0.8.0"
1
+ __version__ = "0.9.0"
2
2
  __author__ = "Emrah NAZIF"
3
3
 
4
4
  # Import core modules
@@ -143,8 +143,12 @@ def _resolve_path(source: str) -> Path:
143
143
  # read_image is skipped for it -- which is most of any real dataset.
144
144
  _ALPHA_CAPABLE = frozenset({".png", ".gif", ".webp", ".tif", ".tiff", ".jp2"})
145
145
 
146
+ # Formats that keep an RGBA image's alpha when written. OpenCV writes a 4-channel array
147
+ # to JPEG or BMP too, dropping the alpha without a word, so RGBA goes only to these.
148
+ _ALPHA_WRITABLE = frozenset({".png", ".webp", ".tif", ".tiff"})
146
149
 
147
- def _require_rgb(image, what: str = "frame") -> None:
150
+
151
+ def _require_rgb(image, what: str = "frame", alpha: bool = False) -> None:
148
152
  """Raise unless ``image`` is the RGB uint8 HxWx3 array this library passes around.
149
153
 
150
154
  ``cv2.cvtColor`` accepts a 2D or 4-channel array for ``RGB2BGR`` and quietly
@@ -156,15 +160,19 @@ def _require_rgb(image, what: str = "frame") -> None:
156
160
  BGR are the same bytes in a different sequence, and no inspection recovers which
157
161
  one you have. So every array entering this library is **taken** to be RGB, at
158
162
  every boundary, not just this one.
163
+
164
+ ``alpha=True`` also accepts RGBA uint8 HxWx4, for the encoders, which convert it
165
+ themselves (see ``_to_bgr``). Every other boundary takes RGB only.
159
166
  """
167
+ if alpha:
168
+ expected, channels = "an RGB uint8 HxWx3 or RGBA HxWx4", (3, 4)
169
+ else:
170
+ expected, channels = "an RGB uint8 HxWx3", (3,)
160
171
  if not isinstance(image, np.ndarray):
172
+ raise ValueError(f"expected {expected} {what}, got {type(image).__name__}")
173
+ if image.ndim != 3 or image.shape[2] not in channels or image.dtype != np.uint8:
161
174
  raise ValueError(
162
- f"expected an RGB uint8 HxWx3 {what}, got {type(image).__name__}"
163
- )
164
- if image.ndim != 3 or image.shape[2] != 3 or image.dtype != np.uint8:
165
- raise ValueError(
166
- f"expected an RGB uint8 HxWx3 {what}, got shape {image.shape} "
167
- f"dtype {image.dtype}"
175
+ f"expected {expected} {what}, got shape {image.shape} dtype {image.dtype}"
168
176
  )
169
177
 
170
178
 
@@ -902,8 +910,39 @@ def read_image(source, width=_UNSET) -> np.ndarray:
902
910
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
903
911
 
904
912
 
913
+ def _to_bgr(image, suffix: str) -> np.ndarray:
914
+ """Check an RGB or RGBA image against *suffix* and convert it for OpenCV.
915
+
916
+ RGBA is refused for a format outside ``_ALPHA_WRITABLE`` rather than flattened,
917
+ which would mean choosing a background colour for the caller.
918
+ """
919
+ _require_rgb(image, "image", alpha=True)
920
+ if image.shape[2] == 3:
921
+ return cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
922
+ if suffix.lower() not in _ALPHA_WRITABLE:
923
+ formats = ", ".join(sorted(_ALPHA_WRITABLE))
924
+ raise ValueError(
925
+ f"Cannot encode an RGBA image as {suffix!r}: the format has no transparency. "
926
+ f"Use one of {formats}, or drop the alpha with image[:, :, :3]."
927
+ )
928
+ return cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)
929
+
930
+
931
+ def _imencode(bgr: np.ndarray, suffix: str) -> bytes:
932
+ """``cv2.imencode``, with an unknown format raised as a ValueError."""
933
+ try:
934
+ success, buffer = cv2.imencode(suffix, bgr)
935
+ except cv2.error as error:
936
+ raise ValueError(
937
+ f"Cannot encode {suffix!r}: OpenCV does not support that format"
938
+ ) from error
939
+ if not success:
940
+ raise ValueError(f"Failed to encode image as {suffix!r}")
941
+ return buffer.tobytes()
942
+
943
+
905
944
  def encode_image(image: np.ndarray, extension: str = ".png") -> bytes:
906
- """Encode an RGB image to bytes, for an HTTP response or a blob.
945
+ """Encode an RGB or RGBA image to bytes, for an HTTP response or a blob.
907
946
 
908
947
  The mirror of ``read_image``'s buffer branch, and it exists for the same reason:
909
948
  channel order is established at the codec boundary, so there has to be one
@@ -911,49 +950,45 @@ def encode_image(image: np.ndarray, extension: str = ".png") -> bytes:
911
950
  that goes with it, and that is the step that gets forgotten.
912
951
 
913
952
  Args:
914
- image: RGB uint8 array of shape (H, W, 3).
915
- extension: Container/format extension, with or without the dot.
953
+ image: RGB uint8 array of shape (H, W, 3), or RGBA (H, W, 4), such as a
954
+ cut-out from background removal.
955
+ extension: Container/format extension, with or without the dot. An RGBA
956
+ image needs one that keeps transparency: ``.png``, ``.webp``, ``.tif`` or
957
+ ``.tiff``. WebP does not keep the colour of fully transparent pixels.
916
958
 
917
959
  Returns:
918
960
  The encoded bytes.
919
961
 
920
962
  Raises:
921
- ValueError: If the image is not RGB uint8 HxWx3, or OpenCV cannot encode
963
+ ValueError: If the image is not RGB or RGBA uint8, an RGBA image is given a
964
+ format without transparency (such as ``.jpg``), or OpenCV cannot encode
922
965
  the requested format.
923
966
 
924
967
  Example:
925
968
  >>> payload = pf.encode_image(frame, ".jpg")
926
969
  >>> return Response(payload, media_type="image/jpeg")
927
970
  """
928
- _require_rgb(image, "image")
929
971
  suffix = extension if extension.startswith(".") else f".{extension}"
930
-
931
- bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
932
- try:
933
- success, buffer = cv2.imencode(suffix, bgr)
934
- except cv2.error as error:
935
- raise ValueError(
936
- f"Cannot encode {suffix!r}: OpenCV does not support that format"
937
- ) from error
938
- if not success:
939
- raise ValueError(f"Failed to encode image as {suffix!r}")
940
- return buffer.tobytes()
972
+ return _imencode(_to_bgr(image, suffix), suffix)
941
973
 
942
974
 
943
975
  def save_image(path: str, image: np.ndarray) -> None:
944
- """Save an RGB numpy array to an image file.
976
+ """Save an RGB or RGBA numpy array to an image file.
945
977
 
946
978
  Args:
947
979
  path: Output file path (extension determines format).
948
- image: RGB numpy array.
980
+ image: RGB uint8 array (H, W, 3), or RGBA (H, W, 4) for a format that keeps
981
+ transparency: ``.png``, ``.webp``, ``.tif`` or ``.tiff``.
949
982
 
950
983
  Raises:
951
984
  NotADirectoryError: If the parent directory does not exist.
952
- ValueError: If the image is not RGB uint8 HxWx3, or the extension is
985
+ ValueError: If the image is not RGB or RGBA uint8, an RGBA image is given a
986
+ format without transparency (such as ``.jpg``), or the extension is
953
987
  missing or not one OpenCV can write.
954
988
  OSError: If the file cannot be written for any other reason.
955
989
  """
956
- _require_rgb(image, "image")
990
+ # Checked first, so a bad image is reported before a bad path, as it always was.
991
+ _require_rgb(image, "image", alpha=True)
957
992
  target = Path(path)
958
993
 
959
994
  # cv2.imwrite returns False for a missing directory and raises cv2.error for an
@@ -970,13 +1005,12 @@ def save_image(path: str, image: np.ndarray) -> None:
970
1005
  f"what format to encode. Try '{target.name}.jpg' or '{target.name}.png'."
971
1006
  )
972
1007
 
973
- # Encoding goes through encode_image rather than cv2.imwrite, so that the
974
- # RGB-to-BGR step and the frame guard exist once. A second encoder here would
975
- # be exactly the duplication encode_image was added to remove.
1008
+ # Encoding goes through the same steps as encode_image rather than cv2.imwrite,
1009
+ # so that the colour conversion and the checks exist once.
1010
+ bgr = _to_bgr(image, target.suffix)
976
1011
  try:
977
- payload = encode_image(image, target.suffix)
1012
+ payload = _imencode(bgr, target.suffix)
978
1013
  except ValueError as error:
979
- # The image was checked above, so anything left is the format.
980
1014
  raise ValueError(
981
1015
  f"Cannot write {path!r}: OpenCV cannot encode '{target.suffix}' files"
982
1016
  ) from error
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelflow
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Computer vision processing library for visualizing and analyzing detection results from ML models
5
5
  Author-email: Emrah Nazif <emrah@datamarkin.com>
6
6
  License: Apache-2.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes