Skip to main content

A simple tool to scramble the background (=anything but people) in images.

Project description

Background Scrambler

This package contains a simple tool that allows to scramble the background of images. By background, we mean anything but the people in the image. This is practical for, e.g., psychology or neuroscience experiments dealing with human vision and/or social cognition.

As an example, it turns this image:

into this image:

Installation

To install this application, either clone this repository, or simply install using pip install bg-scrambler.

Usage

The application will keep the original image size, if its largest side is a multiple of 32 (a requisite of YOLOv11), up till sizes of 2016px. If the largest side exceeds 2016, the image will be resized so that this side becomes 2016px.

Note that the scrambler returns the processed image. By default, the output is NOT saved to disk.
To save the output (i.e., the processed image) to disk, specify out_file='path/to/output.jpg' (or png) when calling process_img().

When cloning the repo

See the example in scrambler.py, reprised here:

if __name__ == '__main__':
    # Create Scrambler instance
    proc = Scrambler()
    # Replace the line below to point at the image you want to parse
    _img = 'test_image_unsplash.jpg'
    # Parse image
    # block_size: size of the blocks (or patches if you prefer) that will be randomly swapped around
    # blur_radius: size of the blur to be applied to the scrambled part
    res = proc.process_img(_img, block_size=3, blur_radius=0, out_file=None, b_show=True)

When installing the package through pip:

A short demo:

from bg_scrambler import scrambler
import os


if __name__ == '__main__':
    proc = scrambler.Scrambler()
    _img = os.path.join(os.path.dirname(scrambler.__file__), 'test_image_unsplash.jpg')

    # Parse image
    # block_size: size of the blocks (or patches if you prefer) that will be randomly swapped around
    # blur_radius: size of the blur to be applied to the scrambled part
    res = proc.process_img(_img, block_size=3, blur_radius=0, out_file=None, b_show=True)

Licensing

This repository is made available under an MIT license (see LICENSE.md). This is in agreement with the original repository, which also uses an MIT license.

The test image is taken from Unsplash:
https://unsplash.com/photos/a-person-sitting-on-a-couch-with-a-laptop-X1GZqv-F7Tw
The image is distributed under the Unsplash license.

Author: Laurent Mertens
Mail: contact@laurentmertens.com

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

bg_scrambler-1.0.1.tar.gz (11.4 MB view details)

Uploaded Source

Built Distribution

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

bg_scrambler-1.0.1-py3-none-any.whl (11.4 MB view details)

Uploaded Python 3

File details

Details for the file bg_scrambler-1.0.1.tar.gz.

File metadata

  • Download URL: bg_scrambler-1.0.1.tar.gz
  • Upload date:
  • Size: 11.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for bg_scrambler-1.0.1.tar.gz
Algorithm Hash digest
SHA256 00ea2accb7e8dfe8c848f4c0ba8e45bdf91799e936216c26473284c14c8bf0f5
MD5 5f798a895adf99d9e8fb9294aa3fca8e
BLAKE2b-256 afb0ab89e3b64fb847c0881751885b496bc2f2240fbfd90988db1787b72e9d3a

See more details on using hashes here.

File details

Details for the file bg_scrambler-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: bg_scrambler-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for bg_scrambler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6aa45f39d1bed94b52624ca69a6defda0ebab15fa9309369780f0a1facbf2b0c
MD5 bb02ad518c19f6ed0e5d48eb68a337c5
BLAKE2b-256 6901c1dea1fe51c480a2b20bedbef0fb8ec3fa17126823aa8dcfe7e017a68bfe

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