MulaiMulai sekarang secara gratis

Proportionally resizing

We want to downscale the images of a veterinary blog website so all of them have the same compressed size.

It's important that you do this proportionally, meaning that these are not distorted.

First, you'll try it out for one image so you know what code to test later in the rest of the pictures.


The image preloaded as dogs_banner.

Remember that by looking at the shape of the image, you can know its width and height.

Latihan ini adalah bagian dari kursus

Image Processing in Python

Lihat Kursus

Petunjuk latihan

  • Import the module and function to resize.
  • Set the proportional height and width so it is half the image's height size.
  • Resize using the calculated proportional height and width.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import the module and function
from skimage.___ import ____

# Set proportional height so its half its size
height = int(____ / 2)
width = int(____ / 2)

# Resize using the calculated proportional height and width
image_resized = ____(dogs_banner, (____, ____),
                       anti_aliasing=True)

# Show the original and resized image
show_image(dogs_banner, 'Original')
show_image(image_resized, 'Resized image')
Edit dan Jalankan Kode