occlusion

Create occluded images

https://github.com/timmaniquet/occlusion

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.9%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Create occluded images

Basic Info
  • Host: GitHub
  • Owner: TimManiquet
  • Language: Python
  • Default Branch: main
  • Size: 24.7 MB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • Open Issues: 1
  • Releases: 1
Created about 3 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Citation

README.md

Occlusion of Images

This repository contains three Python scripts to apply occlusion to a set of images in different ways. The three ways of occluding images are: by adding blobs on top of images, by adding a partial viewing mask with apertures on top of the images, or by deleting parts of the images. Each of these manipulations, occludes objects in the images such that only a certain proportion of them will remain visible.

Installation

Use this package by cloning it (see below) or installing it. To install this package using pip, first ensure that you have Git installed on your system. Then, create a new virtual environment and activate it. Finally, run the following command:

pip install git+https://github.com/TimManiquet/occlusion.git@v0.1

Input images

To ensure that the occluded proportion is calculated correctly, make sure the input images contain an transparent mask (alpha channel) where the object is delineated from the background. These images should be 4-channel, grayscale images. Example of such images can be found in the input images folder.

Requirements

  • Python 3
  • OpenCV (cv2)
  • NumPy
  • pathlib
  • glob
  • os

Usage

  1. Clone or download this repository.
  2. Place the images to occlude in the img_dir folder.
  3. Run the following in your command line:

python occlude_images_folder.py /path/to/input_images --hard 80 --apply_blobs --many_small --out_dir /path/to/outputs

  1. The resulting occluded images will be saved in the out_dir folder.

Arguments

  • img_dir (required): Path to the input images directory.
  • --easy (optional, default 20): Percentage of easy occlusion to apply.
  • --hard (optional, default 60): Percentage of hard occlusion to apply.
  • --apply_blobs (optional): Whether to apply blob occlusion.
  • --apply_deletion (optional): Whether to apply deletion occlusion.
  • --apply_partialviewing (optional): Whether to apply partial viewing occlusion.
  • --many_small (optional): Whether to occlude many small areas.
  • --few_large (optional): Whether to occlude few large areas.
  • --col (optional, default 0): The grayscale color of the occluding window. Defaults to 0 (black).
  • --out_dir (optional, default ./outputs): Path to the output directory.
  • --seed (optional, default 42): Seed for the random number generator.

Validation

The script includes validation to ensure that at least one of 'blobs', 'deletion', or 'partialviewing' is set to True, and that at least one of 'manysmall' or 'fewlarge' is set to True. Additionally, the percentage of object occluded in the easy condition must be lower than the hard condition.

If any of these validations fail, the script will raise a ValueError.

Example

The program can also be run as a python script as shown below

``` from scripts.occlusionfuncs import blobs from scripts.occlusionfuncs import partialviewing from scripts.occlusionfuncs import deletion

If you want to apply only one manipulation type

blobs(inputdir, easy=10, hard=50, manysmall=True, col=255)

deletion(inputdir, easy=40, hard=70, fewlarge=True, col=255)

partialviewing(inputdir, easy=20, hard=50, manysmall=False, fewlarge=True, seed=10, out_dir='/outfolder')

We can also use the more general occlude function that is called in occludeimagesfolder.py

from scripts.occlusion_funcs import occlude

occlude( inputdir, easy=20, hard=60, applyblobs=True, applydeletion=True, applypartialviewing=True, manysmall=True, fewlarge=True, col=0, out_root="./outputs", seed=42, )

```

This example applies different level and types of occlusion to the images in the input_dir folder. The resulting occluded images will be saved in the output_images folder.

Outputs

Below are example output images from different commands.

blobs("path/to/cat.png", easy=10, hard=50, many_small=True, col=255)

deletion("path/to/building.png", easy=40, hard=70, many_small=True, few_large=True)

partial_viewing("path/to/bird.png", easy=20, hard=90, many_small=False, few_large=True, seed=10)

Owner

  • Name: Tim Maniquet
  • Login: TimManiquet
  • Kind: user
  • Location: Leuven
  • Company: KU Leuven

PhD student @KU Leuven.

Citation (CITATION.cff)

cff-version: 1.2.0
title: occlusion
message: 'If you use this software, please cite is a below.'
type: software
authors:
  - given-names: Tim
    name-particle: Timothée
    family-names: Maniquet
    affiliation: KU Leuven
    orcid: 'https://orcid.org/0000-0003-0617-9657'
    email: timotheemaniquet@gmail.com
  - given-names: Andrea
    family-names: Ivan Costantino
    email: andreaivan.costantino@kuleuven.be
    affiliation: KU Leuven
    orcid: 'https://orcid.org/0000-0002-8481-3142'
repository-code: 'https://github.com/TimManiquet/occlusion'
abstract: >-
  Python scripts to apply occlusion to a set of images in
  different ways.
commit: ' da68410'
version: v0.1
date-released: '2023-03-07'

GitHub Events

Total
Last Year

Dependencies

requirements.txt pypi
  • numpy ==1.23.5
  • opencv_python ==4.7.0.68
setup.py pypi