Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

remove tutorials files (#1149)

Edgar Riba1f43c0d4147d
diff --git a/tutorials/README.rst b/tutorials/README.rst
deleted file mode 100644
index e1b56b8f3..000000000
--- a/tutorials/README.rst
+++ /dev/null
@@ -1,4 +0,0 @@
-Tutorials
-=========
-
-This page contains the tutorials about Kornia.
diff --git a/tutorials/color_adjust.py b/tutorials/color_adjust.py
deleted file mode 100644
index 7e7902601..000000000
--- a/tutorials/color_adjust.py
+++ /dev/null
@@ -1,67 +0,0 @@
-"""
-Color adjustment
-================
-
-In this tutorial we are going to learn how to adjust the color in image batches.
-
-"""
-
-import cv2
-import numpy as np
-import torch
-import torchvision
-from matplotlib import pyplot as plt
-
-import kornia
-
-#############################
-# We use OpenCV to load an image to memory represented in a numpy.ndarray
-img_bgr: np.ndarray = cv2.imread('./data/ninja_turtles.jpg', cv2.IMREAD_COLOR)
-
-#############################
-# Convert the numpy array to torch
-x_bgr: torch.Tensor = kornia.image_to_tensor(img_bgr)
-x_rgb: torch.Tensor = kornia.bgr_to_rgb(x_bgr)
-
-#############################
-# Create batch and normalize
-x_rgb = x_rgb.expand(4, -1, -1, -1) # 4xCxHxW
-x_rgb = x_rgb.float() / 255.0
-
-
-def imshow(input: torch.Tensor):
- out: torch.Tensor = torchvision.utils.make_grid(input, nrow=2, padding=5)
- out_np: np.ndarray = kornia.tensor_to_image(out)
- plt.imshow(out_np)
- plt.axis('off')
- plt.show()
-
-
-#############################
-# Show original
-imshow(x_rgb)
-
-#############################
-# Adjust Brightness
-x_brightness: torch.Tensor = kornia.adjust_brightness(x_rgb, 0.6)
-imshow(x_brightness)
-
-#############################
-# Adjust Contrast
-x_contrast: torch.Tensor = kornia.adjust_contrast(x_rgb, 0.2)
-imshow(x_contrast)
-
-#############################
-# Adjust Gamma
-x_gamma: torch.Tensor = kornia.adjust_gamma(x_rgb, gamma=3.0, gain=1.5)
-imshow(x_gamma)
-
-#############################
-# Adjust Saturation
-x_saturated: torch.Tensor = kornia.adjust_saturation(x_rgb, 0.2)
-imshow(x_saturated)
-
-#############################
-# Adjust Hue
-x_hue: torch.Tensor = kornia.adjust_hue(x_rgb, 0.5)
-imshow(x_hue)
diff --git a/tutorials/color_conversions.py b/tutorials/color_conversions.py
deleted file mode 100644
index 369d17654..000000000
--- a/tutorials/color_conversions.py
+++ /dev/null
@@ -1,77 +0,0 @@
-"""
-Color space conversions
-=======================
-
-In this tutorial we are going to learn how to convert image from different image spaces using `kornia.color`.
-
-"""
-
-import cv2
-import numpy as np
-import torch
-import torchvision
-from matplotlib import pyplot as plt
-
-import kornia
-
-#############################
-# We use OpenCV to load an image to memory represented in a numpy.ndarray
-img_bgr: np.ndarray = cv2.imread('./data/simba.png', cv2.IMREAD_COLOR)
-
-#############################
-# Convert the numpy array to torch
-x_bgr: torch.Tensor = kornia.image_to_tensor(img_bgr, keepdim=False)
-
-#############################
-# Using `kornia` we easily perform color transformation in batch mode.
-
-
-def hflip(input: torch.Tensor) -> torch.Tensor:
- return torch.flip(input, [-1])
-
-
-def vflip(input: torch.Tensor) -> torch.Tensor:
- return torch.flip(input, [-2])
-
-
-def rot180(input: torch.Tensor) -> torch.Tensor:
- return torch.flip(input, [-2, -1])
-
-
-def imshow(input: torch.Tensor):
- out: torch.Tensor = torchvision.utils.make_grid(input, nrow=2, padding=5)
- out_np: np.ndarray = kornia.tensor_to_image(out)
- plt.imshow(out_np)
- plt.axis('off')
- plt.show()
-
-
-#############################
-# Create a batch of images
-xb_bgr = torch.cat([x_bgr, hflip(x_bgr), vflip(x_bgr), rot180(x_bgr)])
-imshow(xb_bgr)
-
-#############################
-# Convert BGR to RGB
-xb_rgb = kornia.bgr_to_rgb(xb_bgr)
-imshow(xb_rgb)
-
-#############################
-# Convert RGB to grayscale
-# NOTE: image comes in torch.uint8, and kornia assumes floating point type
-xb_gray = kornia.rgb_to_grayscale(xb_rgb.float() / 255.0)
-imshow(xb_gray)
-
-#############################
-# Convert RGB to HSV
-xb_hsv = kornia.rgb_to_hsv(xb_rgb.float() / 255.0)
-imshow(xb_hsv[:, 2:3])
-
-#############################
-# Convert RGB to YUV
-# NOTE: image comes in torch.uint8, and kornia assumes floating point type
-yuv = kornia.rgb_to_yuv(xb_rgb.float() / 255.0)
-y_channel = torchvision.utils.make_grid(yuv, nrow=2)[0, :, :]
-plt.imshow(y_channel, cmap='gray', vmin=0, vmax=1) # Displaying only y channel
-plt.axis('off')
-plt.show()
diff --git a/tutorials/data/arturito.jpeg b/tutorials/data/arturito.jpeg
deleted file mode 100644
index d2900d13c..000000000
Binary files a/tutorials/data/arturito.jpeg and /dev/null differ
diff --git a/tutorials/data/bennett_aden.png b/tutorials/data/bennett_aden.png
deleted file mode 100644
index d147ea1d1..000000000
Binary files a/tutorials/data/bennett_aden.png and /dev/null differ
diff --git a/tutorials/data/bruce.png b/tutorials/data/bruce.png
deleted file mode 100644
index eb80bde86..000000000
Binary files a/tutorials/data/bruce.png and /dev/null differ
diff --git a/tutorials/data/doraemon.png b/tutorials/data/doraemon.png
deleted file mode 100644
index a5c8a0261..000000000
Binary files a/tutorials/data/doraemon.png and /dev/null differ
diff --git a/tutorials/data/drslump.jpg b/tutorials/data/drslump.jpg
deleted file mode 100644
index a2e5bb91c..000000000
Binary files a/tutorials/data/drslump.jpg and /dev/null differ
diff --git a/tutorials/data/ninja_turtles.jpg b/tutorials/data/ninja_turtles.jpg
deleted file mode 100644
index d344a146d..000000000
Binary files a/tutorials/data/ninja_turtles.jpg and /dev/null differ
diff --git a/tutorials/data/pinhole_model.png b/tutorials/data/pinhole_model.png
deleted file mode 100644
index 45350574c..000000000
Binary files a/tutorials/data/pinhole_model.png and /dev/null differ
diff --git a/tutorials/data/simba.png b/tutorials/data/simba.png
deleted file mode 100644
index 076497457..000000000
Binary files a/tutorials/data/simba.png and /dev/null differ
diff --git a/tutorials/data_augmentation.py b/tutorials/data_augmentation.py
deleted file mode 100644
index 5bfba8d0e..000000000
--- a/tutorials/data_augmentation.py
+++ /dev/null
@@ -1,69 +0,0 @@
-"""
-Data augmentation on the GPU
-============================
-
-In this data you learn how to use `kornia` modules in order to perform the data augmentatio on the GPU in batch mode.
-"""
-
-################################
-# 1. Create a dummy data loader
-
-import torch
-import torch.nn as nn
-from torch.utils.data import DataLoader, Dataset
-
-# from: https://gist.github.com/edgarriba/a781de516c508826f79568d08598efdb
-
-
-class DummyDataset(Dataset):
- def __init__(self, data_root=None):
- self.data_root = data_root
- self.data_index = self.build_index(self.data_root)
-
- def build_index(self, data_root):
- return range(10)
-
- def __len__(self):
- return len(self.data_index)
-
- def __getitem__(self, idx):
- # get data sample
- sample = self.data_index[idx]
-
- # load data, NOTE: modify by cv2.imread(...)
- image = torch.rand(3, 240, 320)
- label = torch.rand(1, 240, 320)
- return dict(images=image, labels=label)
-
-
-################################
-# 2. Define the data augmentation operations
-# Thanks to the `kornia` design all the operators can be placed inside inside a `nn.Sequential`.
-
-import kornia
-
-transform = nn.Sequential(
- kornia.enhance.AdjustBrightness(0.5), kornia.enhance.AdjustGamma(gamma=2.0), kornia.enhance.AdjustContrast(0.7)
-)
-
-################################
-# 3. Run the dataset and perform the data augmentation
-
-# NOTE: change device to 'cuda'
-device = torch.device('cpu')
-print(f"Running with device: {device}")
-
-# create the dataloader
-dataset = DummyDataset()
-dataloader = DataLoader(dataset, batch_size=4, shuffle=True)
-
-# get samples and perform the data augmentation
-for i_batch, sample_batched in enumerate(dataloader):
- images = sample_batched['images'].to(device)
- labels = sample_batched['labels'].to(device)
-
- # perform the transforms
- images = transform(images)
- labels = transform(labels)
-
- print(f"Iteration: {i_batch} Image shape: {images.shape}")
diff --git a/tutorials/filter_blurring.py b/tutorials/filter_blurring.py
deleted file mode 100644
index 5d0e397f0..000000000
--- a/tutorials/filter_blurring.py
+++ /dev/null
@@ -1,56 +0,0 @@
-"""
-Filtering Operations
-====================
-
-In this tutorial you are going to learn how to use the different filtering operations found in `kornia.filters`.
-
-"""
-
-import cv2
-import numpy as np
-import torch
-import torchvision
-from matplotlib import pyplot as plt
-
-import kornia
-
-#############################
-# We use OpenCV to load an image to memory represented in a numpy.ndarray
-img_bgr: np.ndarray = cv2.imread('./data/drslump.jpg', cv2.IMREAD_COLOR)
-
-#############################
-# Convert the numpy array to torch
-x_bgr: torch.Tensor = kornia.image_to_tensor(img_bgr)
-x_rgb: torch.Tensor = kornia.bgr_to_rgb(x_bgr)
-
-#############################
-# Create batch and normalize
-x_rgb = x_rgb.expand(2, -1, -1, -1) # 4xCxHxW
-x_rgb = x_rgb.float() / 255.0
-
-
-def imshow(input: torch.Tensor):
- out: torch.Tensor = torchvision.utils.make_grid(input, nrow=2, padding=1)
- out_np: np.ndarray = kornia.tensor_to_image(out)
- plt.imshow(out_np)
- plt.axis('off')
-
-
-#############################
-# Show original
-imshow(x_rgb)
-
-#############################
-# Box Blur
-x_blur: torch.Tensor = kornia.box_blur(x_rgb, (9, 9))
-imshow(x_blur)
-
-#############################
-# Median Blur
-x_blur: torch.Tensor = kornia.median_blur(x_rgb, (5, 5))
-imshow(x_blur)
-
-#############################
-# Gaussian Blur
-x_blur: torch.Tensor = kornia.gaussian_blur2d(x_rgb, (11, 11), (11.0, 11.0))
-imshow(x_blur)
diff --git a/tutorials/filter_edges.py b/tutorials/filter_edges.py
deleted file mode 100644
index 79ba3c693..000000000
--- a/tutorials/filter_edges.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""
-Compute filter edges
-====================
-
-In this tutorial we are going to learn how to compute the first order and second
-order derivatives of an image using `kornia.filters`.
-"""
-
-import cv2
-import numpy as np
-import torch
-import torchvision
-from matplotlib import pyplot as plt
-
-import kornia
-
-#############################
-# We use OpenCV to load an image to memory represented in a numpy.ndarray
-img_bgr: np.ndarray = cv2.imread('./data/doraemon.png', cv2.IMREAD_COLOR)
-
-#############################
-# Convert the numpy array to torch
-x_bgr: torch.Tensor = kornia.image_to_tensor(img_bgr)
-x_rgb: torch.Tensor = kornia.bgr_to_rgb(x_bgr)
-
-#############################
-# Create batch and normalize
-x_rgb = x_rgb.expand(2, -1, -1, -1) # 4xCxHxW
-x_gray = kornia.rgb_to_grayscale(x_rgb.float() / 255.0)
-
-
-def imshow(input: torch.Tensor):
- out: torch.Tensor = torchvision.utils.make_grid(input, nrow=2, padding=1)
- out_np: np.ndarray = kornia.tensor_to_image(out)
- plt.imshow(out_np)
- plt.axis('off')
-
-
-#############################
-# Show original
-imshow(x_rgb)
-
-#################################
-# Compute the 1st order derivates
-grads: torch.Tensor = kornia.spatial_gradient(x_gray, order=1) # BxCx2xHxW
-grads_x = grads[:, :, 0]
-grads_y = grads[:, :, 1]
-
-#################################
-# Show first derivatives in x
-imshow(grads_x)
-
-#################################
-# Show first derivatives in y
-imshow(grads_y)
-
-#################################
-# Sobel Edges
-# Once with the gradients in the two directions we can computet the Sobel edges.
-# However, in kornia we already have it implemented.
-x_sobel: torch.Tensor = kornia.sobel(x_gray)
-imshow(x_sobel)
-
-#################################
-# Compute the 2nd order derivates
-grads: torch.Tensor = kornia.spatial_gradient(x_gray, order=2) # BxCx2xHxW
-grads_x = grads[:, :, 0]
-grads_y = grads[:, :, 1]
-
-#################################
-# Show second derivatives in x
-imshow(grads_x)
-
-#################################
-# Show second derivatives in y
-imshow(grads_y)
-
-#################################
-# Comute Laplacian Edges
-x_laplacian: torch.Tensor = kornia.laplacian(x_gray, kernel_size=5)
-imshow(x_laplacian)
diff --git a/tutorials/gaussian_blur.py b/tutorials/gaussian_blur.py
deleted file mode 100644
index 5aaec05ac..000000000
--- a/tutorials/gaussian_blur.py
+++ /dev/null
@@ -1,41 +0,0 @@
-"""
-
-Blur image using GaussianBlur operator
-======================================
-
-"""
-
-import cv2
-import matplotlib.pyplot as plt
-import numpy as np
-import torch
-
-import kornia
-
-# read the image with OpenCV
-img: np.ndarray = cv2.imread('./data/doraemon.png')
-img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-
-# convert to torch tensor
-data: torch.tensor = kornia.image_to_tensor(img, keepdim=False) # BxCxHxW
-
-# create the operator
-gauss = kornia.filters.GaussianBlur2d((11, 11), (10.5, 10.5))
-
-# blur the image
-x_blur: torch.tensor = gauss(data.float())
-
-# convert back to numpy
-img_blur: np.ndarray = kornia.tensor_to_image(x_blur.byte())
-
-# Create the plot
-fig, axs = plt.subplots(1, 2, figsize=(16, 10))
-axs = axs.ravel()
-
-axs[0].axis('off')
-axs[0].set_title('image source')
-axs[0].imshow(img)
-
-axs[1].axis('off')
-axs[1].set_title('image blurred')
-axs[1].imshow(img_blur)
diff --git a/tutorials/hello_world.py b/tutorials/hello_world.py
deleted file mode 100644
index 7d6bbf098..000000000
--- a/tutorials/hello_world.py
+++ /dev/null
@@ -1,44 +0,0 @@
-"""
-
-Hello world: Planet Kornia
-==========================
-
-Welcome to Planet Kornia: a set of tutorial to learn about Computer Vision in PyTorch.
-
-This is the first tutorial showing how one can simply load an image and convert from BGR to RGB using Kornia.
-
-"""
-
-import cv2
-import matplotlib.pyplot as plt
-import numpy as np
-import torch
-
-import kornia
-
-#############################
-# We use OpenCV to load an image to memory represented in a numpy.ndarray
-img_bgr: np.ndarray = cv2.imread('./data/arturito.jpeg') # HxWxC
-
-#############################
-# The image is convert to a 4D torch tensor
-x_bgr: torch.tensor = kornia.image_to_tensor(img_bgr) # 1xCxHxW
-
-#############################
-# Once with a torch tensor we can use any Kornia operator
-x_rgb: torch.tensor = kornia.bgr_to_rgb(x_bgr) # 1xCxHxW
-
-#############################
-# Convert back to numpy to visualize
-img_rgb: np.ndarray = kornia.tensor_to_image(x_rgb.byte()) # HxWxC
-
-#############################
-# We use Matplotlib to visualize de results
-fig, axs = plt.subplots(1, 2, figsize=(32, 16))
-axs = axs.ravel()
-
-axs[0].axis('off')
-axs[0].imshow(img_bgr)
-
-axs[1].axis('off')
-axs[1].imshow(img_rgb)
diff --git a/tutorials/total_variation_denoising.py b/tutorials/total_variation_denoising.py
deleted file mode 100644
index 24ea9f571..000000000
--- a/tutorials/total_variation_denoising.py
+++ /dev/null
@@ -1,72 +0,0 @@
-"""
-
-Denoise image using total variation
-======================================
-
-"""
-
-import cv2
-import matplotlib.pyplot as plt
-import numpy as np
-import torch
-
-import kornia
-
-# read the image with OpenCV
-img: np.ndarray = cv2.imread('./data/doraemon.png')
-img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) / 255.0
-img = img + np.random.normal(loc=0.0, scale=0.1, size=img.shape)
-img = np.clip(img, 0.0, 1.0)
-
-# convert to torch tensor
-noisy_image: torch.tensor = kornia.image_to_tensor(img).squeeze() # CxHxW
-
-
-# define the total variation denoising network
-class TVDenoise(torch.nn.Module):
- def __init__(self, noisy_image):
- super(TVDenoise, self).__init__()
- self.l2_term = torch.nn.MSELoss(reduction='mean')
- self.regularization_term = kornia.losses.TotalVariation()
- # create the variable which will be optimized to produce the noise free image
- self.clean_image = torch.nn.Parameter(data=noisy_image.clone(), requires_grad=True)
- self.noisy_image = noisy_image
-
- def forward(self):
- return self.l2_term(self.clean_image, self.noisy_image) + 0.0001 * self.regularization_term(self.clean_image)
-
- def get_clean_image(self):
- return self.clean_image
-
-
-tv_denoiser = TVDenoise(noisy_image)
-
-# define the optimizer to optimize the 1 parameter of tv_denoiser
-optimizer = torch.optim.SGD(tv_denoiser.parameters(), lr=0.1, momentum=0.9)
-
-# run the optimization loop
-num_iters = 500
-for i in range(num_iters):
- optimizer.zero_grad()
- loss = tv_denoiser()
- if i % 25 == 0:
- print("Loss in iteration {} of {}: {:.3f}".format(i, num_iters, loss.item()))
- loss.backward()
- optimizer.step()
-
-# convert back to numpy
-img_clean: np.ndarray = kornia.tensor_to_image(tv_denoiser.get_clean_image())
-
-# Create the plot
-fig, axs = plt.subplots(1, 2, figsize=(16, 10))
-axs = axs.ravel()
-
-axs[0].axis('off')
-axs[0].set_title('Noisy image')
-axs[0].imshow(img)
-
-axs[1].axis('off')
-axs[1].set_title('Cleaned image')
-axs[1].imshow(img_clean)
-
-plt.show()
diff --git a/tutorials/warp_affine.py b/tutorials/warp_affine.py
deleted file mode 100644
index be3a96e89..000000000
--- a/tutorials/warp_affine.py
+++ /dev/null
@@ -1,54 +0,0 @@
-"""
-
-Rotate image using warp affine transform
-========================================
-
-"""
-
-import cv2
-import matplotlib.pyplot as plt
-import numpy as np
-import torch
-
-import kornia
-
-# read the image with OpenCV
-img: np.ndarray = cv2.imread('./data/bennett_aden.png')
-img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-
-# convert to torch tensor
-data: torch.tensor = kornia.image_to_tensor(img, keepdim=False) # BxCxHxW
-
-# create transformation (rotation)
-alpha: float = 45.0 # in degrees
-angle: torch.tensor = torch.ones(1) * alpha
-
-# define the rotation center
-center: torch.tensor = torch.ones(1, 2)
-center[..., 0] = data.shape[3] / 2 # x
-center[..., 1] = data.shape[2] / 2 # y
-
-# define the scale factor
-scale: torch.tensor = torch.ones(1, 2)
-
-# compute the transformation matrix
-M: torch.tensor = kornia.get_rotation_matrix2d(center, angle, scale)
-
-# apply the transformation to original image
-_, _, h, w = data.shape
-data_warped: torch.tensor = kornia.warp_affine(data.float(), M, dsize=(h, w))
-
-# convert back to numpy
-img_warped: np.ndarray = kornia.tensor_to_image(data_warped.byte()[0])
-
-# create the plot
-fig, axs = plt.subplots(1, 2, figsize=(16, 10))
-axs = axs.ravel()
-
-axs[0].axis('off')
-axs[0].set_title('image source')
-axs[0].imshow(img)
-
-axs[1].axis('off')
-axs[1].set_title('image warped')
-axs[1].imshow(img_warped)
diff --git a/tutorials/warp_perspective.py b/tutorials/warp_perspective.py
deleted file mode 100644
index e6a9b4d53..000000000
--- a/tutorials/warp_perspective.py
+++ /dev/null
@@ -1,53 +0,0 @@
-"""
-
-Warp image using perspective transform
-======================================
-
-"""
-
-import cv2
-import matplotlib.pyplot as plt
-import numpy as np
-import torch
-
-import kornia
-
-# read the image with OpenCV
-img: np.ndarray = cv2.imread('./data/bruce.png')
-img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-
-# convert to torch tensor
-data: torch.tensor = kornia.image_to_tensor(img, keepdim=False) # BxCxHxW
-
-# the source points are the region to crop corners
-points_src = torch.tensor([[[125.0, 150.0], [562.0, 40.0], [562.0, 282.0], [54.0, 328.0]]])
-
-# the destination points are the image vertexes
-h, w = 64, 128 # destination size
-points_dst = torch.tensor([[[0.0, 0.0], [w - 1.0, 0.0], [w - 1.0, h - 1.0], [0.0, h - 1.0]]])
-
-# compute perspective transform
-M: torch.tensor = kornia.get_perspective_transform(points_src, points_dst)
-
-# warp the original image by the found transform
-data_warp: torch.tensor = kornia.warp_perspective(data.float(), M, dsize=(h, w))
-
-# convert back to numpy
-img_warp: np.ndarray = kornia.tensor_to_image(data_warp.byte())
-
-# draw points into original image
-for i in range(4):
- center = tuple(points_src[0, i].long().numpy())
- img = cv2.circle(img.copy(), center, 5, (0, 255, 0), -1)
-
-# create the plot
-fig, axs = plt.subplots(1, 2, figsize=(16, 10))
-axs = axs.ravel()
-
-axs[0].axis('off')
-axs[0].set_title('image source')
-axs[0].imshow(img)
-
-axs[1].axis('off')
-axs[1].set_title('image destination')
-axs[1].imshow(img_warp)