Matlab Color Image Processing Lab

Description

1) Take an RGB image (Lab9_3.jpg). and do the following:1. Insert Gaussian noise on its red component and Salt & pepper noise on its green and blue components.2. Concatenating the three components into an image (noisy image).3. Apply Average Filtering on noisy image from part2.4. Concatenating the three components into an image (filtered image in separate).6. Show the results2) Repeat the first part by using your own image. Report all the challenges that faced you in the process of apply noise to an image and then filtering it back..Make sure to include brief :IntroductionObjectivesConclusion

4 attachmentsSlide 1 of 4attachment_1attachment_1attachment_2attachment_2attachment_3attachment_3attachment_4attachment_4

Unformatted Attachment Preview

Computer Vision and Image Processing
COMP4500
Module 4
Module 4 Lab Exercise
1.2 Color Image Processing
1.2.1 RGB Images
M *N*3 array of color pixels as a stack of three gray-scale images
Let fR, fG, fB represent three RGB component images. An RGB image is formed
from these images by using the cat(concatenate) operator to stack the image.
rgb_image= cat(3 , fR, fG, fB)
The following commands extract the three component image:
fR= rgb_image(: , : , 1);
fG= rgb_image(: , : , 2);
fB= rgb_image(: , : , 3);
1.2.2 Smoothing and Sharpening Filtering Techniques on Color images
Filtering an RGB color image ,fc, with a linear spatial filter consists of the following
steps:
1. Extract the three component images:
>>fR= fc( : , : , 1);
fG= fc( : , : , 2);
fB= fc( : , : , 3);
2. Filter each component images individually. Letting w represent a filter
generated using fspecial, we smooth the red component images as follows:
>> fR_filtered= imfilter(fR, w);
3. Reconstruct the filter RGB
images:
>>fc_filtered= cat(3 , fR_filtered, fG_filtered, fB_filtered);
1. Exercises
Exercise1: Median Filter and Adaptive Median Filter
COMP4500
FACULTY OF ENGINEERING – SOHAR
UNIVERSITY
Exercise1: RGB Images
%%ex1.m%%%
clc;
clear all; close all;
I=imread(‘Lab9_2.png’
); size(I);
%251x366x3
R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);
rgb_image= cat(3 , R, G, B);
subplot(121),imshow(I),title(‘original image’);
subplot(122),imshow(rgb_image),title(‘reconstructed image’);
Output:
[Type here]
COMP4500
FACULTY OF ENGINEERING – SOHAR
UNIVERSITY
Exercise2: Smoothing Filtering on Color images
%%ex2.m%%%
clc;
clear all; close all;
a=imread(‘Lab9_3.jpg’);
% Separating red,green and blue components of image
r=a(:,:,1); g=a(:,:,2);
b=a(:,:,3);
% Adding Gaussian noise on green component
g1=imnoise(g,’gaussian’);
% Adding Salt & pepper noise on red
component r1=imnoise(r,’salt & pepper’,0.2);
% Concatenating red,green and blue components to form a composite
image.
image=cat(3,r1,g1,b);
% Creating average filter w1=fspecial(‘average’,3);
% applying filter in in separate
% applying average filter
gg=imfilter(g1,w1);
% applying median filter rr=medfilt2(r1);
% Concatenating red,green and blue components to form a composite
image after filtering
image1=cat(3,rr,gg,b);
subplot(131),imshow(a),title(‘original image’);
subplot(132),imshow(image),title(‘noisy image’);
subplot(133),imshow(image1),title(‘filtered image in separate’);
[Type here]
COMP4500
FACULTY OF ENGINEERING – SOHAR
UNIVERSITY
Output:
Homework
1) Take an RGB image (Lab9_3.jpg). and do the following:
1. Insert Gaussian noise on its red component and Salt & pepper noise on its
green and blue components.
2. Concatenating the three components into an image (noisy image).
3. Apply Average Filtering on noisy image from part2.
4. Concatenating the three components into an image (filtered image in separate).
6. Show the results
2)
Repeat the first part by using your own image. Report all the challenges that faced
you in the process of apply noise to an image and then filtering it back.
[Type here]
Electrical &
Computer
Engineering
Program
Lab Exercise
Compu
ter
Vision
and
Image
Process
ing
COMP4500
3
Module 2 Lab Exercise
Introduction to MATLAB Digital Image Processing
1. Lab Objectives:


Computing of the Fourier Transform for an image and displaying the
spectral image.
Designing of filters in the frequency domain (lowpass and highpass filters)
and apply them to images.
2. Theory
2.1 Fourier Transform:
The Fourier transform is a representation of an image as a sum of complex
exponentials of varying magnitudes, frequencies, and phases. The Fourier
transform plays a critical role in a broad range of image processing applications,
including enhancement, analysis, restoration, and compression.
Working with the Fourier transform on a computer usually involves a form of
the transform known as the discrete Fourier transform (DFT). There are
two principal reasons for using this form:
1) The input and output of the DFT are both discrete, which makes
it convenient for computer manipulations.
2) There is a fast algorithm for computing the DFT known as the fast
Fourier transform (FFT).
The DFT is usually defined for a discrete function f(x,y) that is nonzero only
over the
finite region 0 ≤ x ≤ M-1 and 0 ≤ y ≤ N-1.
[Type here]
The general idea is that the image (f(x,y) of size M x N) will be represented in the
frequency domain (F(u,v)). The equation for the two-dimensional discrete Fourier
transform (DFT)
The concept behind the Fourier transform is that any waveform that can be
constructed using a sum of sine and cosine waves of different frequencies. The
exponential in the above formula can be expanded into sins and cosines with the
variables u and v determining these frequencies
The inverse of the above discrete Fourier transform is given by the following
equation:
Thus, if we have F(u,v), we can obtain the corresponding image (f(x,y)) using
the inverse discrete Fourier transform.
Things to note about the discrete Fourier transform are the following:

The value of the transform at the origin of the frequency domain, at
F(0,0), is called the DC component

F(0,0) is equal to MN times the average value of f(x,y) .

In MATLAB, F(0,0) is actually F(1,1) because array indices in MATLAB
start at 1 rather than 0.
[Type here]

The values of the Fourier transform are complex, meaning they have
real and imaginary parts. The imaginary parts are represented by i,
which is the square root of -1

We visually analyze a Fourier transform by computing a Fourier
spectrum (the magnitude of F(u,v)) and display it as an image. o
The Fourier spectrum is symmetric about the center.

The fast Fourier transform (FFT) is a fast algorithm for computing
the discrete Fourier transform.

MATLAB has three functions to compute the DFT:
1. fft – for one dimension (useful for audio)
2. fft2 – for two dimensions (useful for images)
3. fftn – for n dimensions

MATLAB has three functions that compute the inverse DFT:
1. ifft
2. ifft2
3. ifftn

The function fftshift is used to shift the zero-frequency component to center
of spectrum. Note that it is so important to apply a logarithmic
transformation function on the spectral image before displaying so as
spectral details are efficiently displayed.
How does the Discrete Fourier Transform relate to Spatial
Domain Filtering?
The following convolution theorem shows an interesting relationship between
the spatial domain and frequency domain:
And, conversely,
[Type here]
The symbol “*” indicates convolution of the two functions. The important thing to
extract out of this is that the multiplication of two Fourier transforms corresponds
to the convolution of the associated functions in the spatial domain.
Basic Steps in DFT Filtering
The following summarize the basic steps in DFT Filtering
1. Obtain the Fourier
transform: F=fft2(f);
2. Generate a filter function, H
3. Multiply the transform by the
filter: G=H.*F;
4. Compute the inverse DFT:
g=ifft2(G);
5. Obtain the real part of the inverse FFT of
g: g2=real(g);
2.2 Filters in the Frequency Domain
Based on the property that multiplying the FFT of two functions from the spatial
domain produces the convolution of those functions, you can use Fourier
transforms as a fast convolution on large images. As a note, on small images, it
is faster to work in the spatial domain.
[Type here]
However, you can also create filters directly in the frequency domain. There are
three commonly discussed filters in the frequency domain:
Lowpass filters, sometimes known as smoothing filters
Highpass filters, sometimes known as sharpening filters
Bandpass filters.
A Lowpass filter attenuates high frequencies and retains low frequencies
unchanged.
A Highpass filter blocks all frequencies smaller than D o and leaves the others
unchanged.
Bandpass filters are a combination of both lowpass and highpass filters. They
attenuate all frequencies smaller than a frequency Do and higher than a
frequency D1, while the frequencies between the two cut-offs remain in the
resulting output image.
Lowpass filters:
create a blurred (or smoothed) image attenuate the high frequencies and leave
the low frequencies of the Fourier transform relatively unchanged
Three main lowpass filters are discussed in Digital Image Processing Using
MATLAB:
1.
Ideal lowpass filter (ILPF): The simplest low pass filter that cutoff all high
frequency components of the Fourier transform that are at the distance greater
than distance D0 from the center.
[Type here]
Where D0 is a specified nonnegative quantity (cutoff frequency), and D(u,v) is
the distance from point (u,v) to the center of the frequency rectangle. The center
of frequency rectangle is (M/2,N/2)
The distance from any point (u,v) to the center D(u,v) of the Fourier transform is
given by:
M and N are sizes of the image.
2. Butterworth lowpass filter (BLPF): of order n, and with cutoff frequency at
a distance D0 from the center.
3. Gaussian lowpass filter (GLPF)
The GLPF did not achieve as much smoothing as the BLPF of order 2 for the
same value of cutoff frequency
The corresponding formulas and visual representations of these filters are shown
in the table below. In the formulae, D0 is a specified nonnegative number (cutoff
frequency). D(u,v) is the distance from point (u,v) to the center of the filter.
Butterworth low pass filter (BLPF) of order n.
[Type here]
[Type here]
Highpass filters:
sharpen (or shows the edges of) an image attenuate the low frequencies and
leave the high frequencies of the Fourier transform relatively unchanged
The highpass filter (Hhp) is often represented by its relationship to the lowpass
filter (Hlp):
Because highpass filters can be created in relationship to lowpass filters, the
following table shows the three corresponding highpass filters by their visual
representations:
1. Ideal highpass filter (IHPF)
2. Butterworth highpass filter (BHPF)
3. Gaussian highpass filter (GHPF)
[Type here]
In Matlab, to get lowpass filter we use this command:
H = fspecial(‘gaussian’,HSIZE,SIGMA)
– Returns a rotationally symmetric Gaussian lowpass filter of size HSIZE with
standard deviation SIGMA (positive).
– HSIZE can be a vector specifying the number of rows and columns in H or
scalar, in which case H is a square matrix.
[Type here]
– The default HSIZE is [3 3], the default SIGMA is 0.5.
In Matlab, to get highpass laplacian filter we use this command:
H = fspecial(‘laplacian’,ALPHA)
– Returns a 3-by-3 filter approximating the shape of the two-dimensional
Laplacian operator.
– The parameter ALPHA controls the shape of the Laplacian and must be in the
range 0.0 to 1.0.
– The default ALPHA is 0.2
3. Exercises
Exercise1: Apply FFT and IFFT.
%ex1.m close all clear
clc
%====================================
% 1) Displaying the Fourier Spectrum:
%====================================
I=imread(‘Lab8_1.jpg’); I=im2double(I);
FI=fft2(I); %(DFT) get the frequency for the image
FI_S=abs(fftshift(FI));%Shift zero-frequency component
to center of img_spectrum.
I1=ifft2(FI); I2=real(I1);
subplot(131),imshow(I),title(‘Original’),
subplot(132),imagesc(0.5*log(1+FI_S)),title(‘Fourier
Spectrum’),axis off
subplot(133),imshow(I2),title(‘Reconstructed’)
%imagesc: the data is scaled to use the full colormap.
[Type here]
Output:
Exercise2: Apply lowpass filter.
%ex2.m close all clear
clc
%=============================
% 2)
Low-Pass
Gaussian
Filter:
%=============================
I=imread(‘Lab8_1.jpg’); I=im2double(I);
FI=fft2(I);
%1.Obtain the Fourier transform
LP=fspecial(‘gaussian’,[11 11],1.3); %2.Generate a LowPass filter FLP=fft2(LP,size(I,1),size(I,2)); %3. Filter
padding LP_OUT=FLP.*FI; %4.Multiply the transform by the
filter I_OUT_LP=ifft2(LP_OUT); %5.inverse DFT
I_OUT_LP=real(I_OUT_LP); %6.Obtain the real part(Output)
%%%%spectrum%%%%
[Type here]
FLP_S=abs(fftshift(FLP));%Filter spectrum
LP_OUT_S=abs(fftshift(LP_OUT));%output spectrum
subplot(221),imshow(I),title(‘Original’),
subplot(222),imagesc(0.5*log(1+FLP_S)),title(‘LowPass Filter
Spectrum’),axis off
subplot(223),imshow(I_OUT_LP),title(‘LowPass Filtered
Output’)
subplot(224),imagesc(0.5*log(1+LP_OUT_S)),title(‘LowPass
Spectrum’), axis off
Output:
Exercise3: Apply Ideal lowpass filter.
%ex3.m close all clear
clc
a=imread(‘Lab8_2.tif’); [M N]=size(a); a=im2double(a);
F1=fft2(a);
[Type here]
%1.Obtain the Fourier transform
% Set up range of variables. u = 0:(M-1); %0255 v = 0:(N-1);%0-255
% center (u,v) = (M/2,N/2)
% Compute the indices for use in meshgrid
idx = find(u > M/2);% indices 130-255
u(idx) = u(idx) – M;
idy = find(v > N/2);
v(idy) = v(idy) – N;
%set up the meshgrid arrays needed for
% computing the required distances.
[U, V] = meshgrid(u, v);
% Compute the distances D(U, V).
disp(‘IDEAL LOW PASS FILTERING IN FREQUENCY
DOMAIN’); D0=input(‘Enter the cutoff distance==>’);
% Begin filter computations.
H = double(D 30
Homework
1) Write a Matlab code to apply highpass laplacian filter on Lab8_1.jpg image.
2) Write a Matlab code to apply ideal highpass filter on Lab8_1.jpg image for D0=100
3) Apply FFT2, IFFT2, lowpass Gaussian filter, and highpass laplacian filter
onLab8_3.jpg image.
[Type here]

Purchase answer to see full
attachment

Explanation & Answer:
1 Lab

1 Image

Tags:
Gaussian noise

RGB image

noisy image

User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.

Reviews, comments, and love from our customers and community:

Article Writing

Keep doing what you do, I am really impressed by the work done.

Alexender

Researcher

PowerPoint Presentation

I am speechless…WoW! Thank you so much!

Stacy V.

Part-time student

Dissertation & Thesis

This was a very well-written paper. Great work fast.

M.H.H. Tony

Student

Annotated Bibliography

I love working with this company. You always go above and beyond and exceed my expectations every time.

Francisca N.

Student

Book Report / Review

I received my order wayyyyyyy sooner than I expected. Couldn’t ask for more.

Mary J.

Student

Essay (Any Type)

On time, perfect paper

Prof. Kate (Ph.D)

Student

Case Study

Awesome! Great papers, and early!

Kaylin Green

Student

Proofreading & Editing

Thank you Dr. Rebecca for editing my essays! She completed my task literally in 3 hours. For sure will work with her again, she is great and follows all instructions

Rebecca L.

Researcher

Critical Thinking / Review

Extremely thorough summary, understanding and examples found for social science readings, with edits made as needed and on time. Transparent

Arnold W.

Customer

Coursework

Perfect!

Joshua W.

Student

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>