This module attempts to enhance contrast of a given image by employing a method called HBLPCE.
Project description
imhblpce
This module attempts to enhance contrast of a given image by employing a method called HBLPCE [Histogram-Based Locality-Preserving Contrast Enhancement]. This method enhances contrast of an image through equalizing its histogram, while keeping an eye on histogram's general shape, to conserve overall brightness and prevent excessive enhancement of the image.
You can access the article that came up with this method here.
Through formulating their approach, a minimization problem is introduced and solved using cvxpy library in python.
Installation
Run the following to install:
pip install imhblpce
Usage
import numpy as np
import cv2
from imhblpce import imhblpce
def imresize(img, wr=500, hr=None): # This is just for imshow-ing images with titles
[ h, w, d] = img.shape
hr = (h*wr)//w if not hr else hr
img_resized = cv2.resize(img, dsize=(wr, hr))
return img_resized
def main():
image_name = 'assets/Countryside.jpg'
image = cv2.imread(image_name)
# converts rgb image to hsv
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
v_image = hsv_image[:, :, 2]
v_image_hblpce = imhblpce(v_image)
hsv_image_hblpce = hsv_image.copy()
hsv_image_hblpce[:, :, 2] = v_image_hblpce
image_hblpce = cv2.cvtColor(hsv_image_hblpce, cv2.COLOR_HSV2BGR)
# This is just for imshow-ing images with titles
cv2.imshow('Original Image', imresize(image))
cv2.imshow('HBLPCE-d Image', imresize(image_hblpce))
cv2.waitKey(0)
if __name__ == '__main__': main()
Or
imhblpce --input 'Countryside.jpg' --output 'Countryside-imhblpce.jpg'
Showcase
This is a sample image The sample image enhanced by HBLPCE method
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
Built Distribution
File details
Details for the file imhblpce-0.0.6.tar.gz
.
File metadata
- Download URL: imhblpce-0.0.6.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12f6a65f1974610c7f6d2422c1afc4509cd0b0c6ace78a9c7142a6d079dd988a |
|
MD5 | a0d04c589437c006cf42f6ab30082772 |
|
BLAKE2b-256 | 7a29d1d38eeff5c6237b02f8b9585db549220c07b739bb32365c93fe6aa494d4 |
File details
Details for the file imhblpce-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: imhblpce-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b32111242cd14d0d16d965ef6a6fa5880af966c5be7142aa58e739c2d2c790 |
|
MD5 | 05f657a23ac44568b33c6af981b245ef |
|
BLAKE2b-256 | f677fce8cb685e90d73247e948728c06cd03472352432dfa54bd6cac8e6db301 |