diff --git a/docs/utils/image.md b/docs/utils/image.md
index 8a6768d7..087aebd7 100644
--- a/docs/utils/image.md
+++ b/docs/utils/image.md
@@ -17,6 +17,12 @@ status: new
:::supervision.utils.image.crop_image
+
+
letterbox_image
+
+
+:::supervision.utils.image.letterbox_image
+
resize_image
diff --git a/supervision/draw/color.py b/supervision/draw/color.py
index 825b0da5..debb46f3 100644
--- a/supervision/draw/color.py
+++ b/supervision/draw/color.py
@@ -104,10 +104,13 @@ class Color:
Create a Color instance from a hex string.
Args:
- color_hex (str): Hex string of the color.
+ color_hex (str): The hex string representing the color. This string can
+ start with '#' followed by either 3 or 6 hexadecimal characters. In
+ case of 3 characters, each character is repeated to form the full
+ 6-character hex code.
Returns:
- Color: Instance representing the color.
+ Color: An instance representing the color.
Example:
```python
@@ -115,6 +118,9 @@ class Color:
sv.Color.from_hex('#ff00ff')
# Color(r=255, g=0, b=255)
+
+ sv.Color.from_hex('#f0f')
+ # Color(r=255, g=0, b=255)
```
"""
_validate_color_hex(color_hex)
@@ -126,11 +132,47 @@ class Color:
@classmethod
def from_rgb_tuple(cls, color_tuple: Tuple[int, int, int]) -> Color:
+ """
+ Create a Color instance from an RGB tuple.
+
+ Args:
+ color_tuple (Tuple[int, int, int]): A tuple representing the color in RGB
+ format, where each element is an integer in the range 0-255.
+
+ Returns:
+ Color: An instance representing the color.
+
+ Example:
+ ```python
+ import supervision as sv
+
+ sv.Color.from_rgb_tuple((255, 255, 0))
+ # Color(r=255, g=255, b=0)
+ ```
+ """
r, g, b = color_tuple
return cls(r=r, g=g, b=b)
@classmethod
def from_bgr_tuple(cls, color_tuple: Tuple[int, int, int]) -> Color:
+ """
+ Create a Color instance from a BGR tuple.
+
+ Args:
+ color_tuple (Tuple[int, int, int]): A tuple representing the color in BGR
+ format, where each element is an integer in the range 0-255.
+
+ Returns:
+ Color: An instance representing the color.
+
+ Example:
+ ```python
+ import supervision as sv
+
+ sv.Color.from_bgr_tuple((0, 255, 255))
+ # Color(r=255, g=255, b=0)
+ ```
+ """
b, g, r = color_tuple
return cls(r=r, g=g, b=b)
diff --git a/supervision/utils/image.py b/supervision/utils/image.py
index c1c6b1cf..30535932 100644
--- a/supervision/utils/image.py
+++ b/supervision/utils/image.py
@@ -79,8 +79,8 @@ def resize_image(image: np.ndarray, scale_factor: float) -> np.ndarray:
Args:
image (np.ndarray): The input image to be resized.
- scale_factor (float): The factor by which the image will be scaled. Scale factor
- > 1.0 zooms in, < 1.0 zooms out.
+ scale_factor (float): The factor by which the image will be scaled. Scale
+ factor > 1.0 zooms in, < 1.0 zooms out.
Returns:
np.ndarray: The resized image.
@@ -571,13 +571,13 @@ def letterbox_image(
Resize and pad image to fit the desired size, preserving its aspect
ratio, adding padding of given color if needed to maintain aspect ratio.
- Parameters:
- - image (np.ndarray): Input image (type will be adjusted by decorator,
- you can provide PIL.Image)
- - desired_size (Tuple[int, int]): image size (width, height) representing
- the target dimensions.
- - color (Union[Tuple[int, int, int], Color]): the color to pad with - If
- tuple provided - should be BGR.
+ Args:
+ image (np.ndarray): Input image (type will be adjusted by decorator,
+ you can provide PIL.Image)
+ desired_size (Tuple[int, int]): image size (width, height) representing
+ the target dimensions.
+ color (Union[Tuple[int, int, int], Color]): the color to pad with - If
+ tuple provided - should be BGR.
Returns:
np.ndarray: letterboxed image (type may be adjusted to PIL.Image by