🌈 Library to work with contrast
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file contrast_image-0.1.6.tar.gz
.
File metadata
- Download URL: contrast_image-0.1.6.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a39d292e19b565815b0d08cde860b94b4f982c6e32e7e2c072d9dd835e84be |
|
MD5 | 8adc37db3cbc9fe827cb57d2d88e995a |
|
BLAKE2b-256 | 7a850ed8f5777cd0ba08445e2dc8f219e72d030ec3e4657bda1acece0b8a510c |
File details
Details for the file contrast_image-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: contrast_image-0.1.6-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0c96b1f8c5e72719e84a514dcc04c41bcce4f5bdee159d7861e50c9a9c3539f |
|
MD5 | 068589f304170182c459aad92bb2e9fb |
|
BLAKE2b-256 | 76729ad5419f44eed6c1c84af36df52c7e5d1051429dd7f2dd3ea7afeb2fa458 |