Skip to content

mroncka/image-extraction

Repository files navigation

Bounding box extraction

Minimal bounding box extraction and alignment. This project is implmentation of recruitment task for Konica - Research Position.

Overview

Main purpose of this project is implementation of an algorithm for minimal bounding box extraction from segmentation map. Additionaly each of extracted bounding boxes is alligned to the xy axis with the longer dimnesion being aligned to the y axis. This project can be used directly with the existing example or as a pip package library.

Prerequisites and usage

Using Docker Compose

docker-compose build
docker-compose run app -i assignment/RS_homework_BB.png -o output -t 4 -a True -c

The same can be achieved using Makefile

make build
COMMAND="-i assignment/RS_homework_BB.png -o output -t 4 -a True -c" make run

Using Docker

docker build . -t image-extraction --target build
docker run -v ${PWD}:/app -w /app -it image-extraction -i input/test.png -o output -t 4 -a True -c

Using Pip

pip install -r requirements.txt
python main.py -i input/test.png -o outputs -t 128 -o output -t 4 -a True -c -v

Arguments

  • -i, --input TEXT Input file for bbox extraction.
  • -o, --output TEXT Directory to store extracted bbox images. (default output/{input_filename})
  • -t, --threshold INTEGER Image intensity threshold used to extract contours. (0-255, default 4)
  • -a, --align BOOLEAN Align the bbox dominant dimension with the Y axis. (default True)
  • -c, --center BOOLEAN Center bbox around the contour. (default False)
  • -f, --min_factor INTEGER Bounding box dimension will be divisible by specified value. (default 1)
  • -v, --visual Input image and bounding box visualization using opencv.imshow.

Visualization requires installation of dev_requirements and in case of docker enabled X11 forwarding.

Using as a Pip package

From git

pip install git+https://github.com/mroncka/image-extraction.git

Locally

git clone [email protected]:mroncka/image-extraction.git && cd image-extraction && pip install -e .

Usage

import cv2
from image_extraction.bbox import get_bounding_boxes

image = cv2.imread(input, cv2.IMREAD_GRAYSCALE)
bboxes = get_bounding_boxes(image)
for i, bbox in enumerate(bboxes):
    crop = bbox.crop_axis_aligned(image)

Running tests

Using Docker Compose

docker-compose build
docker-compose run test

The same can be achieved using Makefile

make build
make test

Locally

pip install -r test_requirements.txt
pytest tests

Examples

Running examples require installation of dev_requirements and in case of docker enabled X11 forwarding.

python example.py min
python example.py visual
python example.py rotation

Example input and output

drawing

Extracted contours with threshold values of 4 and 64 (specified by -t argument)

drawing example output example output

drawing example output example output example output

Build Requirements

click==8.1.3
opencv-python-headless==4.6.0.66

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published