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.1.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.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: histogram_manipulation-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e11746156ec5ca91f8933b9d6c181606f475aa3b6b19e7aef59a0087590e9606
MD5 0dc742f2df4a7ed96b5f22dfb0dcf79a
BLAKE2b-256 2452fe7fda7d5c10e618463e84799c06da2f089c6a14b4fa83e03bc5478839ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: histogram_manipulation-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 948056ed5e3b34834f277532658246f02bdb3823ef1c8520d084266c5cd08aa7
MD5 badab847cc7afbece06fb9a74aea2862
BLAKE2b-256 d2671fdd15878a50a522ebfaa88325a28c4e5f21087adb2357c938923bdef411

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