Skip to main content

Image Area Calculator

This Python application is a versatile tool designed for calculating the real-world areas of contours in an image by referencing a known object for scaling. Built with OpenCV for powerful image processing, this tool can handle both standard image files and PDFs (with automatic conversion to images if needed). Users can accurately measure areas in square centimeters by selecting points on an object of known length within the image.

The application is fully command-line driven, making it ideal for automation, scripting, and integration into larger workflows. With just a few command-line options, users can specify input files, set image processing parameters, rotate images, and output the results to CSV files for further analysis. Whether you're working with scanned documents, photos, or any other images containing measurable objects, this tool offers a straightforward and efficient solution for area measurement.

Purpose of the Package

The Image Area Calculator offers a straightforward solution for anyone needing to measure areas in images accurately. Whether you're working with scanned documents, photos, or any other images containing measurable objects, this tool allows you to calculate areas in real-world units (cm²) by referencing a known object in the image. The package supports image files directly and can also convert PDF files to images for processing.

Features

  • Automatically converts single-page PDF files to JPEG images for processing.
  • Allows users to select two points on a reference object in the image to calculate the scale, then calculates and displays areas of contours in the image in square centimeters (cm²).
  • Supports rotating images by a specified angle to correct the orientation before processing.
  • Exports the calculated areas and contour coordinates to a CSV file for further analysis.
  • Displays the image with calculated areas overlaid directly on the contours, making it easy to visualize the results.

Installation Instructions

1. Python Environment
Requires Python 3 environment. Ensure you have it installed on your computer.

pip install image-area-calculator

2. Additional Dependencies
The application uses the following libraries, which will be automatically installed via pip:

  • Click (for handling command-line options and arguments)
  • OpenCV (for image processing)
  • pdf2image (for PDF to image conversion)
  • NumPy (for numerical calculations)

Usage

After installation, you can use the tool directly from the command line. For example:

calculate-areas --image 'path/to/image.jpg' \
                 --ref_length 5 \
                 --threshold_value 127 \
                 --maxval 255 \
                 --area_threshold 200 \
                 --rotation_angle 90 \
                 --output 'output_areas.csv'

Command-Line Options

  • -i, --image: Path to the input image or PDF file. This is required.
  • -l, --ref_length: The length of the reference object in centimeters. This is required to calculate the scale.
  • -t, --threshold_value: The threshold value for binarization (default is 127). Adjust if needed for better contour detection.
  • -m, --maxval: The maximum value for binary thresholding (default is 255).
  • -a, --area_threshold: Minimum contour area in pixels to consider (default is 200). Adjust to filter out smaller contours.
  • -R, --rotation_angle: Angle to rotate the image in degrees (default is 0). Use this if the image needs to be rotated.
  • -o, --output: Path to save the CSV file with contour areas (default is derived from the image name).

Acknowledgment

The development of this application draws upon various Python libraries, particularly OpenCV for image processing and pdf2image for handling PDF files. These tools are critical for enabling the image manipulation and analysis capabilities of this package.

Author

Dr. Clabe Wekesa

Metadata

Release files for image-area-calculator 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for image-area-calculator 0.1.0
File Size Uploaded Provenance
image_area_calculator-0.1.0.tar.gz 6.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for image-area-calculator 0.1.0
File Interpreter ABI Platform
image_area_calculator-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / image_area_calculator-0.1.0.tar.gz

Download URL image_area_calculator-0.1.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c59557da499966ad6207c6b457d88f19d1d4a20eefbec4671275f4bf154db261
BLAKE2b-256 checksum
How to use checksums
6f54fa7cd470f7fb6a9b2825706ca00c48a36d1e0231f29a00e77d9bd1a128d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Release files / image_area_calculator-0.1.0-py3-none-any.whl

Download URL image_area_calculator-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6d105e59422c9c196784513d8b8bafcb73d042f9f79f4d95a5354a38588c7cc
BLAKE2b-256 checksum
How to use checksums
dcf28fffa834afd280fae264aa7c9093f6817b9af41a2e7124cbbb2d0352ea48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Security for image-area-calculator 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page