π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
add resize augmentation and fixes (#1548)
Edgar Riba95d1828c1448
diff --git a/docs/source/augmentation.base.rst b/docs/source/augmentation.base.rstindex 8cdabcb12..b52f42aef 100644--- a/docs/source/augmentation.base.rst+++ b/docs/source/augmentation.base.rst@@ -1,7 +1,7 @@Base Classes============-.. currentmodule:: kornia.augmentation.base+.. currentmodule:: kornia.augmentationThis is the base class for creating a new transform using `kornia.augmentation`.The user only needs to override: `generate_parameters`, `apply_transform` and optionally, `compute_transformation`.diff --git a/docs/source/augmentation.module.rst b/docs/source/augmentation.module.rstindex bfd63c145..37b26533a 100644--- a/docs/source/augmentation.module.rst+++ b/docs/source/augmentation.module.rst@@ -61,3 +61,10 @@ Normalization operations are shape-agnostic for both 2D and 3D tensors... autoclass:: Denormalize.. autoclass:: Normalize++Image Resize+============++.. autoclass:: Resize+.. autoclass:: LongestMaxSize+.. autoclass:: SmallestMaxSizediff --git a/docs/source/contrib.rst b/docs/source/contrib.rstindex 0b10d432f..96551b205 100644--- a/docs/source/contrib.rst+++ b/docs/source/contrib.rst@@ -48,7 +48,7 @@ Lambda.. autoclass:: LambdaDistance Transform-------+------------------.. autofunction:: distance_transformdiff --git a/docs/source/references.bib b/docs/source/references.bibindex ebbef6f0f..7c3194564 100644--- a/docs/source/references.bib+++ b/docs/source/references.bib@@ -163,12 +163,11 @@doi={10.1109/LSP.2019.2910466}}-@inbook{pham2021dtlayer,- author = {Pham, Duc and Dovletov, Gurbandurdy and Pauli, Josef},- year = {2021},- month = {03},- pages = {432-444},- title = {A Differentiable Convolutional Distance Transform Layer for Improved Image Segmentation},- isbn = {978-3-030-71277-8},- doi = {10.1007/978-3-030-71278-5_31}+@article{pham2021dtlayer,+ title={A Differentiable Convolutional Distance Transform Layer for Improved Image Segmentation},+ author={Duc Duy Pham and Gurbandurdy Dovletov and Josef Pauli},+ journal={Pattern Recognition},+ year={2020},+ volume={12544},+ pages={432 - 444}}diff --git a/kornia/utils/draw.py b/kornia/utils/draw.pyindex 3d01730e5..89deea241 100644--- a/kornia/utils/draw.py+++ b/kornia/utils/draw.py@@ -5,12 +5,7 @@ import torch# TODO: implement width of the line-def _draw_pixel(- image: torch.Tensor,- x: int,- y: int,- color: torch.Tensor,-) -> None:+def _draw_pixel(image: torch.Tensor, x: int, y: int, color: torch.Tensor) -> None:r"""Draws a pixel into an image.Args:@@ -25,12 +20,7 @@ def _draw_pixel(image[:, y, x] = color-def draw_line(- image: torch.Tensor,- p1: torch.Tensor,- p2: torch.Tensor,- color: torch.Tensor,-) -> torch.Tensor:+def draw_line(image: torch.Tensor, p1: torch.Tensor, p2: torch.Tensor, color: torch.Tensor) -> torch.Tensor:r"""Draw a single line into an image.Args:@@ -43,16 +33,16 @@ def draw_line(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.]]])+ >>> 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.]]])"""if (len(p1) != 2) or (len(p2) != 2):@@ -61,7 +51,7 @@ def draw_line(if len(image.size()) != 3:raise ValueError("image must have 3 dimensions (C,H,W).")- if (color.size(0) != image.size(0)):+ if color.size(0) != image.size(0):raise ValueError("color must have the same number of channels as the image.")if (p1[0] >= image.size(2)) or (p1[1] >= image.size(1) or (p1[0] < 0) or (p1[1] < 0)):@@ -84,14 +74,14 @@ def draw_line(C = x2 * y1 - x1 * y2# make sure A is positive to utilize the functiom properly- if (A < 0):+ if A < 0:A = -AB = -BC = -C# calculate the slope of the line# check for division by zero- if (B != 0):+ if B != 0:m = -A / B# make sure you start drawing in the right direction@@ -104,10 +94,10 @@ def draw_line(# vertical lineif B == 0:- image[:, y1:y2 + 1, x1] = color+ image[:, y1 : y2 + 1, x1] = color# horizontal lineelif A == 0:- image[:, y1, x1:x2 + 1] = color+ image[:, y1, x1 : x2 + 1] = color# slope between 0 and 1elif 0 < m < 1:for i in range(x1, x2 + 1):@@ -137,10 +127,7 @@ def draw_line(def draw_rectangle(- image: torch.Tensor,- rectangle: torch.Tensor,- color: Optional[torch.Tensor] = None,- fill: Optional[bool] = None,+ image: torch.Tensor, rectangle: torch.Tensor, color: Optional[torch.Tensor] = None, fill: Optional[bool] = None) -> torch.Tensor:r"""Draw N rectangles on a batch of image tensors.@@ -197,20 +184,20 @@ def draw_rectangle(image[b,:,- int(rectangle[b, n, 1]): int(rectangle[b, n, 3] + 1),- int(rectangle[b, n, 0]): int(rectangle[b, n, 2] + 1),+ int(rectangle[b, n, 1]) : int(rectangle[b, n, 3] + 1),+ int(rectangle[b, n, 0]) : int(rectangle[b, n, 2] + 1),] = color[b, n, :, None, None]else:- image[b, :, int(rectangle[b, n, 1]): int(rectangle[b, n, 3] + 1), rectangle[b, n, 0]] = color[+ image[b, :, int(rectangle[b, n, 1]) : int(rectangle[b, n, 3] + 1), rectangle[b, n, 0]] = color[b, n, :, None]- image[b, :, int(rectangle[b, n, 1]): int(rectangle[b, n, 3] + 1), rectangle[b, n, 2]] = color[+ image[b, :, int(rectangle[b, n, 1]) : int(rectangle[b, n, 3] + 1), rectangle[b, n, 2]] = color[b, n, :, None]- image[b, :, rectangle[b, n, 1], int(rectangle[b, n, 0]): int(rectangle[b, n, 2] + 1)] = color[+ image[b, :, rectangle[b, n, 1], int(rectangle[b, n, 0]) : int(rectangle[b, n, 2] + 1)] = color[b, n, :, None]- image[b, :, rectangle[b, n, 3], int(rectangle[b, n, 0]): int(rectangle[b, n, 2] + 1)] = color[+ image[b, :, rectangle[b, n, 3], int(rectangle[b, n, 0]) : int(rectangle[b, n, 2] + 1)] = color[b, n, :, None]