From 2ef029ef4bc64e361e5b0779d12e1231616ab23c Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Thu, 7 Aug 2025 13:32:44 +0200 Subject: [PATCH 1/2] visualize examples --- docs/utils/image.md | 1 + supervision/utils/image.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/utils/image.md b/docs/utils/image.md index a24d19dd..17d94eac 100644 --- a/docs/utils/image.md +++ b/docs/utils/image.md @@ -1,5 +1,6 @@ --- comments: true +status: new --- # Image Utils diff --git a/supervision/utils/image.py b/supervision/utils/image.py index c5c84388..7b53937a 100644 --- a/supervision/utils/image.py +++ b/supervision/utils/image.py @@ -41,7 +41,7 @@ def crop_image( image.shape # (1080, 1920, 3) - xyxy = (200, 400, 600, 800) + xyxy = (400, 400, 800, 800) cropped_image = sv.crop_image(image=image, xyxy=xyxy) cropped_image.shape # (400, 400, 3) @@ -55,12 +55,14 @@ def crop_image( image.size # (1920, 1080) - xyxy = (200, 400, 600, 800) + xyxy = (400, 400, 800, 800) cropped_image = sv.crop_image(image=image, xyxy=xyxy) cropped_image.size # (400, 400) ``` - """ + + ![crop-image](https://media.roboflow.com/supervision-docs/supervision-docs-crop-image-2.png){ align=center width="1000" } + """ # noqa E501 // docs if isinstance(xyxy, (list, tuple)): xyxy = np.array(xyxy) xyxy = np.round(xyxy).astype(int) @@ -110,7 +112,9 @@ def scale_image(image: ImageType, scale_factor: float) -> ImageType: scaled_image.size # (960, 540) ``` - """ + + ![scale-image](https://media.roboflow.com/supervision-docs/supervision-docs-scale-image-2.png){ align=center width="1000" } + """ # noqa E501 // docs if scale_factor <= 0: raise ValueError("Scale factor must be positive.") @@ -170,7 +174,7 @@ def resize_image( # (1000, 562) ``` - ![resize_image](https://media.roboflow.com/supervision-docs/resize-image.png){ align=center width="800" } + ![resize-image](https://media.roboflow.com/supervision-docs/supervision-docs-resize-image-2.png){ align=center width="1000" } """ # noqa E501 // docs if keep_aspect_ratio: image_ratio = image.shape[1] / image.shape[0] @@ -238,7 +242,7 @@ def letterbox_image( # (1000, 1000) ``` - ![letterbox_image](https://media.roboflow.com/supervision-docs/letterbox-image.png){ align=center width="800" } + ![letterbox-image](https://media.roboflow.com/supervision-docs/supervision-docs-letterbox-image-2.png){ align=center width="1000" } """ # noqa E501 // docs assert isinstance(image, np.ndarray) color = unify_to_bgr(color=color) @@ -389,7 +393,7 @@ def tint_image( image = cv2.imread("source.png") tinted_image = sv.tint_image( - image=image, color=sv.Color.BLACK, opacity=0.5 + image=image, color=sv.Color.ROBOFLOW, opacity=0.5 ) cv2.imwrite("target.png", tinted_image) ``` @@ -400,11 +404,13 @@ def tint_image( image = Image.open("source.png") tinted_image = sv.tint_image( - image=image, color=sv.Color.BLACK, opacity=0.5 + image=image, color=sv.Color.ROBOFLOW, opacity=0.5 ) tinted_image.save("target.png") ``` - """ + + ![tint-image](https://media.roboflow.com/supervision-docs/supervision-docs-tint-image-2.png){ align=center width="1000" } + """ # noqa E501 // docs if not 0.0 <= opacity <= 1.0: raise ValueError("opacity must be between 0.0 and 1.0") @@ -452,7 +458,9 @@ def grayscale_image(image: ImageType) -> ImageType: grayscale_image = sv.grayscale_image(image=image) grayscale_image.save("target.png") ``` - """ + + ![grayscale-image](https://media.roboflow.com/supervision-docs/supervision-docs-grayscale-image-2.png){ align=center width="1000" } + """ # noqa E501 // docs grayscaled = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) return cv2.cvtColor(grayscaled, cv2.COLOR_GRAY2BGR) From 6679b1f5a9353776d78b7fa9ccafc099e4f7628b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:45:31 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/utils/image.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/supervision/utils/image.py b/supervision/utils/image.py index 7b53937a..e8931f21 100644 --- a/supervision/utils/image.py +++ b/supervision/utils/image.py @@ -173,7 +173,7 @@ def resize_image( resized_image.size # (1000, 562) ``` - + ![resize-image](https://media.roboflow.com/supervision-docs/supervision-docs-resize-image-2.png){ align=center width="1000" } """ # noqa E501 // docs if keep_aspect_ratio: @@ -241,7 +241,7 @@ def letterbox_image( letterboxed_image.size # (1000, 1000) ``` - + ![letterbox-image](https://media.roboflow.com/supervision-docs/supervision-docs-letterbox-image-2.png){ align=center width="1000" } """ # noqa E501 // docs assert isinstance(image, np.ndarray) @@ -416,12 +416,7 @@ def tint_image( overlay = np.full_like(image, fill_value=color.as_bgr(), dtype=image.dtype) cv2.addWeighted( - src1=overlay, - alpha=opacity, - src2=image, - beta=1 - opacity, - gamma=0, - dst=image + src1=overlay, alpha=opacity, src2=image, beta=1 - opacity, gamma=0, dst=image ) return image @@ -458,7 +453,7 @@ def grayscale_image(image: ImageType) -> ImageType: grayscale_image = sv.grayscale_image(image=image) grayscale_image.save("target.png") ``` - + ![grayscale-image](https://media.roboflow.com/supervision-docs/supervision-docs-grayscale-image-2.png){ align=center width="1000" } """ # noqa E501 // docs grayscaled = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)