<jupyter_start><jupyter_text>Exercice 1<jupyter_code>import cv2
import glob
import numpy as np
from PIL import Image, ImageEnhance
from matplotlib import pyplot as plt
from pathlib import Path
minion = Image.open('../resources/bob-mimon.jpg')<jupyter_output><empty_output><jupyter_text>**Enhancing Brightness**<jupyter_code>enhancer = ImageEnhance.Brightness(minion)
minion_bright = enhancer.enhance(1.5)

figure, axes = plt.subplots(1, 2)
axes[0].set_title('Original')
axes[0].imshow(minion)
axes[1].set_title('Brightened')
axes[1].imshow(minion_bright)

minion_bright.save('minion_bright.jpg')<jupyter_output><empty_output><jupyter_text>**Enhancing Sharpness**<jupyter_code>enhancer = ImageEnhance.Sharpness(minion)
minion_sharp = enhancer.enhance(5.0)

figure, axes = plt.subplots(1, 2)
axes[0].set_title('Original')
axes[0].imshow(minion)
axes[1].set_title('Sharpened')
axes[1].imshow(minion_sharp)

minion_sharp.save('minion_sharp.jpg')<jupyter_output><empty_output><jupyter_text>**Enhancing Contrast**<jupyter_code>enhancer = ImageEnhance.Contrast(minion)
minion_contrast = enhancer.enhance(3.0)

figure, axes = plt.subplots(1, 2)
axes[0].set_title('Original')
axes[0].imshow(minion)
axes[1].set_title('Contrast')
axes[1].imshow(minion_contrast)

minion_contrast.save('minion_contrast.jpg')<jupyter_output><empty_output><jupyter_text>**Enhancing Color**<jupyter_code>enhancer = ImageEnhance.Color(minion)
minion_color = enhancer.enhance(2.0)

figure, axes = plt.subplots(1, 2)
axes[0].set_title('Original')
axes[0].imshow(minion)
axes[1].set_title('Color enhanced')
axes[1].imshow(minion_color)

minion_color.save('minion_color.jpg')<jupyter_output><empty_output><jupyter_text>Exercice 2<jupyter_code>minion = cv2.imread('../resources/bob-mimon.jpg')
minion_grey = cv2.cvtColor(minion, cv2.COLOR_BGR2GRAY)
minion_hsv = cv2.cvtColor(minion, cv2.COLOR_BGR2HSV)
minion_lab = cv2.cvtColor(minion, cv2.COLOR_BGR2LAB)

converted_path = Path().resolve() / 'converted'
converted_path.mkdir(exist_ok=True)

cv2.imwrite(str(converted_path / 'minion.jpg'), minion)
cv2.imwrite(str(converted_path / 'minion_grey.jpg'), minion_grey)
cv2.imwrite(str(converted_path / 'minion_rgb.jpg'), minion)
cv2.imwrite(str(converted_path / 'minion_hsv.jpg'), minion_hsv)
cv2.imwrite(str(converted_path / 'minion_lab.jpg'), minion_lab)<jupyter_output><empty_output><jupyter_text>**Resizing a batch of images**<jupyter_code>paths = sorted(glob.glob(f'{Path().resolve()}/*.jpg'))

resized_path = Path().resolve() / 'resized'
resized_path.mkdir(exist_ok=True)

for path in paths:
    image = cv2.imread(path)
    resized = cv2.resize(image, (300, 300))
    cv2.imwrite(f'{resized_path}/resized_{Path(path).name}', resized)<jupyter_output><empty_output><jupyter_text>Exercice 3<jupyter_code>def data_augmentation(paths: list[Path], angles: list[float]) -> None:
    '''
    Applies rotation on each image from paths by each angle of angles
    '''

    aug_path = Path().resolve() / 'augmentation'
    aug_path.mkdir(exist_ok=True)

    for path in paths:
        image = Image.open(path)
        for angle in angles:
            rotated = image.rotate(angle)
            rotated.save(f'{aug_path}/rotated_{int(angle)}_{Path(path).name}')
paths = sorted(glob.glob(f'{Path().resolve()}/*.jpg'))

nb_angles = int(input("Number of angles"))

angles = []
for i in range(nb_angles):
    angle = float(input(f"Value of angle n°{i + 1}"))
    angles.append(angle)


data_augmentation(paths, angles)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15336194563662375, 'fraction_numerical': 0.017453505007153074, 'mean_word_length': 7.073903002309469, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '623179', 'license': 'MIT', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1363, 'n_words': 185, 'path': 'tp-3/TP 3.ipynb', 'repo_name': 'riadh26/Image-Processing-Course', 'size': '3495'}