rslearn.vis.render_vector_image¶
render_vector_image ¶
Functions for rendering vector layers as images (detection, segmentation).
point_to_pixel_coords ¶
point_to_pixel_coords(point: Point, bounds: PixelBounds, image_width: int, image_height: int, actual_width: int, actual_height: int) -> tuple[int, int]
Convert a point's coordinates to pixel coordinates in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
Shapely Point object |
required |
bounds
|
PixelBounds
|
Pixel bounds of the window |
required |
image_width
|
int
|
Width of the image in pixels |
required |
image_height
|
int
|
Height of the image in pixels |
required |
actual_width
|
int
|
Actual width of the data (bounds[2] - bounds[0]) |
required |
actual_height
|
int
|
Actual height of the data (bounds[3] - bounds[1]) |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (pixel_x, pixel_y) coordinates |
Source code in rslearn/vis/render_vector_image.py
draw_bounding_box_around_point ¶
draw_bounding_box_around_point(draw: ImageDraw, px: int, py: int, width: int, height: int, color: tuple[int, int, int], box_size: int = 20) -> bool
Draw a bounding box around a point on an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
ImageDraw
|
PIL ImageDraw object |
required |
px
|
int
|
Pixel x coordinate |
required |
py
|
int
|
Pixel y coordinate |
required |
width
|
int
|
Image width |
required |
height
|
int
|
Image height |
required |
color
|
tuple[int, int, int]
|
RGB color tuple for the bounding box |
required |
box_size
|
int
|
Size of the bounding box in pixels (default 20) |
20
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the point was drawn (within bounds), False otherwise |
Source code in rslearn/vis/render_vector_image.py
overlay_points_on_image ¶
overlay_points_on_image(draw: ImageDraw, features: list[Feature], bounds: PixelBounds, image_width: int, image_height: int, actual_width: int, actual_height: int, label_colors: dict[str, tuple[int, int, int]], class_property_name: str | None = None) -> None
Overlay point features on an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
ImageDraw
|
PIL ImageDraw object |
required |
features
|
list[Feature]
|
List of Feature objects (points) |
required |
bounds
|
PixelBounds
|
Pixel bounds of the window |
required |
image_width
|
int
|
Width of the image in pixels |
required |
image_height
|
int
|
Height of the image in pixels |
required |
actual_width
|
int
|
Actual width of the data (bounds[2] - bounds[0]) |
required |
actual_height
|
int
|
Actual height of the data (bounds[3] - bounds[1]) |
required |
label_colors
|
dict[str, tuple[int, int, int]]
|
Dictionary mapping label class names to RGB colors |
required |
class_property_name
|
str | None
|
Property name to use for label extraction (from config) |
None
|
Source code in rslearn/vis/render_vector_image.py
render_detection ¶
render_detection(features: list[Feature], window: Window, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]], dataset: Dataset | None = None, bands: dict[str, list[str]] | None = None, raster_render: dict[str, dict[str, Any]] | None = None) -> ndarray
Render vector labels for detection (overlay points on reference raster or blank background).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[Feature]
|
List of Feature objects (points) |
required |
window
|
Window
|
Window object |
required |
layer_config
|
LayerConfig
|
LayerConfig object |
required |
label_colors
|
dict[str, tuple[int, int, int]]
|
Dictionary mapping label class names to RGB colors |
required |
dataset
|
Dataset | None
|
Dataset object (for reading reference raster) |
None
|
bands
|
dict[str, list[str]] | None
|
Dictionary mapping item_group_name -> list of band names |
None
|
raster_render
|
dict[str, dict[str, Any]] | None
|
Dictionary mapping item_group_name -> render spec dict |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, 3) as uint8 |
Source code in rslearn/vis/render_vector_image.py
render_segmentation ¶
render_segmentation(features: list[Feature], window: Window, layer_config: LayerConfig, label_colors: dict[str, tuple[int, int, int]], dataset: Dataset | None = None, bands: dict[str, list[str]] | None = None, raster_render: dict[str, dict[str, Any]] | None = None) -> ndarray
Render vector labels for segmentation (draw polygons on mask).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[Feature]
|
List of Feature objects (polygons) |
required |
window
|
Window
|
Window object |
required |
layer_config
|
LayerConfig
|
LayerConfig object |
required |
label_colors
|
dict[str, tuple[int, int, int]]
|
Dictionary mapping label class names to RGB colors |
required |
dataset
|
Dataset | None
|
Dataset object (unused) |
None
|
bands
|
dict[str, list[str]] | None
|
Dictionary mapping item_group_name -> list of band names (unused) |
None
|
raster_render
|
dict[str, dict[str, Any]] | None
|
Dictionary mapping item_group_name -> render spec dict (unused) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with shape (height, width, 3) as uint8 |
Source code in rslearn/vis/render_vector_image.py
render_vector_image ¶
render_vector_image(window: Window, layer_name: str, layer_config: LayerConfig, render_spec: dict[str, Any], label_colors: dict[str, tuple[int, int, int]], dataset: Dataset | None = None, group_idx: int = 0, bands: dict[str, list[str]] | None = None, raster_render: dict[str, dict[str, Any]] | None = None) -> ndarray
Dispatch to the appropriate vector image render function.
Reads the vector features and passes them to the render function selected by render_spec["name"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
Window
|
Window object |
required |
layer_name
|
str
|
Layer name |
required |
layer_config
|
LayerConfig
|
LayerConfig object |
required |
render_spec
|
dict[str, Any]
|
Dict with "name" key and optional "args" dict |
required |
label_colors
|
dict[str, tuple[int, int, int]]
|
Dictionary mapping label class names to RGB colors |
required |
dataset
|
Dataset | None
|
Dataset object (needed for detection reference raster) |
None
|
group_idx
|
int
|
Item group index |
0
|
bands
|
dict[str, list[str]] | None
|
Dictionary mapping item_group_name -> list of band names |
None
|
raster_render
|
dict[str, dict[str, Any]] | None
|
Dictionary mapping item_group_name -> render spec dict |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Rendered image array (H, W, 3) uint8 |