В этой статье мы обсудим, как выполнить блочное искажение изображений с помощью Python. Мы будем использовать модуль под названием block_distoriton. Давайте посмотрим вкратце об этом модуле.
Модуль Block_distortion
• Он применяет эффекты блочного искажения к изображениям.
• У него есть возможность создавать как неподвижные, так и анимированные (.gif) версии изображения.
• Количество искажений можно контролировать
Installation
Чтобы установить этот модуль, введите следующую команду в терминале.
pip install block_distortion
Искажение на неподвижное изображение
Функция distort_image () используется для искажения изображений.
Синтаксис:
distort_image (изображение, разбиение = 2000)
Параметр: splits = Количество выполняемых разделений [искажений], по умолчанию 2000. Чем больше разделений, тем более плавное изображение.
Используемое изображение:
from
skimage
import
img_as_ubyte
from
skimage.io
import
imread, imsave
from
block_distortion
import
distort_image
# read image
input_image
=
imread(
'hotel.jpeg'
)
# distort the read image
distorted
=
distort_image(input_image)
# save to required path the converted binary image
imsave(
"./block-hotel.png"
, img_as_ubyte(distorted))
Выход :
Distorting GIF images
Метод animate_image () используется для выполнения требуемого искажения gif.
Синтаксис:
animate_image(splits=2000, frames=100)
Parameters:
splits = Number of splits [ distortions ] to be performed, defaults to 2000. More the splits, more smoother is image.
frames = Number of frames to be created for gif image. defaults to 100.write_frames_to_gif(path=curr, animated_image, duration=100)
path : Location to save file.
duration : duration of persistance of each frame in gif. ( in m/s ) defaults to 100.
from
skimage.io
import
imread
from
block_distortion
import
animate_image, write_frames_to_gif
# read the image
input_image
=
imread(
"hotel.jpeg"
)
# convert to .gif after block distortion
frames
=
animate_image(input_image)
# write gif to output path
write_frames_to_gif(
"./block-anim-hotel.gif"
, frames, duration
=
100
)
Выход :