Skip to main content

This module attempts to enhance contrast of a given image by employing a method called HBLPCE.

Project description


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.


Run the following to install:

pip install imhblpce


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))

if __name__ == '__main__': main()


imhblpce --input 'Countryside.jpg' --output 'Countryside-imhblpce.jpg'


This is a sample image Countryside.jpg Image The sample image enhanced by HBLPCE method Countryside-imhblpce.jpg Image

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

imhblpce-0.0.6.tar.gz (3.7 MB view hashes)

Uploaded source

Built Distribution

imhblpce-0.0.6-py3-none-any.whl (5.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page