<jupyter_start><jupyter_text>[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.sandbox.google.com/github/kornia/tutorials/blob/master/source/image_enhancement.ipynb) Image EnhancementIn this tutorial we are going to learn how to tweak image properties using the compoments from `kornia.enhance`.<jupyter_code>%%capture
!pip install kornia
%%capture
!wget https://github.com/kornia/data/raw/main/ninja_turtles.jpg
import cv2
from matplotlib import pyplot as plt
import numpy as np

import torch
import torchvision
import kornia as K
def imshow(input: torch.Tensor):
    out: torch.Tensor = torchvision.utils.make_grid(input, nrow=2, padding=5)
    out_np: np.ndarray = K.utils.tensor_to_image(out)
    plt.imshow(out_np)
    plt.axis('off')
    plt.show()<jupyter_output><empty_output><jupyter_text>We use OpenCV to load an image to memory represented in a numpy.ndarray<jupyter_code>img_bgr: np.ndarray = cv2.imread('ninja_turtles.jpg', cv2.IMREAD_COLOR)<jupyter_output><empty_output><jupyter_text>Convert the numpy array to torch<jupyter_code>x_bgr: torch.Tensor = K.utils.image_to_tensor(img_bgr)
x_rgb: torch.Tensor = K.color.bgr_to_rgb(x_bgr)<jupyter_output><empty_output><jupyter_text>Create batch and normalize<jupyter_code>x_rgb = x_rgb.expand(4, -1, -1, -1)  # 4xCxHxW
x_rgb = x_rgb.float() / 255.0
imshow(x_rgb)<jupyter_output><empty_output><jupyter_text>Adjust brightness<jupyter_code>x_out: torch.Tensor = K.enhance.adjust_brightness(
    x_rgb, torch.linspace(0.2, 0.8, 4))
imshow(x_out)<jupyter_output><empty_output><jupyter_text>Adjust Contrast<jupyter_code>x_out: torch.Tensor = K.enhance.adjust_contrast(
    x_rgb, torch.linspace(0.5, 1., 4))
imshow(x_out)<jupyter_output><empty_output><jupyter_text>Adjust Saturation<jupyter_code>x_out: torch.Tensor = K.enhance.adjust_saturation(
    x_rgb, torch.linspace(0., 1., 4))
imshow(x_out)<jupyter_output><empty_output><jupyter_text>Adjust Gamma<jupyter_code>x_out: torch.Tensor = K.enhance.adjust_gamma(
    x_rgb, torch.tensor([0.2, 0.4, 0.5, 0.6]))
imshow(x_out)<jupyter_output><empty_output><jupyter_text>Adjust Hue<jupyter_code>x_out: torch.Tensor = K.enhance.adjust_hue(
    x_rgb, torch.linspace(0., 3.14159, 4))
imshow(x_out)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13068432671081678, 'fraction_numerical': 0.018543046357615896, 'mean_word_length': 6.840830449826989, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '326757', 'license': 'Apache-2.0', 'n_tokens_mistral': 948, 'n_tokens_neox': 908, 'n_words': 140, 'path': 'source/image_enhancement.ipynb', 'repo_name': 'oskarflordal/tutorials', 'size': '2265'}