Skip to main content

Contrast-image

Base on multiple papers about contrast, I create this library to contrast images with opencv.

Installation

pip install contrast-image

Usage

from contrast_image import contrast_image
import cv2 as cv

input = cv.imread('input.jpg')

ci = CI(input, 'HSV')
output = ci.GHE()

API

CI

Store all functions to contrast image

from contrast_image import contrast_image

ci = CI(image, color_space = 'HSV')

GHE (Global Histogram Equalization)

This function is similar to equalizeHist(image) in opencv.

ci.GHE()
  • Return: image after equalization

BBHE (Brightness Preserving Histogram Equalization)

This function separate the histogram by the mean of the image, then equalize histogram of each part.

This method tries to preserve brightness of output image by assume PDF is symmetrical distribution.

ci.BBHE()
  • Return: image after equalization

DSIHE (Dualistic Sub-Image Histogram Equalization)

This function is similar to BBHE except using median instead of mean.

Unlike BBHE, DSIHE tries to preserve brightness of output image by maximum entropy after separate.

ci.DSIHE()
  • Return: image after equalization

MMBEBHE (Minimum Mean Brightness Error Histogram Equalization)

This function is similar to BBHE except using minimum mean brightness error instead of mean.

Theortically, mean of output image (by GHE) is middle gray level. Therefore, MMBEBHE believe by separate histogram such that mean of output image near mean of input image must preserve brightness.

ci.MMBEBHE()
  • Return: image after equalization

BPHEME (Brightness Preserving Histogram Equalization with Maximum Entropy)

This function finds matching function such that make output image maximum entropy, then using histogram specification to match input's histogram and matching function.

Based on idea of DSIHE, BPHEME tries to generalize by using histogram specification and solve optimize problem by Lagrange interpolation.

ci.BPHEME()
  • Return: image after equalization

RLBHE (Range Limited Bi-Histogram Equalization)

This function is similar to BBHE except using otsu's method instead of mean. Moreover, this limit range of gray level such that output image has minimum mean brightness error.

This method tries to equalize histogram for foreground and background separately by Otsu's method.

ci.RLBHE()
  • Return: image after equalization

RMSHE (Recursively Mean-Separate Histogram Equalization)

This function recursively separate histogram by mean. Therefore, recursive = 2 will create 4 sub-histograms, then equalize each sub-histograms.

Same idea as BBHE but recursively separate to preserve more brightness.

ci.RMSHE(recursive = 2)
  • Parameter recurive: number of recursive time
  • Return: image after equalization

RSIHE (Recursive Sub-Image Histogram Equalization)

This function is similar to RMSHE except using median instead of mean.

Same idea as DSIHE but recursively separate to preserve more brightness.

ci.RSIHE(recursive = 2)
  • Parameter recurive: number of recursive time
  • Return: image after equalization

RSWHE (Recursive Separated and Weighted Histogram Equalization)

This function recursively separate histogram by mean or median, then weighting each sub-histogram before equalize them.

This method similar to RMSHE and RSIHE except weighting sub-histogram to avoid local extreme value in histogram.

ci.RSWHE(type = 'mean', beta = 0, recursive = 2)
  • Parameter type: 'mean' or 'median'
  • Parameter beta: increasing more brightness in output image
  • Parameter recurive: number of recursive time
  • Return: image after equalization

FHSABP (Flattest Histogram Specification with Accurate Brightness Preservation)

This function finds matching function such that make the flattest output's histogram, then using histogram specification to match input's histogram and matching function.

Because of discrete, histogram equalization does not often the flattest histogram. FHSABP tries to solve optimization function to find the flattest output's histogram.

ci.FHSABP()
  • Return: image after equalization

WTHE (Weighted Thresholded Histogram Equalization)

This function weight histogram before equalize it.

ci.WTHE(root, value, lower = 0)
  • Return: image after equalization

AGCWD (Adaptive Gamma Correction with Weighting Distribution)

This function automatic correct gamma using weighting distribution

ci.AGCWD(alpha)
  • Parameter alpha: adjustment
  • Return: image after equalization

AGCCPF (Adaptive Gamma Correction Color Preserving Framework)

This similar to AGCWD except smooth pdf

ci.AGCCPF(alpha)
  • Parameter alpha: adjustment
  • Return: image after equalization

Quantitation

Store all functions to quantity output image

from contrast_image import quantitation

quantitation = Quantitation()

AMBE (Absolute Mean Brightness Error)

ci.AMBE(input_image, output_image)

PSNR (Peak Signal to Noise Ratio)

ci.PSNR(input_image, output_image)

Entropy

ci.Entropy(image)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Release files for contrast-image 0.1.6

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

Source distribution (sdist)

Source distribution for contrast-image 0.1.6
File Size Uploaded
contrast_image-0.1.6.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contrast-image 0.1.6
File Interpreter ABI Platform
contrast_image-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / contrast_image-0.1.6.tar.gz

Download URL contrast_image-0.1.6.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
65a39d292e19b565815b0d08cde860b94b4f982c6e32e7e2c072d9dd835e84be
BLAKE2b-256 checksum
How to use checksums
7a850ed8f5777cd0ba08445e2dc8f219e72d030ec3e4657bda1acece0b8a510c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

Release files / contrast_image-0.1.6-py3-none-any.whl

Download URL contrast_image-0.1.6-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0c96b1f8c5e72719e84a514dcc04c41bcce4f5bdee159d7861e50c9a9c3539f
BLAKE2b-256 checksum
How to use checksums
76729ad5419f44eed6c1c84af36df52c7e5d1051429dd7f2dd3ea7afeb2fa458
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

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