# Untitled

unknown
plain_text
2 months ago
2.5 kB
1
Indexable
Never
```from PIL import Image, ImageOps
import matplotlib.pyplot as plt
import numpy as np

# Wczytaj obraz
img = Image.open('obraz.jpg')

# 1. Zastosuj metodę resize
scales = [(0.15, 0.27)]
resampling_methods = [Image.NEAREST, Image.LANCZOS, Image.BILINEAR, Image.BICUBIC, Image.BOX, Image.HAMMING]
resized_images = [img.resize((int(img.width * s_w), int(img.height * s_h)), resample=method) for s_w, s_h in scales for method in resampling_methods]

# Wyświetl obrazy i różnice
fig, axs = plt.subplots(2, len(resized_images), figsize=(20, 10))
for i, resized_img in enumerate(resized_images):
axs[0, i].imshow(resized_img)
axs[1, i].imshow(np.abs(np.array(resized_images[0]) - np.array(resized_img)))
plt.savefig('fig1.png')

# Wczytaj obraz
img2 = Image.open('balwan.png')

# Zdefiniuj, gdzie są rękawiczki na obrazie
glove1_box = (0, 240, 80, 320)
glove2_box = (325, 185, 425, 520)

# Wytnij rękawiczki z obrazu
glove1 = img2.crop(glove1_box)
glove2 = img2.crop(glove2_box)

# Powiększ rękawiczki
glove1 = glove1.resize((int(glove1.width * 1.5), int(glove1.height * 1.5)))
glove2 = glove2.resize((int(glove2.width * 1.5), int(glove2.height * 1.5)))

# Wklej powiększone rękawiczki z powrotem do obrazu
img2.paste(glove1, glove1_box[:2])
img2.paste(glove2, glove2_box[:2])

# Zapisz obraz
img2.save('balwan2.png')

# 3. Obróć obraz
angles = [60, -60]
expand_options = [True, False]
fill_colors = ['red', 'green']
rotated_images = [img.rotate(angle, resample=Image.BICUBIC, expand=expand, fillcolor=color) for angle in angles for expand in expand_options for color in fill_colors]

# Wyświetl obrazy
fig, axs = plt.subplots(1, len(rotated_images), figsize=(20, 10))
for i, rotated_img in enumerate(rotated_images):
axs[i].imshow(rotated_img)
plt.savefig('fig4.png')

# 4. Obróć obraz wokół punktu (0,0)
new_img = Image.new('RGB', (img.width * 2, img.height * 2), 'white')
new_img.paste(img, (img.width // 2, img.height // 2))
rotated_img = new_img.rotate(-30, resample=Image.BICUBIC, expand=True)
rotated_img.save('obrot.png')

# 5. Przekształcenia Image.TRANSPOSE i Image.TRANSVERSE
# Image.TRANSPOSE to obrót o 90 stopni w prawo, a następnie Image.FLIP_LEFT_RIGHT
transpose_img = img.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT)

# Image.TRANSVERSE to obrót o 90 stopni w lewo, a następnie Image.FLIP_LEFT_RIGHT
transverse_img = img.rotate(90).transpose(Image.FLIP_LEFT_RIGHT)
```