You are on page 1of 8

Q 1: Obtain the two Images (Image1 and Image 2).

Part a. Read and display images

Ans : To read the image there are two ways used in Matlab

1. A=imread(‘image1.Jpg’)
2. B=imwite(‘image2.Jpg’)

To display the image following functions are used

1. Imshow(P)
2. imshow(P,[low high])
3. imshow(P,[])

4. imshow(RGB)

For example

A=imread(‘image1.Jpg’)

Imshow(A)

Part b:

Step 1: Read image 1 and 2

Code:

image1= imread(‘Matlabimages/image1.jpg’)

image2= imread(‘Matlabimages/image2.jpg’)

Step 2: Scaling J image as size of image1 and 2

Code:
[X1, Y1]=meshgrid( linspace(0, 1, size(image1,2)), linspace(0, 1, size(image1,1)));

[X2, Y2]=meshgrid( linspace(0, 1, size(image2,2)), linspace(0, 1, size(image2,1)));

nchannels = size(I1,3);

Step 3: Split image in left column and right column

Code:

n1= image (; ,1; end/2)

n2 = image (; , end/2+1 :end);

Step 4: Making the left half of image J as of the left column of image1.

Code:

[X1, Y1]=meshgrid( linspace(0, 1, size(image1,2)), linspace(0, 1, size(image1,1)));

D = imresize(n1, [rowsA colsA])

Step 5: Making the right half of image J as of the right column of image2.

Code:

[X1, Y1]=meshgrid( linspace(0, 1, size(image1,2)), linspace(0, 1, size(image1,1)));

D = imresize(n1, [rowsA colsA])

Part c:

Swap the left and right halves of image J.

Code:
subplot(2,2,1)
imshow(I)
Ir = flipdim(I,2);
subplot(2,2,2)
imshow(Ir)
title 'image in original form'
title ' image in flipped form'
IIr = horzcat(I,Ir);
subplot(2,2,3:4)
imshow(IIr)
title 'joined images'

______________________________________________________________________________

Q2: Discuss the types of image noises and write a matlab code to add noise and then de-
noise the image.

Image:

Before going into Image processing let’s talk about image itself. Many of us think of an image as
a picture that we see in a wall or magazine etc.

Types of digital images:

There are typically three types of digital images.

 Binary Images

 Gray Scale Images

 Color Images

Noise in images:

Image noise is random variation of brightness or color information in the images captured. It is
degradation in image signal caused by external sources. Images containing multiplicative noise
have the characteristic that the brighter the area the noisier it. But mostly it is additive. We can
model a noisy image as
A(x,y) = H(x,y) + B(x,y) Where, A(x,y)= function of noisy image, H(x,y)= function of image
noise , B(x,y)= function of original image.

Sources of Image noise:

 While image being sent electronically from one place to another.

 Sensor heat while clicking an image.

 With varying ISO Factor which varies with the capacity of camera to absorb light.

Types of Image noise:

There are different types of image noise. They can typically be divided into 3 types.

1. Gaussian Noise:

Gaussian Noise is a statistical noise having a probability density function equal to normal
distribution, also known as Gaussian Distribution. Random Gaussian function is added to
Image function to generate this noise. It is also called as electronic noise because it arises in
amplifiers or detectors. Source: thermal vibration of atoms and discrete nature of radiation of
warm objects.

2. Impulse Noise:

Impulse Function: In the discrete world impulse function on a value of 1 at a single location
and In continuous world impulse function is an idealized function having unit area.
2.1 Types of Impulse Noise:

There are three types of impulse noises. Salt Noise, Pepper Noise, Salt and Pepper Noise.

Salt Noise: Salt noise is added to an image by addition of random bright (with 255 pixel value) all
over the image.

Pepper Noise: Salt noise is added to an image by addition of random dark (with 0 pixel value) all
over the image.

Salt and Pepper Noise: Salt and Pepper noise is added to an image by addition of both random
bright (with 255 pixel value) and random dark (with 0 pixel value) all over the image. This model
is also known as data drop noise because statistically it drop the original data values.

3. Poisson Noise:

The appearance of this noise is seen due to the statistical nature of electromagnetic waves such as
x-rays, visible lights and gamma rays. The x-ray and gamma ray sources emitted number of
photons per unit time. These rays are injected in patient’s body from its source, in medical x rays
and gamma rays imaging systems. These sources are having random fluctuation of photons.
Result gathered image has spatial and temporal randomness. This noise is also called as quantum
(photon) noise or shot noise.

4. Speckle Noise

A fundamental problem in optical and digital holography is the presence of speckle noise in the
image reconstruction process. Speckle is a granular noise that inherently exists in an image and
degrades its quality. Speckle noise can be generated by multiplying random pixel values with
different pixels of an image.
Part b:

Matlab Code for Adding Noise to an Image

Step 1: Read a gray scale image and display it.

P = imread('eight.tif');
imshow(P)

Step 2: Add salt and pepper noise, with a noise density of 0.02, to the image. Display the result.

Q = imnoise(P,'salt & pepper',0.02);


imshow(Q)

Step3: De-noise the image Q

Kaverage = filter2(fspecial('average',3),Q)/255;
figure
imshow(Kaverage)

Now use a median filter to filter the noisy image, Q. The example also uses a 3-by-3
neighborhood. Display the two filtered images side-by-side for comparison. Notice
that medfilt2 does a better job of removing noise, with less blurring of edges of the coins.

Kmedian = medfilt2(Q);
imshowpair(Kaverage,Kmedian,'montage')

You might also like