[![PyPI Latest Release](https://img.shields.io/pypi/v/imhblpce.svg)](https://pypi.org/project/imhblpce/)
[![Package Status](https://img.shields.io/pypi/status/imhblpce.svg)](https://pypi.org/project/imhblpce/)
[![Downloads](https://pepy.tech/badge/imhblpce)](https://pepy.tech/project/imhblpce)
[![License](https://img.shields.io/pypi/l/imhblpce.svg)](https://github.com/Mamdasn/imhblpce/blob/main/LICENSE)
![Repository Size](https://img.shields.io/github/repo-size/mamdasn/imhblpce)
# 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](https://www.researchgate.net/publication/272424815_Histogram-Based_Locality-Preserving_Contrast_Enhancement).
Through formulating their approach, a minimization problem is introduced and solved using cvxpy library in python.
## Installation
Run the following to install:
```python
pip install imhblpce
```
## Usage
```python
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
```Bash
imhblpce --input 'Countryside.jpg' --output 'Countryside-imhblpce.jpg'
```
## Showcase
This is a sample image
![Countryside.jpg Image](https://raw.githubusercontent.com/Mamdasn/imhblpce/main/assets/Countryside.jpg "Countryside.jpg Image")
The sample image enhanced by HBLPCE method
![Countryside-imhblpce.jpg Image](https://raw.githubusercontent.com/Mamdasn/imhblpce/main/assets/Countryside-imhblpce.jpg "Countryside-imhblpce.jpg")
Raw data
{
"_id": null,
"home_page": "https://github.com/Mamdasn/imhblpce",
"name": "imhblpce",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,histogram,imhblpce,hblpce,histogram equalization,histogram based equalization,histogram locality preserving,contrast enhancement",
"author": "mamdasn s",
"author_email": "<mamdassn@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/15/9a/a81700f4664004d8a8b75e76a85174aa706c31a35a734965ef1c3164b558/imhblpce-1.0.0.tar.gz",
"platform": null,
"description": "\n[![PyPI Latest Release](https://img.shields.io/pypi/v/imhblpce.svg)](https://pypi.org/project/imhblpce/)\n[![Package Status](https://img.shields.io/pypi/status/imhblpce.svg)](https://pypi.org/project/imhblpce/)\n[![Downloads](https://pepy.tech/badge/imhblpce)](https://pepy.tech/project/imhblpce)\n[![License](https://img.shields.io/pypi/l/imhblpce.svg)](https://github.com/Mamdasn/imhblpce/blob/main/LICENSE)\n![Repository Size](https://img.shields.io/github/repo-size/mamdasn/imhblpce)\n\n\n# imhblpce\nThis 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. \n\nYou can access the article that came up with this method [here](https://www.researchgate.net/publication/272424815_Histogram-Based_Locality-Preserving_Contrast_Enhancement). \n\nThrough formulating their approach, a minimization problem is introduced and solved using cvxpy library in python.\n\n## Installation\n\nRun the following to install:\n\n```python\npip install imhblpce\n```\n\n## Usage\n\n```python\nimport numpy as np\nimport cv2\nfrom imhblpce import imhblpce\n\ndef imresize(img, wr=500, hr=None): # This is just for imshow-ing images with titles\n [ h, w, d] = img.shape\n hr = (h*wr)//w if not hr else hr\n img_resized = cv2.resize(img, dsize=(wr, hr))\n return img_resized\n\ndef main():\n image_name = 'assets/Countryside.jpg'\n image = cv2.imread(image_name)\n\n # converts rgb image to hsv\n hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)\n v_image = hsv_image[:, :, 2]\n v_image_hblpce = imhblpce(v_image)\n \n hsv_image_hblpce = hsv_image.copy()\n hsv_image_hblpce[:, :, 2] = v_image_hblpce\n image_hblpce = cv2.cvtColor(hsv_image_hblpce, cv2.COLOR_HSV2BGR)\n\n # This is just for imshow-ing images with titles\n\n cv2.imshow('Original Image', imresize(image))\n cv2.imshow('HBLPCE-d Image', imresize(image_hblpce))\n cv2.waitKey(0)\n \nif __name__ == '__main__': main()\n``` \nOr \n```Bash\nimhblpce --input 'Countryside.jpg' --output 'Countryside-imhblpce.jpg'\n``` \n\n## Showcase\nThis is a sample image\n![Countryside.jpg Image](https://raw.githubusercontent.com/Mamdasn/imhblpce/main/assets/Countryside.jpg \"Countryside.jpg Image\")\nThe sample image enhanced by HBLPCE method\n![Countryside-imhblpce.jpg Image](https://raw.githubusercontent.com/Mamdasn/imhblpce/main/assets/Countryside-imhblpce.jpg \"Countryside-imhblpce.jpg\")\n",
"bugtrack_url": null,
"license": "",
"summary": "This module attempts to enhance contrast of a given image by employing a method called HBLPCE.",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/Mamdasn/imhblpce"
},
"split_keywords": [
"python",
"histogram",
"imhblpce",
"hblpce",
"histogram equalization",
"histogram based equalization",
"histogram locality preserving",
"contrast enhancement"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0f399d670945fcc4b9bb6f94b57bc73a2dfa00241cd2d4fa0224d6c838a7c3f1",
"md5": "b48477709e38f3c752249072794931a5",
"sha256": "c4144520a9669199f65c68c530fd9c403220c44228dac3a2da4fc614d5451df4"
},
"downloads": -1,
"filename": "imhblpce-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b48477709e38f3c752249072794931a5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 16679,
"upload_time": "2023-12-23T15:18:32",
"upload_time_iso_8601": "2023-12-23T15:18:32.289019Z",
"url": "https://files.pythonhosted.org/packages/0f/39/9d670945fcc4b9bb6f94b57bc73a2dfa00241cd2d4fa0224d6c838a7c3f1/imhblpce-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "159aa81700f4664004d8a8b75e76a85174aa706c31a35a734965ef1c3164b558",
"md5": "ee0c79c2063fe599b83d882b293322af",
"sha256": "5c895750b11563635e1d67e4a0b320c079416168050296be8b77f04c6afe3db1"
},
"downloads": -1,
"filename": "imhblpce-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "ee0c79c2063fe599b83d882b293322af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3690721,
"upload_time": "2023-12-23T15:18:34",
"upload_time_iso_8601": "2023-12-23T15:18:34.245201Z",
"url": "https://files.pythonhosted.org/packages/15/9a/a81700f4664004d8a8b75e76a85174aa706c31a35a734965ef1c3164b558/imhblpce-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-23 15:18:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Mamdasn",
"github_project": "imhblpce",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "imhblpce"
}