Repository: kornia/kornia

Issue:
kornia.utils.draw_line produce wrong output for coordinates larger than uint8
### Describe the bug

Hi, I'm using `kornia.utils.draw_line` to draw a simple line but it's producing incorrect output for coordinates larger than `uint8`

For example:
- An image with shape `3, 800, 800`
- Draw a line from `500, 500` to `600, 600`

And `kornia.utils.draw_line` will produce an output like this:
![wrong](https://user-images.githubusercontent.com/26834698/152783200-f6ae6636-3f9f-48c5-af94-148e1238b04f.jpg)

Which is totally wrong and should looks like this:
![correct](https://user-images.githubusercontent.com/26834698/152783221-1d7c5d3c-9805-416c-943d-9c8a07de0278.jpg)


### Reproduction steps
Run this code snippet:
```python3
import cv2
import torch
from kornia.utils.draw import draw_line

img = torch.ones(3, 800, 800) * 255
img = img.to(torch.uint8)
a = torch.tensor([500, 500])
b = torch.tensor([600, 600])
color = torch.tensor([0, 0, 0])

img = draw_line(img, a, b, color)
img = img.permute(1, 2, 0).numpy()
cv2.imwrite('test.jpg', img)
```

You will get the output image in the description above

### Expected behavior

Can draw the line correctly like the example had shown above

### Environment

```console
Collecting environment information...
PyTorch version: 1.8.2
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.9

Python version: 3.6.15 | packaged by conda-forge | (default, Dec  3 2021, 18:49:41)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-96-generic-x86_64-with-debian-bullseye-sid
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 1080 Ti
Nvidia driver version: 460.84
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] torch==1.8.2
[pip3] torch-ort==1.9.0
[pip3] torchaudio==0.8.2
[pip3] torchvision==0.9.2
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.1.74              h6bb024c_0    nvidia
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py36he8ac12f_0  
[conda] mkl_fft                   1.3.0            py36h54f3939_0  
[conda] mkl_random                1.1.1            py36h0573a6f_0  
[conda] numpy                     1.19.5                   pypi_0    pypi
[conda] numpy-base                1.19.2           py36hfa32c7d_0  
[conda] pytorch                   1.8.2           py3.6_cuda11.1_cudnn8.0.5_0    pytorch-lts
[conda] torch-ort                 1.9.0                    pypi_0    pypi
[conda] torchaudio                0.8.2                      py36    pytorch-lts
[conda] torchvision               0.9.2                py36_cu111    pytorch-lts
```


### Additional context

I had found the problem due to a wrong type conversion. I will send in a PR ASAP
kornia.utils.draw_line produce wrong output for coordinates larger than uint8
### Describe the bug

Hi, I'm using `kornia.utils.draw_line` to draw a simple line but it's producing incorrect output for coordinates larger than `uint8`

For example:
- An image with shape `3, 800, 800`
- Draw a line from `500, 500` to `600, 600`

And `kornia.utils.draw_line` will produce an output like this:
![wrong](https://user-images.githubusercontent.com/26834698/152783200-f6ae6636-3f9f-48c5-af94-148e1238b04f.jpg)

Which is totally wrong and should looks like this:
![correct](https://user-images.githubusercontent.com/26834698/152783221-1d7c5d3c-9805-416c-943d-9c8a07de0278.jpg)


### Reproduction steps
Run this code snippet:
```python3
import cv2
import torch
from kornia.utils.draw import draw_line

img = torch.ones(3, 800, 800) * 255
img = img.to(torch.uint8)
a = torch.tensor([500, 500])
b = torch.tensor([600, 600])
color = torch.tensor([0, 0, 0])

img = draw_line(img, a, b, color)
img = img.permute(1, 2, 0).numpy()
cv2.imwrite('test.jpg', img)
```

You will get the output image in the description above

### Expected behavior

Can draw the line correctly like the example had shown above

### Environment

```console
Collecting environment information...
PyTorch version: 1.8.2
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.9

Python version: 3.6.15 | packaged by conda-forge | (default, Dec  3 2021, 18:49:41)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-96-generic-x86_64-with-debian-bullseye-sid
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 1080 Ti
Nvidia driver version: 460.84
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] torch==1.8.2
[pip3] torch-ort==1.9.0
[pip3] torchaudio==0.8.2
[pip3] torchvision==0.9.2
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.1.74              h6bb024c_0    nvidia
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py36he8ac12f_0  
[conda] mkl_fft                   1.3.0            py36h54f3939_0  
[conda] mkl_random                1.1.1            py36h0573a6f_0  
[conda] numpy                     1.19.5                   pypi_0    pypi
[conda] numpy-base                1.19.2           py36hfa32c7d_0  
[conda] pytorch                   1.8.2           py3.6_cuda11.1_cudnn8.0.5_0    pytorch-lts
[conda] torch-ort                 1.9.0                    pypi_0    pypi
[conda] torchaudio                0.8.2                      py36    pytorch-lts
[conda] torchvision               0.9.2                py36_cu111    pytorch-lts
```


### Additional context

I had found the problem due to a wrong type conversion. I will send in a PR ASAP


Discussion:

Resolving patch:
diff --git a/kornia/utils/draw.py b/kornia/utils/draw.py
--- a/kornia/utils/draw.py
+++ b/kornia/utils/draw.py
@@ -60,8 +60,11 @@ def draw_line(image: torch.Tensor, p1: torch.Tensor, p2: torch.Tensor, color: to
     if (p2[0] >= image.size(2)) or (p2[1] >= image.size(1) or (p2[0] < 0) or (p2[1] < 0)):
         raise ValueError("p2 is out of bounds.")
 
-    # make move arguments to same device and dtype as the input image
-    p1, p2, color = p1.to(image), p2.to(image), color.to(image)
+    # move p1 and p2 to the same device as the input image
+    # move color to the same device and dtype as the input image
+    p1 = p1.to(image.device).to(torch.int64)
+    p2 = p2.to(image.device).to(torch.int64)
+    color = color.to(image)
 
     # assign points
     x1, y1 = p1


Test patch:
diff --git a/test/utils/test_draw.py b/test/utils/test_draw.py
--- a/test/utils/test_draw.py
+++ b/test/utils/test_draw.py
@@ -39,6 +39,14 @@ def test_draw_line_horizontal(self, dtype, device):
         ]], device=device, dtype=dtype)
         assert_close(img, img_mask)
 
+    def test_draw_line_with_big_coordinates(self, dtype, device):
+        """Test drawing a line with big coordinates."""
+        img = torch.zeros(1, 500, 500, dtype=dtype, device=device)
+        img = draw_line(img, torch.tensor([200, 200]), torch.tensor([400, 200]), torch.tensor([255]))
+        img_mask = torch.zeros(1, 500, 500, dtype=dtype, device=device)
+        img_mask[:, 200, 200:401] = 255
+        assert_close(img, img_mask)
+
     def test_draw_line_m_lte_neg1(self, dtype, device):
         """Test drawing a line with m <= -1."""
         img = torch.zeros(1, 8, 8, dtype=dtype, device=device)