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(y1=30, y2=80, x1=20, x2=70)

# 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-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

roi_rectangle-1.0.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: roi_rectangle-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for roi_rectangle-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9573b35fe81fa978ed65da42b33384df9b87a6f2d644cdbded01e6be7f2e0918
MD5 35480fe8821307f81841727db6b675af
BLAKE2b-256 c7d66e8a563a71249d796fb27e361671e48a519b214304bc0ca655a1fc21fb78

See more details on using hashes here.

Provenance

The following attestation bundles were made for roi_rectangle-1.0.0.tar.gz:

Publisher: pipy_release.yml on SJB7777/roi_rectangle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: roi_rectangle-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for roi_rectangle-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b863d6de6b48c9a131e04d441eddfaa8dcbb9f7b80d7b154ab8053ff6c58c4b1
MD5 5cff53481aa19a2f99ab3f4e9a6de9b5
BLAKE2b-256 049b4ab37509536dc21589fd05e67e4b39842a19fac5baeb6b71eb7b4c95b079

See more details on using hashes here.

Provenance

The following attestation bundles were made for roi_rectangle-1.0.0-py3-none-any.whl:

Publisher: pipy_release.yml on SJB7777/roi_rectangle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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