You are on page 1of 20

3.

2 Materials and Methods

This section critically examines tools, technologies and environmental setup used in devel-
oping the content trading system. It provides a detailed overview of software, hardware, and
setup procedures, enabling to understand the technical infrastructure supporting the project’s
objectives and methodologies.

3.2.1 Tools
1. Vs code: Visual Studio Code (VS Code) is a versatile and customizable integrated devel-
opment environment (IDE) developed by Microsoft. This platform, utilized for the project
on image dehazing, offers a range of library features essential for efficient development.
These include syntax highlighting, code completion, debugging capabilities, version con-
trol integration (such as Git), support for extensions, and a lightweight yet powerful in-
terface. These features enhance productivity, streamline the development process, and
provide flexibility for implementing and testing image dehazing algorithms effectively.

2. Kaggle Notebook: In a Kaggle notebook for a dehazing project, users can leverage var-
ious datasets available on the platform to train and evaluate their models. Kaggle hosts a
diverse range of datasets that may include hazy images paired with their corresponding
clear images, facilitating supervised learning approaches for dehazing algorithms. These
datasets may be sourced from different domains and environments, providing a rich vari-
ety of scenes and conditions for training robust dehazing models. Additionally, Kaggle’s
dataset exploration tools and community-driven discussions enable users to discover, an-
alyze, and contribute to datasets relevant to their dehazing project, fostering collaboration
and knowledge sharing within the data science community. Overall, the availability of
datasets on Kaggle enhances the accessibility and effectiveness of dehazing projects by
providing a wealth of data for training and experimentation.

3. Python: Python offers a versatile and efficient platform for dehazing, a crucial task in
image processing and computer vision. With libraries like OpenCV and scikit-image,
Python provides a rich ecosystem of tools for implementing dehazing algorithms. Addi-
tionally, machine learning frameworks such as TensorFlow and PyTorch enable the de-
velopment of sophisticated deep learning models for dehazing tasks. Python’s simplicity

9
and readability facilitate rapid prototyping and experimentation, making it an ideal choice
for developers working in the field of image enhancement and restoration.

4. CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz:The Intel Core i7-7700HQ


CPU @ 2.80GHz provides substantial computational power for dehazing tasks, whether
utilizing traditional CPU-based algorithms or deep learning CNN techniques. With its
quad-core architecture and high clock speed, the processor efficiently handles complex
image processing algorithms involved in dehazing. Deep learning CNNs excel at learning
intricate patterns from images, making them highly effective for dehazing tasks. Leverag-
ing the CPU’s multi-threading capabilities and processing powers, deep learning models
for dehazing can be trained and executed efficiently, enabling image enhancement. Thus,
the i7-7700HQ CPU serves as an ideal platform for implementing both traditional and
cutting-edge dehazing techniques, meeting the demands of various image processing ap-
plications.

10
Chapter 4

RESULTS AND ANALYSIS

In this chapter, a comprehensive examination of the outcomes of dehazing the images sep-
arately using Digital Image Processing techniques and Deep Learning, specifically employing
CNN is provided. It thoroughly assesses the quality and efficacy of each method in reducing
haze and enhancing image quality across diverse environmental conditions. Through compara-
tive evaluation, this section aims to elucidate the strengths and limitations of both approaches,
offering valuable insights into their respective performances. Rather than examining the result
by visual inspection, examination is also done quantitatively by metrics such as PSNR, SSIM,
and MAE, this analysis provides a detailed understanding of the effectiveness of digital image
processing versus deep learning techniques in dehazing images.

4.1 Results

1. Dehazed images using Digital Image Processing: Efficient dehazing of the images was
achieved through the application of Digital Image Processing techniques. The hazy image
Fig. 4.1 underwent dehazing using the Digital Image Processing technique to dehaze the
image and dehazed the image shown in Fig. 4.2.

Figure 4.1: Hazy Image

11
Figure 4.2: Dehazed image using Digital Image Processing

2. Dehazed images using CNN: The hazy image Fig.4.1 underwent dehazing using Con-
volutional Neural Network (CNN) techniques, leveraging the power of deep learning to
effectively mitigate the effects of haze and enhance image clarity. Fig.4.3 shows the de-
hazed image using CNN model.

Figure 4.3: Dehazed image using CNN

12
4.2 Performance Analysis
This section critically examines various aspects of the system’s performance. Through a
comprehensive discussion of these results, insights into the effectiveness of the proposed sys-
tem.

4.2.1 Evaluation Metrics


In addition to the subjective evaluation, three evaluation metrics are used to measure the
dehazing effects: peak signal-to-noise ratio (PSNR) structural similarity (SSIM) and Mean Ab-
solute Error (MAE). Higher PSNR and SSIM indicate better results, and lower MAE indicates
better results.

• Peak Signal-to-Noise Ratio (PSNR): It is the most widely used objective evaluation
standard for images. In other words, the value of this parameter depends on how far the
real image is from the restored image in terms of pixel match. Thus, PSNR is highly
sensitive to errors, and its unit is dB. PSNR should be maximized.

• Structural similarity (SSIM): The perception model is used to assess image similarity,
which takes into account three factors: brightness, contrast and structure. SSIM [0, 1],
Closer to 1 states the higher structural quality of the restored image.

• Mean Absolute Error (MAE): MAE measures the average absolute difference between
corresponding pixels of the original and processed images.

4.2.1.1 Digital Image Processing Technique


Across the five different images, Digital Image Processing consistently yields higher PSNR
values, indicating superior image quality compared to CNN is shown in the Fig. 4.4. Addi-
tionally, the SSIM scores are generally higher for Digital Image Processing, signifying better
preservation of structural details in the reconstructed images shown in the Fig. 4.5. Moreover,
Digital Image Processing results in lower MAE values, suggesting greater accuracy in repro-
ducing the original images shown in the Fig. 4.6. Notably, the highest PSNR value and SSIM
value achieved through Digital Image Processing is 24.37, 0.92 respectively,also the lower MAE
value is 10.36 demonstrating the exceptional quality attainable with this method.

13
4.2.1.2 CNN Method
In contrast, the Convolutional Neural Network (CNN) approach tends to produce lower
PSNR values across the evaluated 5 different images, indicating comparatively lower image
quality than Digital Image Processing as shown in the Fig. 4.4 . The SSIM scores for CNN are
also lower on average, indicating less preservation of structural details during reconstruction as
depicted in Fig. 4.5. Furthermore, in Fig. 4.6, CNN methods exhibit higher MAE values, sug-
gesting a higher degree of distortion and reduced accuracy in reproducing the original images.
These results highlight the challenges faced by CNN methods in achieving image enhancement
comparable to Digital Image Processing techniques.

Figure 4.4: PSNR of 5 images

Figure 4.5: SSIM of 5 images

14
Figure 4.6: MAE of 5 images

Table 4.1: Comparison of PSNR, SSIM and MAE for Digital Image Processing and CNN

Metrics
Image Method
PSNR SSIM MAE
1 Digital Image Processing 16.92 0.84 31.96
CNN 14.24 0.8 42.93
2 Digital Image Processing 16.95 0.82 31.19
CNN 15.24 0.87 37.92
3 Digital Image Processing 24.37 0.92 10.36
CNN 16.53 0.9 33.16
4 Digital Image Processing 20.39 0.92 20.46
CNN 14.07 0.8 41.2
5 Digital Image Processing 17.96 0.85 29.02
CNN 16.87 0.78 32.69

In Table 4.1, a detailed comparison is drawn between Digital Image Processing and Con-
volutional Neural Network (CNN) methods across five images, revealing notable performance
disparities. For each image, Digital Image Processing consistently outperforms CNN across all
metrics. For instance, in Image 1, Digital Image Processing achieves a PSNR of 16.92, SSIM
of 0.84, and MAE of 31.96, surpassing CNN’s corresponding values of 14.24, 0.8, and 42.93.
This trend persists across all images, with Digital Image Processing consistently yielding higher
PSNR values, indicating superior image quality preservation, along with higher SSIM scores

15
and lower MAE values, implying better structural preservation and reconstruction accuracy.

In conclusion, the comparison between Digital Image Processing and Deep Learning (CNN)
methods for dehazing images reveals significant differences in performance. While both ap-
proaches aim to enhance image clarity and quality by mitigating the effects of haze, Digital
Image Processing techniques consistently outperform CNN-based methods in terms of quan-
titative metrics such as PSNR, SSIM, and MAE. Also, training the deep learning models is
time-consuming and requires high-quality training labels.The Digital Image Processing method
achieves higher scores across all metrics, indicating better preservation of image details and
closer resemblance to ground truth. Moreover, visual inspection further confirms the superior
visual quality of images dehazed using Digital Image Processing techniques. Therefore, in the
context of dehazing images, Digital Image Processing demonstrates superior effectiveness over
Deep Learning (CNN), offering a more reliable and robust solution for enhancing image clarity
and quality that can be effectively used for target detection.

16
Chapter 5

CONCLUSION

In conclusion, this project presents an effective dehazing method that combines digital im-
age processing techniques with deep learning, specifically CNN, to mitigate the challenges
posed by haze in outdoor and remote sensing images. By leveraging techniques such as Dark
Channel Prior, Atmospheric Scattering Model, Retinex, and Gaussian-weighted Image Fusion,
the proposed system successfully enhances image clarity and quality while reducing the effects
of haze. This method takes advantage of the image enhancement based dehazing methods and
image restoration based dehazing methods. To address the problem of inaccurate calculation of
transmittance in existing methods, a Gaussian-weighted image fusion is introduced to obtain a
refined transmittance. Additionally, the dehazed images are corrected using a USM method to
solve the color distortion problem. Comparative evaluation between digital image processing
and CNN-based dehazing methods reveals that digital image processing techniques consistently
outperform CNN in terms of quantitative metrics such as PSNR (22.3), SSIM (0.93) and MAE
(34.0). The digital image processing method achieves higher scores across these metrics, indi-
cating better preservation of image details, closer resemblance to ground truth and efficiently
removed haze. Visual inspection further confirms the superior visual quality of images dehazed
using digital image processing techniques. Therefore, in the context of dehazing images, digital
image processing demonstrates superior effectiveness over CNN, offering a more reliable and
robust solution for enhancing image clarity and quality, which is crucial for target detection in
various fields. Overall, this project provides a valuable contribution to the domain of outdoor
and remote sensing imaging by offering a robust dehazing solution applicable across diverse
scenarios, particularly those requiring precise target detection under challenging atmospheric
conditions.

17
Chapter 6

FUTURE SCOPE

In the future, the focus can be given to reduce the complexity of the method to facilitate
its implementation for real-time processing of image acquisition terminals. While our current
approach shows promise, further enhancements are necessary to address challenges associated
with dense haze and clouds. Specifically, aim to improve the dehazing performance in scenarios
where images contain dense clouds, as the current method may yield suboptimal results under
such conditions. This will involve exploring advanced techniques and algorithms tailored to
effectively remove dense haze, thereby enhancing the overall robustness and applicability of
the dehazing solution. Additionally, plan to investigate methods for optimizing computational
efficiency without compromising the quality of dehazed images, ensuring seamless integration
into real-time image processing systems. By addressing these aspects in the future work, we
aim to advance the capabilities of our dehazing method and enable its widespread deployment
in various practical applications requiring reliable haze removal.

18
BIBLIOGRAPHY

[1] Chenyang Li, Hang Yu, Suiping Zhou, Zhiheng Liu, Yuru Guo and Wenjie Zhang
”Efficient Dehazing Method for Outdoor and Remote Sensing Images” IEEE Jour-
nal Of Selected Topics In Applied Earth Observations and Remote Sensing, Vol.
16,2023,10.1109/JSTARS.2023.3274779

[2] A. A. J. Pazhani and S. Periyanayagi, “A novel haze removal computing architecture for
remote sensing images using multi-scale Retinex technique,” Earth Sci. Inform., vol. 15,
no. 2, pp. 1147–1154, Jun. 2022, doi: 10.1007/s12145-022-00798-4.

[3] H. Yu, C. Li, Z. Liu, Y. Guo, Z. Xie, and S. Zhou, “A novel nighttime dehazing model inte-
grating Retinex algorithm and atmospheric scattering model,” inProc. 3rd Int. Conf. Geol.,
Mapping Remote Sens., 2022, pp. 111–115, doi: 10.1109/ICGMRS55602.2022.9849369.

[4] . Song, D. Zhou, W. Li, H. Ding, Y. Dai, and L. Zhang, “WSAMF-Net: Wavelet spa-
tial attention-based multistream feedback network for single image dehazing,” IEEE
Trans. Circuits Syst. Video Technol., vol. 33, no. 2, pp. 575–588, Feb. 2023, doi:
10.1109/TCSVT.2022.3207020.

[5] https://www.kaggle.com/datasets/wwwwwee/dehaze

[6] F. A. Dharejo , “A deep hybrid neural network for single image dehazing via wavelet
transform,” Optik, vol. 231, Apr. 2021, Art. no. 166462, doi: 10.1016/j.ijleo.2021.166462.

[7] S. C. Pei and T. Y. Lee, Nighttime haze removal using color transfer pre-processing and
dark channel prior,” in Proc. IEEE 19th Int. Conf. Image Process., 2012, pp. 957–960, doi:
10.1109/ICIP.2012.6467020.

[8] J. Zhang, Y. Cao, S. Fang, Y. Kang, and C. W. Chen, “ Fast haze removal for night-
time image using maximum reflectance prior”, in Proc. IEEE Conf. Comput. Vis. Pattern
Recognit.,7 2017, pp. 7016–7024, doi: 10.1109/CVPR.2017.742

[9] J. Guo, J. Yang, H. Yue, H. Tan, C. Hou, and K. Li, “ RSDehazeNet: Dehazing net-
work with channel refinement for multispectral remote sensing images,” IEEE Trans.
Geosci. Remote Sens., vol. 59, no. 3, pp. 2535–2549, Mar. 2021, doi: 10.1109/T-
GRS.2020.3004556.

19
APPENDIX

Sample Code

1 import cv2
2 import numpy as np
3 import streamlit as st
4 from skimage.metrics import structural_similarity as ssim
5 from skimage.metrics import mean_squared_error as mse
6 import tensorflow as tf
7 from PIL import Image
8

9 # Function to evaluate the model


10 def evaluate(net, image):
11 # Resize the image to match model input shape
12 img = tf.image.resize(image, size=(384, 384))
13

14 # Normalize the image


15 img = img / 255
16 img = tf.expand_dims(img, axis=0) # Transform input image from 3
D to 4D
17

18 # Generate dehazed output


19 dehaze = net(img)
20

21 # Return the dehazed image


22 return dehaze[0]
23

24 # Load the SavedModel


25 loaded_model = tf.saved_model.load(’trained_model’)
26

27 def psnr(original, processed):


28 mse_value = mse(original, processed)
29 max_pixel = 255.0
30 return 10 * np.log10((max_pixel ** 2) / mse_value)

20
31

32 def ssim_index(original, processed):


33 min_dim = min(original.shape[:2])
34 win_size = min(7, min_dim) # Adjusted window size
35 win_size = win_size if win_size % 2 != 0 else win_size - 1 #
Ensure odd value
36 ssim_value = 0
37 for i in range(3): # Iterate over each channel
38 ssim_value += ssim(original[:, :, i], processed[:, :, i],
win_size=win_size, data_range=255)
39 return ssim_value / 3 # Return average SSIM across channels
40

41 def mean_absolute_error(original, processed):


42 return np.mean(np.abs(original - processed))
43

44 def dark_channel_prior(image):
45 dark_channel = cv2.ximgproc.createFastGlobalSmootherFilter(image,
10, 0.05)
46 dark_channel = dark_channel.filter(image)
47 return dark_channel
48

49 def dehaze_ASM(image, omega=0.78, t0=0.01):


50 dark_channel = dark_channel_prior(image)
51 atmospheric_light = np.percentile(image, 90, axis=(0, 1))
52 transmission = 1 - omega * dark_channel / atmospheric_light
53 transmission[transmission < t0] = t0
54 dehazed_channels = []
55 for i in range(3):
56 dehazed_channel = ((image[:, :, i].astype(np.float32) -
atmospheric_light[i]) / transmission[:, :, 0]) + atmospheric_light
[i]
57 dehazed_channels.append(dehazed_channel)
58 dehazed_image = np.stack(dehazed_channels, axis=-1)
59 dehazed_image = np.clip(dehazed_image, 0, 255).astype(np.uint8)
60 return dehazed_image

21
61

62 def retinex(image, sigma=100, gain=128):


63 log_image = np.log1p(image.astype(np.float32))
64 blurred = cv2.GaussianBlur(log_image, (0, 0), sigma)
65 retinex_image = np.clip(log_image - blurred + gain, 0, 255).
astype(np.uint8)
66 return retinex_image
67 def gaussian_weighted_fusion(image1, image2, alpha=0.5):
68 fused_image = cv2.addWeighted(image1, alpha, image2, 1-alpha, 0)
69 return fused_image
70 def unsharp_mask(image, sigma=1.0, strength=1.5):
71 blurred = cv2.GaussianBlur(image, (0, 0), sigma)
72 sharpened = cv2.addWeighted(image, 1.0 + strength, blurred, -
strength, 0)
73 return sharpened
74 def main():
75 st.title("Image Enhancement App")
76 uploaded_image = st.file_uploader("Upload an image", type=["jpg",
"jpeg", "png", "webp"])
77 omega = 0.58
78 t0 = 0.01
79 sigma_retinex = 100
80 gain_retinex = 128
81 alpha_fusion = 0.5
82 sigma_usm = 1.0
83 strength_usm = 1.5
84

85 if uploaded_image is not None:


86 image = np.array(bytearray(uploaded_image.read()), dtype=np.
uint8)
87 image1 = Image.open(uploaded_image)
88 img_array = np.array(image1)
89 original_image = cv2.imdecode(image, -1)
90 st.image(original_image, caption="Original Image",
use_column_width=True)

22
91

92 if st.button("Enhance"):
93 try:
94 dehazed_img = dehaze_ASM(original_image, omega=omega,
t0=t0)
95 retinex_img = retinex(original_image, sigma=
sigma_retinex, gain=gain_retinex)
96 fused_transmittance = gaussian_weighted_fusion(
dehazed_img, retinex_img, alpha=alpha_fusion)
97 corrected_img = unsharp_mask(dehazed_img, sigma=
sigma_usm, strength=strength_usm)
98 st.image(corrected_img, caption="Image Processed
Dehazed Image", use_column_width=True)
99 # Convert images to float32 for metrics calculation
100 original_float = original_image.astype(np.float32)
101 enhanced_float = corrected_img.astype(np.float32)
102 # Calculate PSNR
103 psnr_value = psnr(original_float, enhanced_float)
104 st.write("PSNR:", round(psnr_value, 2))
105 # Calculate SSIM
106 ssim_value = ssim_index(original_float,
enhanced_float)
107 st.write("SSIM:", round(ssim_value, 2))
108 # Calculate MAE
109 mae_value = mean_absolute_error(original_float,
enhanced_float)
110 st.write("MAE:", round(mae_value, 2))
111 # Generate CNN-based dehazed image and metrics
112 cnn_dehazed_img_tensor = evaluate(loaded_model,
img_array)
113 cnn_dehazed_img_numpy = cnn_dehazed_img_tensor.numpy
() # Convert TensorFlow tensor to numpy array
114 cnn_dehazed_img_resized = cv2.resize(
cnn_dehazed_img_numpy, (original_image.shape[1], original_image.
shape[0]))

23
115 cnn_dehazed_img_resized_display = cv2.convertScaleAbs
(cnn_dehazed_img_resized, alpha=(255.0/cnn_dehazed_img_resized.max
()))
116 # Normalize pixel values to range [0, 1]
117 cnn_dehazed_img_resized = cnn_dehazed_img_resized /
255.0
118 st.image(cnn_dehazed_img_resized_display, caption=’
CNN-based Dehazed Image’, use_column_width=True)
119 # Convert CNN-based dehazed image to float32 for
metrics calculation
120 cnn_dehazed_float = cnn_dehazed_img_resized.astype(np
.float32)
121 # Calculate PSNR, SSIM, and MAE for CNN-based
dehazed image
122 cnn_psnr_value = psnr(original_float,
cnn_dehazed_float)
123 st.write("PSNR (CNN-based Dehazed Image):", round(
cnn_psnr_value, 2))
124 cnn_ssim_value = ssim_index(original_float,
cnn_dehazed_float)
125 st.write("SSIM (CNN-based Dehazed Image):", round(
cnn_ssim_value, 2))
126 cnn_mae_value = mean_absolute_error(original_float,
cnn_dehazed_float)
127 st.write("MAE (CNN-based Dehazed Image):", round(
cnn_mae_value, 2))
128 except Exception as e:
129 st.write("Error occurred during processing:", e)
130

131 if __name__ == "__main__":


132 main()

24
Project Screenshots

Figure 6.1: Haze image

25
Dehazed Image

Figure 6.2: Dehazed image using Digital Image processing

26
Figure 6.3: Dehazed Image using CNN

27
GitHub History

Figure 6.4: GitHub History

28

You might also like