Digital Signal Processing Reference
In-Depth Information
Program 14.2. Examples of Gaussian filtering, media filtering, and Laplacian of Gaussian filtering.
close all;clear all; clc;
X ¼ imread( ' cruise ' , ' jpeg ' );
% Provided by the instructor
Y ¼ rgb2gray(X);
% Convert the RGB image to the grayscale image
I ¼ im2double(Y);
% Get the intensity image
image1_g ¼ imnoise(I, ' gaussian ' );
% Add random noise to the intensity image
ng ¼ mat2gray(image1_g);
% Adjust the range
ng ¼ im2uint8(ng);
% 8-bit corrupted image
% Linear filtering
K_size ¼ 5; % Kernel size ¼ 5 5
sigma ¼ 0.8; % sigma (the bigger, the smoother the image)
h ¼ fspecial( ' gaussian ' ,K_size,sigma); % Determine Gaussian filter coefficients
% This command will construct a Gaussian filter
% of size 5 5 with a main lobe width of 0.8.
image1_out ¼ filter2(h,image1_g); % Perform filtering
image1_out ¼ mat2gray(image1_out); % Adjust the range
image1_out ¼ im2uint8(image1_out); % Get the 8-bit image
subplot(1,2,1); imshow(ng),title( ' Noisy image ' );
subplot(1,2,2); imshow(image1_out);
title( ' 5 5 Gaussian kernel ' );
% Median filtering
image1_s
¼
imnoise(I,
salt & pepper
);
% Add
salt and pepper
noise to the image
'
'
mn
¼
mat2gray(image1_s);
% Adjust the range
mn
¼
im2uint8(mn);
% Get the 8-bit image
K_size
3; % Kernel size
image1_m ¼ medfilt2(image1_s,[K_size, K_size]); % Perform median filtering
image1_m ¼ mat2gray(image1_m);
¼
% Adjust the range
image1_m ¼ im2uint8(image1_m);
% Get the 8-bit image
figure, subplot(1,2,1);imshow(mn)
title( ' Median noisy ' );
subplot(1,2,2);imshow(image1_m);
title( ' 3 3 median kernel ' );
% Laplacian of Gaussian filtering
K_size ¼ 5;
% Kernel size
sigma ¼ 0.9;
% Sigma parameter
h ¼ fspecial( ' log ' ,K_size,alpha);
% Determine the Laplacian of Gaussian %filter
kernel
image1_out ¼ filter2(h,I);
% Perform filtering
image1_out ¼ mat2gray(image1_out);
% Adjust the range
image1_out ¼ im2uint8(image1_out);
% Get the 8-bit image
figure,subplot(1,2,1); imshow(Y)
title( ' Original ' );
subplot(1,2,2); imshow(image1_out);
title(
Laplacian
lter 5
5 kernel
);
'
'
Search WWH ::




Custom Search