This module attempts to enhance contrast of a given image by employing a method called weighted thresholded histogram equalization (WTHE).
Project description
imWeightedThresholdedheq
This module attempts to enhance contrast of a given image or video by employing a method called weighted thresholded histogram equalization (WTHE). This method seeks to improve on preformance of the conventional histogram equalization method by adding controllable parameters to it. By weighting and thresholding the PMF of the image before performing histogram equalization, two parameters are introduced that can be changed manually, but by experimenting on a variety of images, optimal values for both parameters are calculated (r = 0.5, v = 0.5).
You can access the article that came up with this method here.
Installation
Run the following to install:
pip install imWeightedThresholdedheq
Usage
import numpy as np
import cv2
from imWeightedThresholdedheq import imWTHeq
cap = cv2.VideoCapture('assets/Arctic-Convoy-With-Giant-Mack-Trucks.mp4')
# output video without sound
video_out_name = 'assets/output.mp4'
i = 0
j = 0
Wout_list = np.zeros((10))
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
frame_hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
frame_v = frame_hsv[:, :, 2].copy()
image_heq, Wout = imWTHeq(frame_v, Wout_list, r=0.5, v=0.5)
Wout_list[j] = Wout
j += 1
if j == 10:
j = 0
frame_hsv[:, :, 2] = image_heq
frame_eq = cv2.cvtColor(frame_hsv, cv2.COLOR_HSV2BGR)
fps = cap.get(cv2.CAP_PROP_FPS)
if i==0:
h, w, d = frame_eq.shape
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_out = cv2.VideoWriter(video_out_name, fourcc, fps, (w, h))
video_out.write(frame_eq)
i+=1
cv2.destroyAllWindows()
video_out.release()
Showcase
- A 5 minutes comparative video: https://youtu.be/5H_EY_ugmzg
- This is a sample video
The sample video enhanced by WTHE 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 imWeightedThresholdedheq-0.0.4.tar.gz
.
File metadata
- Download URL: imWeightedThresholdedheq-0.0.4.tar.gz
- Upload date:
- Size: 209.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e952d4daee2a9a37511c233978624c29c61bbaa45d172564a0a486192701b3ca |
|
MD5 | 67e5f217fdd88210774a468f06e9b339 |
|
BLAKE2b-256 | a8f51da056c5d41dfc4ae1796a881cd6328c9624a2fdc59a1ce417b9d675b94e |
File details
Details for the file imWeightedThresholdedheq-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: imWeightedThresholdedheq-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c4261713eb128309ce15efe2b37303c42f968d41eaad5a6f375e77795ec2d74 |
|
MD5 | c4a74bdd8987cd52e0870755f3c28ee9 |
|
BLAKE2b-256 | d1829608fac7928f15cde12627fc020b3b8ffaa033b87ede7a063336c2f242d6 |