Drawing#
- kornia.image.draw_line(image, p1, p2, color)[source]#
Draw a single line into an image.
- Parameters:
image (
Tensor) – the input image to where to draw the lines with shape :math`(C,H,W)`.p1 (
Tensor) – the start point [x y] of the line with shape (2, ) or (B, 2).p2 (
Tensor) – the end point [x y] of the line with shape (2, ) or (B, 2).color (
Tensor) – the color of the line with shape :math`(C)` where :math`C` is the number of channels of the image.
- Return type:
- Returns:
the image with containing the line.
Examples
>>> image = torch.zeros(1, 8, 8) >>> draw_line(image, torch.tensor([6, 4]), torch.tensor([1, 4]), torch.tensor([255])) tensor([[[ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 255., 255., 255., 255., 255., 255., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.]]])
- kornia.image.draw_rectangle(image, rectangle, color=None, fill=None)[source]#
Draw N rectangles on a batch of image tensors.
- Parameters:
image (
Tensor) – is tensor of BxCxHxW.rectangle (
Tensor) – represents number of rectangles to draw in BxNx4 N is the number of boxes to draw per batch index[x1, y1, x2, y2] 4 is in (top_left.x, top_left.y, bot_right.x, bot_right.y).color (
Optional[Tensor], optional) – a size 1, size 3, BxNx1, or BxNx3 tensor. If C is 3, and color is 1 channel it will be broadcasted. Default:Nonefill (
Optional[bool], optional) – is a flag used to fill the boxes with color if True. Default:None
- Return type:
- Returns:
This operation modifies image inplace but also returns the drawn tensor for convenience with same shape the of the input BxCxHxW.
Example
>>> img = torch.rand(2, 3, 10, 12) >>> rect = torch.tensor([[[0, 0, 4, 4]], [[4, 4, 10, 10]]]) >>> out = draw_rectangle(img, rect)
- kornia.image.draw_convex_polygon(images, polygons, colors)[source]#
Draws convex polygons on a batch of image tensors.
- Parameters:
- Return type:
- Returns:
This operation modifies image inplace but also returns the drawn tensor for convenience with same shape the of the input BxCxHxW.
Note
This function assumes a coordinate system (0, h - 1), (0, w - 1) in the image, with (0, 0) being the center of the top-left pixel and (w - 1, h - 1) being the center of the bottom-right coordinate.
Example
>>> img = torch.rand(1, 3, 12, 16) >>> poly = torch.tensor([[[4, 4], [12, 4], [12, 8], [4, 8]]]) >>> color = torch.tensor([[0.5, 0.5, 0.5]]) >>> out = draw_convex_polygon(img, poly, color)