Skip to content

Commit c7de70e

Browse files
authored
Merge pull request #1943 from roboflow/docs/refactor_0.27.0
docs/refactor 0.27.0
2 parents 005cdbd + dce96d4 commit c7de70e

File tree

15 files changed

+332
-683
lines changed

15 files changed

+332
-683
lines changed

docs/how_to/process_datasets.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,9 @@ for i in range(16):
331331
annotated_image = label_annotator.annotate(annotated_image, annotations, labels)
332332
annotated_images.append(annotated_image)
333333

334-
grid = sv.create_tiles(
334+
sv.plot_images_grid(
335335
annotated_images,
336336
grid_size=(4, 4),
337-
single_tile_size=(400, 400),
338-
tile_padding_color=sv.Color.WHITE,
339-
tile_margin_color=sv.Color.WHITE
340337
)
341338
```
342339

File renamed without changes.

docs/utils/image.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ comments: true
2929
:::supervision.utils.image.letterbox_image
3030

3131
<div class="md-typeset">
32-
<h2><a href="#supervision.utils.image.overlay_image">overlay_image</a></h2>
32+
<h2><a href="#supervision.utils.image.tint_image">tint_image</a></h2>
3333
</div>
3434

35-
:::supervision.utils.image.overlay_image
35+
:::supervision.utils.image.tint_image
36+
37+
<div class="md-typeset">
38+
<h2><a href="#supervision.utils.image.grayscale_image">grayscale_image</a></h2>
39+
</div>
40+
41+
:::supervision.utils.image.grayscale_image
3642

3743
<div class="md-typeset">
3844
<h2><a href="#supervision.utils.image.ImageSink">ImageSink</a></h2>

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extra:
2626

2727
extra_css:
2828
- stylesheets/extra.css
29-
- stylesheets/cookbooks-card.css
29+
- stylesheets/cookbooks_card.css
3030

3131
nav:
3232
- Home: index.md

supervision/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@
120120
from supervision.utils.file import list_files_with_extensions
121121
from supervision.utils.image import (
122122
ImageSink,
123-
create_tiles,
124123
crop_image,
124+
grayscale_image,
125125
letterbox_image,
126126
overlay_image,
127127
resize_image,
128128
scale_image,
129+
tint_image,
129130
)
130131
from supervision.utils.notebook import plot_image, plot_images_grid
131132
from supervision.utils.video import (
@@ -206,7 +207,6 @@
206207
"clip_boxes",
207208
"contains_holes",
208209
"contains_multiple_segments",
209-
"create_tiles",
210210
"crop_image",
211211
"cv2_to_pillow",
212212
"draw_filled_polygon",
@@ -222,6 +222,7 @@
222222
"get_coco_class_index_mapping",
223223
"get_polygon_center",
224224
"get_video_frames_generator",
225+
"grayscale_image",
225226
"letterbox_image",
226227
"list_files_with_extensions",
227228
"mask_iou_batch",
@@ -245,6 +246,7 @@
245246
"rle_to_mask",
246247
"scale_boxes",
247248
"scale_image",
249+
"tint_image",
248250
"xcycwh_to_xyxy",
249251
"xywh_to_xyxy",
250252
"xyxy_to_polygons",

supervision/annotators/base.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
from abc import ABC, abstractmethod
2-
from typing import TypeVar
3-
4-
import numpy as np
5-
from PIL import Image
62

73
from supervision.detection.core import Detections
8-
9-
ImageType = TypeVar("ImageType", np.ndarray, Image.Image)
10-
"""
11-
An image of type `np.ndarray` or `PIL.Image.Image`.
12-
13-
Unlike a `Union`, ensures the type remains consistent. If a function
14-
takes an `ImageType` argument and returns an `ImageType`, when you
15-
pass an `np.ndarray`, you will get an `np.ndarray` back.
16-
"""
4+
from supervision.draw.base import ImageType
175

186

197
class BaseAnnotator(ABC):

supervision/annotators/core.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from PIL import Image, ImageDraw, ImageFont
1010
from scipy.interpolate import splev, splprep
1111

12-
from supervision.annotators.base import BaseAnnotator, ImageType
12+
from supervision.annotators.base import BaseAnnotator
1313
from supervision.annotators.utils import (
1414
PENDING_TRACK_ID,
1515
ColorLookup,
@@ -29,12 +29,13 @@
2929
polygon_to_mask,
3030
xyxy_to_polygons,
3131
)
32+
from supervision.draw.base import ImageType
3233
from supervision.draw.color import Color, ColorPalette
3334
from supervision.draw.utils import draw_polygon, draw_rounded_rectangle, draw_text
3435
from supervision.geometry.core import Point, Position, Rect
3536
from supervision.utils.conversion import (
36-
ensure_cv2_image_for_annotation,
37-
ensure_pil_image_for_annotation,
37+
ensure_cv2_image_for_class_method,
38+
ensure_pil_image_for_class_method,
3839
)
3940
from supervision.utils.image import (
4041
crop_image,
@@ -177,7 +178,7 @@ def __init__(
177178
self.thickness: int = thickness
178179
self.color_lookup: ColorLookup = color_lookup
179180

180-
@ensure_cv2_image_for_annotation
181+
@ensure_cv2_image_for_class_method
181182
def annotate(
182183
self,
183184
scene: ImageType,
@@ -260,7 +261,7 @@ def __init__(
260261
self.thickness: int = thickness
261262
self.color_lookup: ColorLookup = color_lookup
262263

263-
@ensure_cv2_image_for_annotation
264+
@ensure_cv2_image_for_class_method
264265
def annotate(
265266
self,
266267
scene: ImageType,
@@ -349,7 +350,7 @@ def __init__(
349350
self.opacity = opacity
350351
self.color_lookup: ColorLookup = color_lookup
351352

352-
@ensure_cv2_image_for_annotation
353+
@ensure_cv2_image_for_class_method
353354
def annotate(
354355
self,
355356
scene: ImageType,
@@ -439,7 +440,7 @@ def __init__(
439440
self.thickness: int = thickness
440441
self.color_lookup: ColorLookup = color_lookup
441442

442-
@ensure_cv2_image_for_annotation
443+
@ensure_cv2_image_for_class_method
443444
def annotate(
444445
self,
445446
scene: ImageType,
@@ -526,7 +527,7 @@ def __init__(
526527
self.color_lookup: ColorLookup = color_lookup
527528
self.opacity = opacity
528529

529-
@ensure_cv2_image_for_annotation
530+
@ensure_cv2_image_for_class_method
530531
def annotate(
531532
self,
532533
scene: ImageType,
@@ -622,7 +623,7 @@ def __init__(
622623
self.color_lookup: ColorLookup = color_lookup
623624
self.kernel_size: int = kernel_size
624625

625-
@ensure_cv2_image_for_annotation
626+
@ensure_cv2_image_for_class_method
626627
def annotate(
627628
self,
628629
scene: ImageType,
@@ -722,7 +723,7 @@ def __init__(
722723
self.end_angle: int = end_angle
723724
self.color_lookup: ColorLookup = color_lookup
724725

725-
@ensure_cv2_image_for_annotation
726+
@ensure_cv2_image_for_class_method
726727
def annotate(
727728
self,
728729
scene: ImageType,
@@ -814,7 +815,7 @@ def __init__(
814815
self.corner_length: int = corner_length
815816
self.color_lookup: ColorLookup = color_lookup
816817

817-
@ensure_cv2_image_for_annotation
818+
@ensure_cv2_image_for_class_method
818819
def annotate(
819820
self,
820821
scene: ImageType,
@@ -903,7 +904,7 @@ def __init__(
903904
self.thickness: int = thickness
904905
self.color_lookup: ColorLookup = color_lookup
905906

906-
@ensure_cv2_image_for_annotation
907+
@ensure_cv2_image_for_class_method
907908
def annotate(
908909
self,
909910
scene: ImageType,
@@ -1002,7 +1003,7 @@ def __init__(
10021003
self.outline_thickness = outline_thickness
10031004
self.outline_color: Color | ColorPalette = outline_color
10041005

1005-
@ensure_cv2_image_for_annotation
1006+
@ensure_cv2_image_for_class_method
10061007
def annotate(
10071008
self,
10081009
scene: ImageType,
@@ -1128,7 +1129,7 @@ def __init__(
11281129
max_line_length=max_line_length,
11291130
)
11301131

1131-
@ensure_cv2_image_for_annotation
1132+
@ensure_cv2_image_for_class_method
11321133
def annotate(
11331134
self,
11341135
scene: ImageType,
@@ -1438,7 +1439,7 @@ def __init__(
14381439
max_line_length=max_line_length,
14391440
)
14401441

1441-
@ensure_pil_image_for_annotation
1442+
@ensure_pil_image_for_class_method
14421443
def annotate(
14431444
self,
14441445
scene: ImageType,
@@ -1665,7 +1666,7 @@ def __init__(
16651666
self.position = icon_position
16661667
self.offset_xy = offset_xy
16671668

1668-
@ensure_cv2_image_for_annotation
1669+
@ensure_cv2_image_for_class_method
16691670
def annotate(
16701671
self, scene: ImageType, detections: Detections, icon_path: str | list[str]
16711672
) -> ImageType:
@@ -1754,7 +1755,7 @@ def __init__(self, kernel_size: int = 15):
17541755
"""
17551756
self.kernel_size: int = kernel_size
17561757

1757-
@ensure_cv2_image_for_annotation
1758+
@ensure_cv2_image_for_class_method
17581759
def annotate(
17591760
self,
17601761
scene: ImageType,
@@ -1843,7 +1844,7 @@ def __init__(
18431844
self.smooth = smooth
18441845
self.color_lookup: ColorLookup = color_lookup
18451846

1846-
@ensure_cv2_image_for_annotation
1847+
@ensure_cv2_image_for_class_method
18471848
def annotate(
18481849
self,
18491850
scene: ImageType,
@@ -1965,7 +1966,7 @@ def __init__(
19651966
self.low_hue = low_hue
19661967
self.heat_mask: npt.NDArray[np.float32] | None = None
19671968

1968-
@ensure_cv2_image_for_annotation
1969+
@ensure_cv2_image_for_class_method
19691970
def annotate(self, scene: ImageType, detections: Detections) -> ImageType:
19701971
"""
19711972
Annotates the scene with a heatmap based on the provided detections.
@@ -2047,7 +2048,7 @@ def __init__(self, pixel_size: int = 20):
20472048
"""
20482049
self.pixel_size: int = pixel_size
20492050

2050-
@ensure_cv2_image_for_annotation
2051+
@ensure_cv2_image_for_class_method
20512052
def annotate(
20522053
self,
20532054
scene: ImageType,
@@ -2144,7 +2145,7 @@ def __init__(
21442145
self.outline_thickness: int = outline_thickness
21452146
self.outline_color: Color | ColorPalette = outline_color
21462147

2147-
@ensure_cv2_image_for_annotation
2148+
@ensure_cv2_image_for_class_method
21482149
def annotate(
21492150
self,
21502151
scene: ImageType,
@@ -2256,7 +2257,7 @@ def __init__(
22562257
raise ValueError("roundness attribute must be float between (0, 1.0]")
22572258
self.roundness: float = roundness
22582259

2259-
@ensure_cv2_image_for_annotation
2260+
@ensure_cv2_image_for_class_method
22602261
def annotate(
22612262
self,
22622263
scene: ImageType,
@@ -2396,7 +2397,7 @@ def __init__(
23962397
else int(0.15 * self.height)
23972398
)
23982399

2399-
@ensure_cv2_image_for_annotation
2400+
@ensure_cv2_image_for_class_method
24002401
def annotate(
24012402
self,
24022403
scene: ImageType,
@@ -2577,7 +2578,7 @@ def __init__(
25772578
self.border_thickness: int = border_thickness
25782579
self.border_color_lookup: ColorLookup = border_color_lookup
25792580

2580-
@ensure_cv2_image_for_annotation
2581+
@ensure_cv2_image_for_class_method
25812582
def annotate(
25822583
self,
25832584
scene: ImageType,
@@ -2726,7 +2727,7 @@ def __init__(
27262727
self.opacity = opacity
27272728
self.force_box = force_box
27282729

2729-
@ensure_cv2_image_for_annotation
2730+
@ensure_cv2_image_for_class_method
27302731
def annotate(self, scene: ImageType, detections: Detections) -> ImageType:
27312732
"""
27322733
Applies a colored overlay to the scene outside of the detected regions.
@@ -2824,7 +2825,7 @@ def __init__(
28242825
self.label_scale = label_scale
28252826
self.text_thickness = int(self.label_scale + 1.2)
28262827

2827-
@ensure_cv2_image_for_annotation
2828+
@ensure_cv2_image_for_class_method
28282829
def annotate(
28292830
self, scene: ImageType, detections_1: Detections, detections_2: Detections
28302831
) -> ImageType:

supervision/draw/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import TypeVar
2+
3+
import numpy as np
4+
from PIL import Image
5+
6+
ImageType = TypeVar("ImageType", np.ndarray, Image.Image)
7+
"""
8+
An image of type `np.ndarray` or `PIL.Image.Image`.
9+
10+
Unlike a `Union`, ensures the type remains consistent. If a function
11+
takes an `ImageType` argument and returns an `ImageType`, when you
12+
pass an `np.ndarray`, you will get an `np.ndarray` back.
13+
"""

0 commit comments

Comments
 (0)