Code Monkey home page Code Monkey logo

utkarsh-deshmukh / single-image-dehazing-python Goto Github PK

View Code? Open in Web Editor NEW
96.0 3.0 24.0 7.7 MB

python implementation of the paper: "Efficient Image Dehazing with Boundary Constraint and Contextual Regularization"

License: BSD 2-Clause "Simplified" License

Python 100.00%
computer-vision image-dehazing python opencv haze-removal haze-removal-algorithm defogging fog-removal single-image-dehazing single-image-defogging airlight-estimation ieee

single-image-dehazing-python's Introduction

Single-Image-Dehazing-Python

python implementation of the paper: "Efficient Image Dehazing with Boundary Constraint and Contextual Regularization"

Installation and Running the tests

method 1

pip install image_dehazer

Usage:

import image_dehazer										# Load the library

HazeImg = cv2.imread('image_path')						# read input image -- (**must be a color image**)
HazeCorrectedImg, HazeTransmissionMap = image_dehazer.remove_haze(HazeImg)		# Remove Haze

cv2.imshow('input image', HazeImg);						# display the original hazy image
cv2.imshow('enhanced_image', HazeCorrectedImg);			# display the result
cv2.waitKey(0)											# hold the display window

user controllable parameters (with their default values):

airlightEstimation_windowSze=15
boundaryConstraint_windowSze=3
C0=20
C1=300
regularize_lambda=0.1
sigma=0.5
delta=0.85
showHazeTrasmissionMap=True

method 2

  1. Go to the src folder
  2. run the file "example.py"
  3. sample images are stored in the "Images/" folder
  4. Output images will be stored in the "outputImages/" folder

Libraries needed:

1.numpy==1.19.0

2.opencv-python

3.scipy

Theory

This code is an implementation of the paper "Efficient Image Dehazing with Boundary Constraint and Contextual Regularization" The algorithm can be divided into 4 parts:

  • Airlight estimation
  • Calculating boundary constraints
  • Estimate and refine Transmission
  • Perform Dehazing using the estimated Airlight and Transmission

License

  • This project is licensed under the BSD 2 License - see the LICENSE.md file for details

Acknowledgements

  • The author would like to thank "Gaofeng MENG" and his implementation of his algorithm: https://github.com/gfmeng/imagedehaze

  • The author would like to thank Gaofeng MENG, Ying WANG, Jiangyong DUAN, Shiming XIANG, Chunhong PAN for their paper "Efficient Image Dehazing with Boundary Constraint and Contextual Regularization"

  • The author would like to thank Alexandre Boucaud. The function psf2otf was obtained from his repository. (https://github.com/aboucaud/pypher/blob/master/pypher/pypher.py)

  • The Author would like to thank Dr. Suresh Merugu for his matlab implementation of the codes. This repository is the python implementation of the matlab codes.

  • The Author would like to thank Mayank Singal for his repository "PyTorch-Image-Dehazing" which gives a pytorch implementation of the AOD-Net architecture. Link to ICCV 2017 paper

Merugu, Suresh. (2014). Re: How to detect fog in an image and then enhance the image to remove fog?. Retrieved from: https://www.researchgate.net/post/How_to_detect_fog_in_an_image_and_then_enhance_the_image_to_remove_fog/53ae3f10d2fd64c3648b45a9/citation/download.

Citation

@INPROCEEDINGS{6751186, 
  author={G. Meng and Y. Wang and J. Duan and S. Xiang and C. Pan}, 
  booktitle={IEEE International Conference on Computer Vision}, 
  title={Efficient Image Dehazing with Boundary Constraint and Contextual Regularization}, 
  year={2013}, 
  volume={}, 
  number={}, 
  pages={617-624}, 
  month={Dec},}

Results

2

1

3

Performance Comparison:

In this section, I am comparing the dehazing output with that of AOD-Net. I am using this python implementation of AOD-Net to run a pretrained AOD-Net model image

Here are some cases where AOD-Net is better: image

single-image-dehazing-python's People

Contributors

utkarsh-deshmukh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

single-image-dehazing-python's Issues

Real time

Can This algorithm works with a real time video?

Does not work with Python2.7

  Downloading image_dehazer-0.0.4.tar.gz (5.0 kB)

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
DEPRECATION: The -b/--build/--build-dir/--build-directory option is deprecated and has no effect anymore. pip 21.1 will remove support for this functionality. A possible replacement is use the TMPDIR/TEMP/TMP environment variable, possibly combined with --no-clean. You can find discussion regarding this at https://github.com/pypa/pip/issues/8333.
ERROR: Could not find a version that satisfies the requirement numpy==1.19.0 (from image-dehazer) (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0b3, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.11.1rc1, 1.11.1, 1.11.2rc1, 1.11.2, 1.11.3, 1.12.0b1, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.1rc1, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 1.13.3, 1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6)
ERROR: No matching distribution found for numpy==1.19.0 (from image-dehazer)

Not working with pip install

Hello brother shared code example is not working with pip install

The following error

File "/home/mrtan/ritvik/image_dehazer.py", line 15, in
HazeCorrectedImg, HazeMap = image_dehazer.remove_haze(HazeImg) # Remove Haze
AttributeError: partially initialized module 'image_dehazer' has no attribute 'remove_haze' (most likely due to a circular import)

difference in calling dehazing using pip package

In the readme it show the implementation of the dehazing as follows

$ import image_dehazer										# Load the library

$ HazeImg = cv2.imread('image_path', 0)						# read input image
$ HazeCorrectedImg = image_dehazer.remove_haze(HazeImg)	

That means we are loading the image as grayscale and simply passing that image in remove_haze function.

But in example.py we are doing the following

HazeImg = cv2.imread('../Images/foggy_bench.jpg')
# Resize image
'''
Channels = cv2.split(HazeImg)
rows, cols = Channels[0].shape
HazeImg = cv2.resize(HazeImg, (int(0.4 * cols), int(0.4 * rows)))
'''
# Estimate Airlight
windowSze = 15
AirlightMethod = 'fast'
A = Airlight(HazeImg, AirlightMethod, windowSze)
# Calculate Boundary Constraints
windowSze = 3
C0 = 20 # Default value = 20 (as recommended in the paper)
C1 = 300 # Default value = 300 (as recommended in the paper)
Transmission = BoundCon(HazeImg, A, C0, C1, windowSze) # Computing the Transmission using equation (7) in the paper
# Refine estimate of transmission
regularize_lambda = 1 # Default value = 1 (as recommended in the paper) --> Regularization parameter, the more this value, the closer to the original patch wise transmission
sigma = 0.5
Transmission = CalTransmission(HazeImg, Transmission, regularize_lambda, sigma) # Using contextual information
# Perform DeHazing
HazeCorrectedImg = removeHaze(HazeImg, Transmission, A, 0.85)

That is we are using the color image and calculating Transmission Airlight and then passing those values to removeHaze(HazeImg, Transmission, A, 0.85)

Is the pip documentation wrong/outdated? or image_dehazer.remove_haze(HazeImg) function calculates them internally? If so why we are using grayscale image?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.