Skip to main content

This tool help in extracting the region of interest in a given image.

Project description

polyroi

polyroi.py

Status GitHub Issues GitHub Pull Requests License


Select and manipulate Region of interest.

📝 Table of Contents

🧐 About

A small python module to select a polygonal region of interest (ROI) in a given image that is stored as a Shape object. You can use this Shape object later to manipulate the polygon selected. You can also extract the inner content from an image, calculate the histogram of the created shape, calculate the center of the shape, rotate the shape around its center, or translate the shape.

🏁 Getting Started

import cv2 as cv
from polyroi import Shape
img = cv.imread('image.jpg')
shape = Shape.get_roi(img) #returns a Shape object
shape.draw_shape(img, color=(0, 255, 255), thickness=1)
while(1):
    cv.imshow("Getting Started", img)

    k = cv.waitKey(1) & 0xFF
    if k == 27:
        break
cv.destroyAllWindows()

Prerequisites

pip install cv2
pip install numpy

Installing

pip install polyroi 

🎈 Usage

Some time ago, I looked for an efficient tool to draw and manipulate polygons in a python environment. But I didn't find anything useful for my case. I did find some tools that can draw and extract a NumPy array, but as for the manipulation of shapes, I had to develop the logic myself. So I decided to create one. I was trying to implement the particle filter from Part-Based Lumbar Vertebrae Tracking in Videofluoroscopy Using Particle Filter. You can check the repository of how I did manage to work with this package.

img = cv.imread('image.jpg')

# returns a Shape object
shape = Shape.get_roi(img) 

# Copy the shape
shape2 = Shape.copy(shape) 

# Rotate the shape
shape2.rotate_around_center(np.pi/4) 

# x translate the shape by 5
shape2.translate_x(5) 

# y translate the shape by 5
shape2.translate_y(5) 

# recalculate the center of the shape
shape2.centroid() 

# translate the shape first point to (10, 15) along with the shape
shape2.translate_to(10, 15) 

# x translate, y translate, and rotate around the center by np.pi / 12
shape2.update(5, 3, np.pi / 12) 

# Drawing the shapes
shape.draw_shape(img, color=(0, 255, 255), thickness=1)
shape2.draw_shape(img, color=(0, 255, 0), thickness=1)

# return the bounding box points (upper left, bottom right)
p1, p2 = shape2.to_rectangle() 

# plotting the image
while(1):
    cv.imshow("Getting Started", img)

    k = cv.waitKey(1) & 0xFF
    if k == 27:
        break
cv.destroyAllWindows()

⛏️ Built Using

✍️ Authors

See also the list of contributors who participated in this project.

🎉 Acknowledgements

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

polyroi-0.0.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

polyroi-0.0.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file polyroi-0.0.2.tar.gz.

File metadata

  • Download URL: polyroi-0.0.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for polyroi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 87de2ca002e5ffdad8eab1cf92711658de5c751b44adce5f7f4a1e60475110b8
MD5 7f8671737862a4b8be212c1852a9edc6
BLAKE2b-256 e79e12a8082dceba96d1b6a55211c008cf319a533b0d10fbd084ed9d3bf949e1

See more details on using hashes here.

File details

Details for the file polyroi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: polyroi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for polyroi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5705bed88ca8ad10b57c1bdff794fd875e01238072fe3c867dd2b17bdbc63948
MD5 293cf8920380d136eeb69f3449d32c3d
BLAKE2b-256 7c1d2f9a03a1c9b836f27895888645f9950a536363f8c1fb650caa7f01b7c14c

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