Skip to main content

A library for histogram manipulation of images

Project description

Geospatial Raster Processing Library

Overview

This library provides geospatial image processing utilities for enhancing and analyzing raster datasets. It aims to provide essential functionalities for image histogram manipulation, allowing users to input multi-band images and apply various operations to enhance image contrast and distribution. It includes the following modules:

  1. Histogram Stretching: A module to enhance the contrast of raster images by applying percentile-based stretching.
  2. Histogram Matching: A module to adjust the pixel intensity distribution of a raster image to match a reference histogram.
  3. Histogram Equalization: A module to improve the contrast of raster images by redistributing pixel intensity values using histogram equalization.

These tools are designed for geospatial applications, enabling preprocessing steps commonly used in remote sensing and GIS workflows.


Features

Histogram Stretching

  • Enhances the contrast of images by clipping and rescaling pixel intensity values between specified lower and upper percentiles.
  • Outputs a visually improved raster image with stretched pixel values.
  • Supports multi-band raster datasets.

Histogram Matching

  • Adjusts the histogram of an input image to match the histogram of a reference image.
  • Useful for normalizing image datasets for analysis or visualization.
  • Compatible with single-band and multi-band raster datasets.

Histogram Equalization

  • Improves image contrast by redistributing pixel intensity values across the entire intensity range.
  • Automatically balances the intensity distribution to enhance image details.
  • Supports single-band raster datasets.

Installation

pip install histogram-manipulation

Usage

There are some examples in test folder

Histogram Stretching

from histogram_manipulation import HistogramStretching

# Initialize the class with input and output paths
stretching = HistogramStretching(input_path="input.tif", output_path="stretched_output.tif")

# Apply contrast stretching
stretching.contrast_stretch(lower_percentile=2, upper_percentile=98)

# Save the stretched image
stretching.save_stretched_image()

# Plot original vs. stretched images in RGB channel 
stretching.plot_rgb()
# Plot original vs. stretched images in single channel
stretching.plot_singleband()

# Plot the Histograms
stretching.plot_histograms()

Histogram Matching

from histogram_manipulation import HistogramMatcher

# Initialize the class with input and reference images
matcher = HistogramMatcher(reference_path="reference.tif", secondary_path="second.tif")

# Apply histogram matching
matcher.match_histograms()

# Save the matched image
matcher.save_matched_image()

# Plot the bands of secondary, reference, and matched images
matcher.plot_bands(matcher.secondary, "Secondary")
matcher.plot_bands(matcher.reference, "Reference")

with rio.open(matcher.matched_path) as matched_src:
    matched_data = matched_src.read()
matcher.plot_bands(matched_data, "Matched")

matcher.plot_histograms()

Histogram Equalization

from histogram_manipulation.equalization import HistogramEqualization

# Initialize the class with the input path
equalizer = HistogramEqualization(image_path="input.tif")

# Apply histogram equalization
equalizer.equalize()

# Save the equalized image
equalizer.save_equalized_image(output_path="equalized_output.tif")

# Display the original and equalized images side by side
equalizer.display_images()

# Plot histograms of the original and equalized images
equalizer.plot_histograms()

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

histogram_manipulation-1.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

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

histogram_manipulation-1.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file histogram_manipulation-1.1.0.tar.gz.

File metadata

  • Download URL: histogram_manipulation-1.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for histogram_manipulation-1.1.0.tar.gz
Algorithm Hash digest
SHA256 662512cb949ca2e61891d631ca9613ea7cb1608a3fd49d5dce23b4a52524d518
MD5 f6137cb38af7d04d4cf185f9563a6b0e
BLAKE2b-256 b90bb4328d4e18b1c74009b78e2495139b03565ff398b3b52d151dc2cb525f5e

See more details on using hashes here.

File details

Details for the file histogram_manipulation-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: histogram_manipulation-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for histogram_manipulation-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3cc5fb527573f3ce2022408e560a0bdd092a173ca7d93162ec2ed4e81e3c83f
MD5 7d11fb603c3bbe93f67b670fa57b11ce
BLAKE2b-256 599e764341ffacd19d367b54519d489905b6867edb07d52786fcbd37fde1421d

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