This module attempts to enhance contrast of a given image by equalizing its two dimensional histogram.
Project description
im2dhisteq
This module attempts to enhance contrast of a given image by equalizing its two dimensional histogram. An easy way to enhance quality of a given image is to just equalize its histogram, but despite using minimum resources and a very short process time, there are a lot of drawbacks to it.
One of the ways to tackle drawbacks of histogram equalization method
is to instead equalize the image's two dimensional histogram
, as one dimensional histogram of a given image does not contain the image's contextual information. Tests on a multitude of images has shown, by taking contextual information of an image in addition to the image's histogram into account when attempting to enhance contrast, output images are significantly better in quality in compare to histogram equalizaion and a handful of other known methods.
You can access the article that came up with this method here.
Two Dimensional Histogram
Here is the source code for the im2dhist python library with a short description on how it's done.
Installation
Run the following to install:
pip install im2dhisteq
Usage
import numpy as np
import cv2
from im2dhisteq import im2dhisteq
def imresize(img, wr=500, hr=None): # This is just for imshow-ing images with titles
[ h, w] = img.shape
hr = (h*wr)//w if not hr else hr
img_resized = cv2.resize(img, dsize=(wr, hr))
return img_resized
def main():
fullname = 'cloudy-day.jpg'
image = cv2.imread(fullname)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# w_neighboring=6 is generally an adequate value, drived by a lot of experimenting.
# w_neighboring=6 corresponds to a 13*13 square
gray_image_2DHisteq = im2dhisteq(gray_image, w_neighboring=6)
# This is just for imshow-ing images with titles
gray_Image_resized = imresize(gray_image)
gray_Image_2DHisteq_resized = imresize(gray_image_2DHisteq)
cv2.imshow('Original Image', gray_Image_resized)
cv2.imshow('2DHeq Image', gray_Image_2DHisteq_resized)
cv2.waitKey(0)
if __name__ == '__main__': main()
Or
im2dhisteq --input 'cloudy-day.jpg' --output 'assets/cloudy-day-2dhisteq.jpg' --w 6
Showcase
- A one minute comparative video: https://youtu.be/tX1KbJ2ugdE
- This is a sample image and its corresponding 2d-histogram equalized image.
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
Hashes for im2dhisteq-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bef32d1d93a549d66af9a319715a2c390c55746cd6508f341908ffca23a61584 |
|
MD5 | 1391a339a3bac0f2535bc2be751015b3 |
|
BLAKE2b-256 | 541662a2ae6c128e130e315f09bd12946a769e330a8516c562630ed7cd4e37ad |