Denoising of Images Using Autoencoders

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Denoising Of Images Using

AutoEncoders

Under the guidance of - Prof. Dr. Monica Subashini M

J Component Project Report EEE1007 (Winter Semester 2020-21)

SUBMITTED BY:

KINJAL SARKAR (19BEE0221)

SUDESHA BASU MAJUMDER(19BEE0228)

1
INDEX
1. ABSTRACT………………………………………………………………………4

1.1 OBJECTIVE…………………………………………………………….……4

1.2 EXPECTED OUTCOME WITH ACCURACY……………………………..4

2. INTRODUCTION………………………………………………………………..5

2.1 LITERATURE SURVEY.…………………………………………………..6

2.2 NOVELTY OF WORK……………………………………………………..7

3. METHODOLOGY…………..…………………………………………………..8

3.1 DATASET USED IN PROJECT……………………….…………………..8

3.2 SAMPLE DATASET……………………………………………………….8

3.3 BLOCK DIAGRAM…………………………………….……………….....8

3.4 EXPLANATION…………………………..………………………………..9

4. IMPLEMENTATION…………………………………………………………..10

4.1 FLOWCHART……………………...……………………………………...10

4.2 ALGORITHM…………………..………………………………………….11

4.3 CODE……………………..………………………………………………..11

5. RESULTS…………………….……………………..…………………………..14

5.1 FINAL RESULTS…………………………………….……………………..14

5.2 GRAPHS……...……………………………………………………………...15

5.3 SUMMARY……………………………………….…………………………16

6. CONCLUSION………………………………………………………………….17
7. REFERENCES……………………………….………………………………….17

2
ACKNOWLEDGEMENT:
This is to certify that the project work entitled “Denoising Of Images Using
AutoEncoders” that is being submitted by Kinjal Sarkar, Sudesha Basu
Majumder, for Neural Networks and Fuzzy Control is a record of bonafide
work done under Prof. Dr. Monica Subashini M. The contents of this Project
Work, in full or in parts, have neither been taken from any other source nor
have been submitted for any other CAL courses.

3
1. ABSTRACT:-

1.1 OBJECTIVE

For the enhancement of images and the extraction of relevant


information from them, image processing techniques are widely
utilised in the fields of sciences and computer vision. The
elimination of various types of noise from images is a crucial step
in image processing. During the storage, transmission, or
acquisition of photographs, noise might appear in the image.If a
model achieves both picture preservation and noise removal, it is
considered a satisfactory de-noising model. Gaussian, salt and
pepper, Speckle, and other types of noise can be found in an
image. A model that can denoise several types of noises is seen
to be superior to others.In this paper, we provide an autoencoder-
based model for removing various types of noise from pictures.
We used Gaussian noise, loss function MSE data, Optimizer
Adam to denoise the images.

1.2 EXPECTED OUTCOME WITH ACCURACY


In our project we collect data from Kaggle which is a dataset
consisting of coloured cat images, we add gaussian noise to the
images and our expected outcome is a denoised image with an
expected accuracy of 76.77%.

4
2. INTRODUCTION:-
The progression within the innovation of computerized
photography is momentous. It can provide dark and white
photographs and recordings color and reestablish any mutilated
pictures, which can be convenient prove for measurable
purposes. Computer vision and profound learning methods just
include this. Neural networks and convolution neural systems are
well known for their information modeling methods and approach.

Keras includes a surprisingly effective Python-based neural


network API, and it runs on the top of Tensorflow.

Picture information is made up of pixels. In black and white


pictures, each pixel shows a number extending from 0 to255. A
color picture contains the pixel combination red (R), green (G),
blue (B), each extending from 0 to 255. Autoencoders are labeled
under self-supervised learning. A few say it's unsupervised as
they are autonomous of the labeled reactions when coming to
classification. They are utilized by neural networks to perform
representation learning.

To remove the noise from a picture, it is vital to decrease its


dimensionality. Principal Component Analysis (PCA) is utilized to
perform this task. But PCA has restrictions; it only applies linear
transformation and also contains exceptions. On the other hand,
autoencoders can present nonlinearity into the network with the
assistance of their non-linear activation functions and the stack of
numerous layers. Exceptions, a by-product of dimensionality
reduction, can effortlessly be identified by utilizing this neural
network

5
2.1 LITERATURE SURVEY:

Denoising images is a fundamental component of neural


networks. Vincent et al [7] introduced its expanded standard
addition of autoencoder to learn reconstruction of input given its
noisy version. Denoising autoencoders uses a stacked technique
in which the output of one neural network is fed into the input of
another neural network[8] X. In comparison to sparse autoencoder
with KL Divergence, Jiang et al [1] presented a form of auto
encoder to pre-train deep neural networks as a basic block. The
employment requires some limitations, as well as the light level of
concealed units. L. Gondara [3] provided a method for determining
the best architecture for small-sample denoising. This research
looked into a variety of image architectures that were similar and
had a high resolution. He used a variety of image denoising
techniques, including median filters and SVD (Singular value
decomposition) for image preprocessing, as well as DAE and
CNN (Convolutional Neural Network) for improving and boosting
the performance of denoising to increase the training sample size
and combine by means of. By leveraging convolutional neural
nets, Jain et al. [4] expanded work on image denoising. It was
discovered that by using a small example of picture preparation,
execution at standard or better than state-of-the-art in terms of
wavelets and Markov arbitrary view may be achieved. For image
denoising and in work of art, Xie et al. [5] used stacked meagre
autoencoders, which performed well with KSVD. Agostinelli et al.
[6] investigated various approaches to flexible multi-section deep
neural networks for image denoising, which were built using a
combination of stacked scanty autoencoders. This structure
proved to be strong enough for a variety of commotion
compositions. C. Xing proposed work at el [2]. The DL approach
is used to remove attributes from hyper-spectral data. The
employed work produces good discriminability for classification

6
task and SDAE (Stacked Denoising Autoencoder) to pre-train
model, in network first layer logistic regression method is exploited
to persuade a deep network for classification and feature
extraction in include supervised fine-tuning and unsupervised pre-
training, the employed work produces good discriminability for
classification task and SDAE (Stacked Denoise Autoencoder) to
pre-train model, in network first layer logistic regression method.
The SDAE pre-training in aggregate by means of the LR
enhancement and classification (SDAE LR) can achieve higher
accuracies than the well-known SVM(Support Vector Machine)
classifier, according to the results obtained using ROSIS hyper
spectrum data, Hyper ion, and AVIRIS.

2.2 NOVELTY OF WORK

The complexity when it comes to denoising a RGB schemed


image is very high. In our project we build a simple
convolutional neural network with 6 convolutional layers
where the noisy image is fed as an input to the encoder and
after decoding we get a denoised image. It's easier to run and
interpret. Anyone with basic knowledge of neural networks
can understand and improvise the code.

7
3. METHODOLOGY:-
3.1 DATASET USED IN THE PROJECT:-
https://www.kaggle.com/tongpython/cat-and-dog (only the cat dataset have
been used)

3.2 SAMPLE DATASET:-

3.3 BLOCK DIAGRAM:-

8
3.4 EXPLANATION:-

The dataset employed in this study consists of 5013 coloured cat


photographs, with 4001 photos serving as the training dataset
and 1012 serving as the test dataset. With a batch size of 32, the
code runs for 100 epochs. The Gaussian noise distribution
across the signal is evenly distributed. It means that each pixel in
the noisy image is equal to the sum of the true pixel cost and a
Gaussian distributed noise cost. As the name implies, the Bell
shape probability distribution function is utilised in Gaussian
noise, where z corresponds to the grey level, specifies the
function's mean or average, and indicates the noise's standard
deviation. The probability density function of a Gaussian
random variables is given by:

Because of the large number of images in the dataset, we employ


the CCN (convolutional neural networks) model for encoders and
decoders. For better training, we use 100 epochs in our model and
utilise Matplot lib to visualise our results. The image dimension of
each 2D layer in the convolution neural network is 128x128. The
parameters for the relu activation function are set to their default
settings with the same padding. With a batch size of 32, the
network is trained using the relu activation function. The optimizer
chosen is Adam.Adam combines the best properties of the
AdaGrad and RMSProp algorithms to provide an optimization
algorithm that can handle sparse gradients on noisy
problems.Rather than introducing noise to a single image, we

9
apply it to the entire dataset, causing each row to represent an
image to be corrupted. As shown in the picture below, a simple
convolutional denoising autoencoder architecture was employed
for modelling on a corrupted dataset.

4. IMPLEMENTATION:-

For this project we have used the Kaggle Notebook.It is a cloud


computational environment that enables reproducible and
collaborative analysis.

4.1 FLOWCHART:

10
4.2 ALGORITHM:

Step1: All the required libraries are imported.The data set is read.

Step2: Data visualisation is done

Step3: A function is created to add noise to the training dataset and


the testing data set. After passing them through the function the
first 10 images from the noisy dataset are printed for the training
and test datasets respectively.

Step4: The neural network is created and the noisy images are the
inputs to the encoder.The autoencoder isn’t fed the original images
at any point in time and we are expecting the autoencoder to give
us output without any noise.
Step5: Fitting of the model

Step6: The reconstructed images are printed and the required


graphs are plotted.

4.3 Code:-

import numpy as np
import pandas as pd
import os
import tensorflow as tf
import matplotlib.pyplot as plt
from keras.layers import Input, Dense, Conv2D, MaxPooling2D,
UpSampling2D, Conv2DTranspose
from keras.models import Model
from keras.preprocessing import image

cat_train_path = "../input/cat-and-dog/training_set/training_set/cats/"
cat_test_path = "../input/cat-and-dog/test_set/test_set/cats/"
cat_train = []
for filename in os.listdir(cat_train_path):
if filename.endswith(".jpg"):

11
img = image.load_img(cat_train_path+filename, target_size=(128, 128))
cat_train.append(image.img_to_array(img))
cat_train = np.array(cat_train)

cat_test = []
for filename in os.listdir(cat_test_path):
if filename.endswith(".jpg"):
img = image.load_img(cat_test_path+filename, target_size=(128, 128))
cat_test.append(image.img_to_array(img))
cat_test = np.array(cat_test)

print("cat_train", cat_train.shape)
print("cat_test", cat_test.shape)

def show_cat_data(X, n=10, title=""):


plt.figure(figsize=(15, 5))
for i in range(n):
ax = plt.subplot(2,n,i+1)
plt.imshow(image.array_to_img(X[i]))
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.suptitle(title, fontsize = 20)

def noisy(image):
row,col,ch= image.shape
mean = 50
var = 1024
sigma = var**0.5
gauss = np.random.normal(mean,sigma,(row,col,ch))
gauss = gauss.reshape(row,col,ch)
noisy = image + gauss
return noisy

cat_train_noisy = []
for img in cat_train:
noisy_img = noisy(img)
cat_train_noisy.append(noisy_img)
cat_train_noisy = np.array(cat_train_noisy)
print(cat_train_noisy.shape)

cat_test_noisy = []
for img in cat_test:
noisy_img = noisy(img)
cat_test_noisy.append(noisy_img)
cat_test_noisy = np.array(cat_test_noisy)

12
print(cat_test_noisy.shape)

show_cat_data(cat_train, title="train cats")


show_cat_data(cat_train_noisy, title="train cats noisy")

show_cat_data(cat_test, title="test cats")


show_cat_data(cat_test_noisy, title="test cats noisy")

show_cat_data(cat_train, title="train cats")


show_cat_data(cat_test, title="test cats")

input_layer = Input(shape=(128, 128, 3), name="INPUT")


x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_layer)
x = MaxPooling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)

code_layer = MaxPooling2D((2, 2), name="CODE")(x)

x = Conv2DTranspose(8, (3, 3), activation='relu',


padding='same')(code_layer)
x = UpSampling2D((2, 2))(x)
x = Conv2DTranspose(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2DTranspose(16, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2,2))(x)
output_layer = Conv2D(3, (3, 3), padding='same', name="OUTPUT")(x)

cat_AE = Model(input_layer, output_layer)


cat_AE.compile(optimizer='adam', loss='mse',metrics="accuracy")
cat_AE.summary()

history=cat_AE.fit(cat_train, cat_train,
epochs=100,
batch_size=32,
shuffle=True,
validation_data=(cat_test, cat_test))

cat_AE.save("cat_AE.h5")

get_encoded_cat = Model(inputs=cat_AE.input,
outputs=cat_AE.get_layer("CODE").output)
encoded_cat = get_encoded_cat.predict(cat_test)
encoded_cat = encoded_cat.reshape((len(cat_test), 16*16*8))

13
encoded_cat.shape

reconstructed_cats = cat_AE.predict(cat_test_noisy)

print("Test Accuracy:
{:.2f}%".format(cat_AE.evaluate(np.array(cat_test_noisy),np.array(cat_test))[1
]*100))

show_cat_data(cat_test_noisy, title="original cats noisy")


show_cat_data(reconstructed_cats, title="reconstructed cats")

plt.plot(history.history["loss"], label="Training Loss")


plt.plot(history.history["val_loss"], label="Validation Loss")
plt.legend()

plt.plot(history.history["accuracy"], label="Training Accuracy")


plt.plot(history.history["val_accuracy"], label="Validation Accuracy")
plt.legend()

5. RESULTS :-

5.1 FINAL RESULTS:

14
5.2 GRAPHS

Training Loss Vs Validation Loss Graph:

● Our training dataset comprises 4001 images and our test dataset
comprises 1012 dataset. We see our validation loss graph almost
overlaps the training loss graphs, hence we can conclude that the
loss while training the model is almost equal to the loss while
testing the model.

Training Accuracy Vs Validation Accuracy Graph:

15
● After training the model we get an accuracy of 79.57% and after
testing the model we get an accuracy of 77% approx. This justifies
the jittery validation accuracy graph and we can interpret that the
learning rate is high here.

5.3 SUMMARY

16
6. CONCLUSION:-

On a coloured dataset of 5013 images with dimensions of


128x128 pixels, this paper sought to create a Denoise
Autoencoder. With a batch size of 32, it is run for 100 epochs.
Gaussian noise is used to distort all of the photos in the dataset in
order to conduct the experiment. The autoencoder algorithm was
used to remove Gaussian noise from the data. After using the
autoencoder algorithm, we get a denoised image with an
estimated accuracy of 76.77 percent, which could be attributable
to pre-existing factors like image quality, picture size, and
segmentation.

7. REFERENCES:-

[1] X. Jiang, Y. Zhang, W. Zhang, and X. Xiao. "A novel sparse


auto-encoder for deep unsupervised learning." In Advanced
Computational Intelligence (ICACI), 2013 Sixth
International Conference on, pp. 256-261. IEEE, 2013.

[2] C. Xing, L. Ma, and X. Yang. "Stacked denoise autoencoder


based feature extraction and classification for hyperspectral
images." Journal of Sensors, Vol. 2016, pp. 1-10, 2016.

[3] L. Gondara. "Medical image denoising using convolutional


denoising autoencoders." In, 2016 IEEE 16th International
Conference on Data Mining Workshops (ICDMW),12-15 Dec.
2016, Barcelona, Spain, IEEE: pp. 241-246.

[4] V. Jain, and S. Seung. "Natural image denoising with


convolutional networks." In Advances in Neural Information
Processing Systems, pp. 769-776. 2009.

[5] J. Xie, L. Xu, and E. Chen. "Image denoising and inpainting

17
with deep neural networks." In Advances in neural
information processing systems, pp. 341-349. 2012.

[6] F. Agostinelli, M.R. Anderson, and H. Lee. "Adaptive multi-


column deep neural networks with application to robust image
denoising." In Advances in Neural Information Processing
Systems, pp. 1493-1501. 2013.

[7] P. Vincent, H. Larochelle, Y. Bengio, and P. A. Manzagol.


"Extracting and composing robust features with denoising
autoencoders." In Proceedings of the 25th international
conference on Machine learning, pp. 1096-1103. ACM, 2008.

[8] P. Vincent, H. Larochelle, I. Lajoie, Y. Bengio, and P. A.


Manzagol. "Stacked denoising autoencoders: Learning useful
representations in a deep network with a local denoising
criterion." Journal of machine learning research 11, no. Dec
(2010): 3371-3408.

[9] https://www.cs.toronto.edu/~kriz/cifar.html

[10] https://blog.keras.io/building-autoencoders-in-keras.html

Plagiarism Check:

18

You might also like