Skip to content

Commit

Permalink
Update tutorials to use kornia.io (#55)
Browse files Browse the repository at this point in the history
* Use `K.io` in anti-alias with local features examples

* Use `K.io` in canny example

* Use `K.io` in color conversion example

* Use `K.io` in connected components example

* Use `K.io` in data augmentation examples

* Use `K.io` in descriptor matching example

* Use `K.io` in extract patches tutorial

* Use `K.io` in face detection tutorial

* Use `K.io` in edges tutorial

* add `kornia-rs` install line

* Use `K.io` in filtering operators tutorial

* Use `K.io` in gaussian blur tutorial

* Use `K.io` in geometric transform tutorial

* Use `K.io` in geometry generate patch

* reorder hello world tutorial

* Use `K.io` in homography example

* Use `K.io` in image enhancement tutorial

* Use `K.io` in image matching tutorials

* add install kornia and kornia-rs

* Use `K.io` in image registration tutorial

* Use `K.io` in sold2 tutorial

* Use `K.io` in morphology tutorial

* Use `K.io` in resize antialias tutorial

* Use `K.io` in rotate tutorial

* Use `K.io` in denoising tutorial

* Use `K.io` in unsharp mask tutorial

* Use `K.io` in warp perspective tutorial

* fix resize alieased with local features img name

* replace kornia install with pypi
  • Loading branch information
johnnv1 authored May 8, 2023
1 parent 918c52c commit 639356e
Show file tree
Hide file tree
Showing 36 changed files with 680 additions and 963 deletions.
73 changes: 44 additions & 29 deletions nbs/aliased_and_not_aliased_patch_extraction.ipynb

Large diffs are not rendered by default.

36 changes: 16 additions & 20 deletions nbs/canny.ipynb

Large diffs are not rendered by default.

92 changes: 43 additions & 49 deletions nbs/color_conversions.ipynb

Large diffs are not rendered by default.

43 changes: 14 additions & 29 deletions nbs/connected_components.ipynb

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions nbs/data_augmentation_2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
"For more information check the docs: https://kornia.readthedocs.io/en/latest/augmentation.module.html"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
4 changes: 3 additions & 1 deletion nbs/data_augmentation_kornia_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia pytorch_lightning torchmetrics"
"!pip install kornia\n",
"!pip install kornia-rs\n",
"!pip install pytorch_lightning torchmetrics"
]
},
{
Expand Down
28 changes: 13 additions & 15 deletions nbs/data_augmentation_mosiac.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
"**Mosaicing** means taking several input images and combine their random crops into mosaic. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -65,7 +76,6 @@
"outputs": [],
"source": [
"import kornia as K\n",
"import numpy as np\n",
"import torch\n",
"from matplotlib import pyplot as plt\n",
"from torchvision.transforms import transforms\n",
Expand All @@ -78,19 +88,7 @@
" img_vis = img.clone()\n",
" img_vis = K.utils.draw_rectangle(img_vis, box, color=torch.tensor([255, 0, 0]))\n",
" plt.imshow(K.tensor_to_image(img_vis))\n",
"\n",
"\n",
"def load_img(img_path):\n",
" try:\n",
" # not ready on Windows machine\n",
" img = K.io.load_image(img_path, K.io.ImageLoadType.RGB32)\n",
" except:\n",
" import cv2\n",
"\n",
" img = cv2.imread(img_path, cv2.IMREAD_COLOR)\n",
" img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
" img = K.image_to_tensor(img).float() / 255.0\n",
" return img"
" plt.show()"
]
},
{
Expand All @@ -111,7 +109,7 @@
}
],
"source": [
"img1 = load_img(\"panda.jpg\")\n",
"img1 = K.io.load_image(\"panda.jpg\", K.io.ImageLoadType.RGB32)\n",
"img2 = K.augmentation.RandomEqualize(p=1.0, keepdim=True)(img1)\n",
"img3 = K.augmentation.RandomInvert(p=1.0, keepdim=True)(img1)\n",
"img4 = K.augmentation.RandomChannelShuffle(p=1.0, keepdim=True)(img1)\n",
Expand Down
43 changes: 17 additions & 26 deletions nbs/data_augmentation_segmentation.ipynb

Large diffs are not rendered by default.

91 changes: 48 additions & 43 deletions nbs/data_augmentation_sequential.ipynb

Large diffs are not rendered by default.

111 changes: 59 additions & 52 deletions nbs/data_patch_sequential.ipynb

Large diffs are not rendered by default.

112 changes: 52 additions & 60 deletions nbs/descriptors_matching.ipynb

Large diffs are not rendered by default.

60 changes: 16 additions & 44 deletions nbs/extract_combine_patches.ipynb

Large diffs are not rendered by default.

93 changes: 39 additions & 54 deletions nbs/face_detection.ipynb

Large diffs are not rendered by default.

26 changes: 5 additions & 21 deletions nbs/filtering_edges.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia"
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
Expand Down Expand Up @@ -74,10 +75,11 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We use OpenCV to load an image to memory represented in a numpy.ndarray"
"We use Kornia to load an image to memory represented in a torch.tensor"
]
},
{
Expand All @@ -86,26 +88,8 @@
"metadata": {},
"outputs": [],
"source": [
"img_bgr: np.ndarray = cv2.imread(\"doraemon.png\", cv2.IMREAD_COLOR)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert the numpy array to torch"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x_bgr: torch.Tensor = K.utils.image_to_tensor(img_bgr) # CxHxWx\n",
"x_bgr = x_bgr[None, ...].float() / 255.0\n",
"x_rgb: torch.Tensor = K.io.load_image(\"doraemon.png\", K.io.ImageLoadType.RGB32)[None, ...] # BxCxHxW\n",
"\n",
"x_rgb: torch.Tensor = K.color.bgr_to_rgb(x_bgr)\n",
"x_gray = K.color.rgb_to_grayscale(x_rgb)"
]
},
Expand Down
45 changes: 14 additions & 31 deletions nbs/filtering_operators.ipynb

Large diffs are not rendered by default.

24 changes: 9 additions & 15 deletions nbs/gaussian_blur.ipynb

Large diffs are not rendered by default.

50 changes: 13 additions & 37 deletions nbs/geometric_transforms.ipynb

Large diffs are not rendered by default.

39 changes: 10 additions & 29 deletions nbs/geometry_generate_patch.ipynb

Large diffs are not rendered by default.

73 changes: 37 additions & 36 deletions nbs/hello_world_tutorial.ipynb

Large diffs are not rendered by default.

59 changes: 20 additions & 39 deletions nbs/homography.ipynb

Large diffs are not rendered by default.

44 changes: 14 additions & 30 deletions nbs/image_enhancement.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nbs/image_histogram.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia kornia-rs"
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
Expand Down
51 changes: 28 additions & 23 deletions nbs/image_matching.ipynb

Large diffs are not rendered by default.

27 changes: 9 additions & 18 deletions nbs/image_matching_adalam.ipynb

Large diffs are not rendered by default.

57 changes: 10 additions & 47 deletions nbs/image_matching_disk.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nbs/image_points_transforms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia kornia_rs matplotlib"
"!pip install kornia\n",
"!pip install kornia-rs matplotlib"
]
},
{
Expand Down
11 changes: 11 additions & 0 deletions nbs/image_prompter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down
43 changes: 17 additions & 26 deletions nbs/image_registration.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nbs/image_stitching.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install kornia"
"!pip install kornia\n",
"!pip install kornia-rs"
]
},
{
Expand Down
42 changes: 11 additions & 31 deletions nbs/line_detection_and_matching_sold2.ipynb

Large diffs are not rendered by default.

50 changes: 27 additions & 23 deletions nbs/morphology_101.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 639356e

Please sign in to comment.