Skip to main content

A module for handling rectangular regions of interest (ROI) in images.

Project description

roi_rectangle

A Python module for handling rectangular regions of interest (ROI) in images.

Features

  • Define a rectangular ROI with coordinates.
  • Get the center of the ROI.
  • Move the ROI to a new center.
  • Resize the ROI.
  • Get the coordinates and area of the ROI.
  • Slice the ROI region from an image.

Installation

To install the roi_rectangle module, use:

pip install roi_rectangle

Usage

Here's an example of how to use the RoiRectangle module:

from roi_rect import RoiRectangle
import numpy as np
import matplotlib.pyplot as plt

# Create a test image
test_image = np.random.random((100, 100))

# Create an instance of RoiRectangle
roi = RoiRectangle(x1=20, y1=30, x2=70, y2=80)

# Print ROI information
print("Initial ROI:")
print(roi)

# Get the center coordinate of the ROI
print("Center Coordinate:", roi.center)

# Get the width and height of the ROI
print("Width:", roi.width)
print("Height:", roi.height)

# Move the ROI to a new center
new_center = (50, 50)
roi.move_to_center(new_center)
print("\nAfter Moving to Center:")
print(roi)

# Resize the ROI
new_width, new_height = 30, 40
roi.resize(new_width, new_height)
print("\nAfter Resizing:")
print(roi)

# Slice the ROI region from the test image
roi_slice = roi.slice(test_image)
print("\nROI Slice:")
print(roi_slice)

# Visualize the original image and the sliced ROI
plt.figure(figsize=(8, 4))
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(test_image, cmap='gray')

plt.subplot(1, 2, 2)
plt.title('ROI Slice')
plt.imshow(roi_slice, cmap='gray')

plt.gca().add_patch(plt.Rectangle((roi.x1, roi.y1), roi.width, roi.height, linewidth=2, edgecolor='r', facecolor='none'))
plt.show()

License

This project is licensed under the MIT License.

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

roi_rectangle-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

roi_rectangle-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file roi_rectangle-0.0.1.tar.gz.

File metadata

  • Download URL: roi_rectangle-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for roi_rectangle-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5dab5355c09d8d5c13b3da75cd5352fe6b3195506c49ffa61897e7f462455556
MD5 13246fcc74503d8c7f0d30afdd94c91b
BLAKE2b-256 f4732bbd2c327f15a2816e5a02d6160d4f7f484c14b7501f72ab3844f2c926bc

See more details on using hashes here.

File details

Details for the file roi_rectangle-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for roi_rectangle-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de52b8dd48adaf5c204319b25baa342492f9a73764911abbdb97fb12b536925a
MD5 5eba1ac42d8acc6facbf7ed6a5d6d10e
BLAKE2b-256 eb425fe0152223d5cee4555035f9b369d91c2741421ce96ec3f0c455c8d9144d

See more details on using hashes here.

Supported by

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