Skip to main content

Spatial distortions for image augmentations

Project description

saug (Spatial Augmentation)

Spatial distortions for image augmentations

Cite this library:

Oskouei, S., Valla, M., Pedersen, A., Smistad, E., Dale, V.G., Høibø, M., Wahl, S.G.F., Haugum, M.D., Langø, T., Ramnefjell, M.P. and Akslen, L.A., 2024. Segmentation of Non-Small Cell Lung Carcinomas: Introducing DRU-Net and Multi-Lens Distortion. arXiv preprint arXiv:2406.14287.

and

DOI || Harvard citation: Soroush Oskouei (2024) “SoroushOskouei/saug: saug”. Zenodo. doi: 10.5281/zenodo.10780398.

Include both citations!

Overview

This Python library provides a collection of functions to apply various distortion effects to images. These effects range from simple pixelation and mirroring to more complex transformations like elastic and wave distortions, enabling creative alterations of images for artistic or research purposes. The library leverages NumPy for efficient array manipulations, ensuring high performance even for large images.

Dependencies

NumPy: For array operations and mathematical functions. OpenCV (cv2): For image reading and saving functionalities, as well as some image processing tasks.

Functions

This library includes a variety of functions to apply different types of distortions to images. Each function accepts an image (as a NumPy array) as input and returns the distorted image. The main functions include:

multi_lens_distortion: Applies a several lens distortion effects on various positions.

elastic_transform: Applies an elastic deformation to the image.

twirl_distortion01 and twirl_distortion02: Apply a twirling effect to parts of the image.

wave_distortion01, wave_distortion02, and wave_distortion: Create wave-like distortions across the image.

pixelate_image: Pixelates a specified region or the entire image.

cartesian_to_polar_image_stretched: Transforms the image from Cartesian to polar coordinates, stretching the pixels.

mirror_effect: Applies a mirroring effect to a specified side of the image.

tilt_shift_effect: Simulates a tilt-shift photography effect, blurring parts of the image while keeping a specific area in focus.

ripple_effect: Creates a ripple effect across the image.

zoom_blur: Applies a zoom blur effect from a specified point.

space_distortion_v1: Distorts the space within the image in a specified direction.

wind_distortion: Simulates the effect of wind on the image.

squeeze_stretch_effect: Applies a squeeze and stretch effect to the image.

smooth_lens_distortion: Applies a smooth lens distortion effect centered around a specified point.

crystallize_distortion: Simulates a crystalline effect by averaging blocks of pixels.

honeycomb_distortion: Applies a honeycomb-like distortion effect across the image.

moving_blur: Applies a moving blur effect on the whole image with specified direction and intensity.

warp_bubbles_effect: Creates a warp-like effect around a specified position.

Usage Examples Below are examples demonstrating how to use some of the functions provided in this library. These examples use a chessboard image as the input, but you can replace it with any image of your choice.

distorted_chessboard = multi_lens_distortion(chessboard, num_lenses=8, radius_range=[120, 190], strength_range=[-0.2, 0.7]):

image

distorted_chessboard = elastic_transform(chessboard, 90, 7)

image

distorted_chessboard = twirl_distortion01(chessboard, (170,270), 200, 0.8)

image

distorted_chessboard = twirl_distortion02(chessboard, (170,170), 10, 0.12)

image

distorted_chessboard = wave_distortion01(chessboard, (170,100), 10, 10)

image

distorted_chessboard = wave_distortion02(chessboard, (170,100), 8, 60)

image

distorted_chessboard = wave_distortion(chessboard, 8, 80)

image

distorted_chessboard = pixelate_image(chessboard, 14, (50, 50, 340, 340))

image

distorted_chessboard = cartesian_to_polar_image_stretched(chessboard, center=None)

image

distorted_chessboard = mirror_effect(chessboard, direction='horizontal', mirror_line_position=180, side='right')

image

distorted_chessboard = tilt_shift_effect(chessboard, 0.3, 0.7, 5, 0.4)

image

distorted_chessboard = ripple_effect(chessboard, 3, 7)

image

distorted_chessboard = zoom_blur(chessboard, (150, 150), intensity=0.07, blend=0.3)

image

distorted_chessboard = space_distortion_v1(chessboard)

image

distorted_chessboard = wind_distortion(chessboard, direction=(0.4, -1), strength=21)

image

distorted_chessboard = squeeze_stretch_effect(chessboard)

image

distorted_chessboard = smooth_lens_distortion(chessboard, 200, 200, 150, 1.3)

image

distorted_chessboard = crystallize_distortion(chessboard, crystal_size=27)

image

distorted_chessboard = honeycomb_distortion(chessboard)

image

distorted_chessboard = moving_blur(chessboard, 2,0.4, 3)

image

distorted_chessboard = warp_bubbles_effect(chessboard, [(170, 170)], 149, 3)

image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saug-0.0.3.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saug-0.0.3-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file saug-0.0.3.tar.gz.

File metadata

  • Download URL: saug-0.0.3.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for saug-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5768a3ea78086d4a7c40aa24bbf9b7eec461408c77d16bbe58172e2ae799e42a
MD5 10588fd02e35545d95a0afceacbd0eb2
BLAKE2b-256 4c4eb5511236408769bf60507afd623e6c7719772b88071c59f6cdbe3b9be311

See more details on using hashes here.

File details

Details for the file saug-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: saug-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for saug-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d1457ee804b961e2d6462fbe6acd4aefb87850a4834a3e5ca5b77cf52985aa5a
MD5 d9a0b1f8b157e1cc61f728f22a898d94
BLAKE2b-256 6e4f39b5e1a0227094e009a0806d7db8e7702f8e64938c5863c6b0dfc9547ec8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page