MATLAB CODES - Gaussian Filter , Average Filter , Median Filter ,High Pass Filter , Sharpening Filter , Unsharp Mask Filter

clc;
close all;
clear all;

% Read the test image and display it
myimage = imread('grayleaf.jpg');
subplot(3,3,1);
imshow(myimage); title('Original Image');

% The command fspecial() is used to create mask
% The command imfilter() is used to apply the gaussian filter mask to the image
% Create a Gaussian low pass filter of size 3

gaussmask = fspecial('gaussian',3);
filtimg = imfilter(myimage,gaussmask);
subplot(3,3,2);
imshow(filtimg,[]),title('Output of Gaussian filter 3 X 3');

% Generate a lowpass filter of size 7 X 7
% The command conv2 is used the apply the filter
% This is another way of using the filter

avgfilt = [ 1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1;
            1 1 1 1 1 1 1];

avgfiltmask = avgfilt/sum(avgfilt);
convimage= conv2(double(myimage),double(avgfiltmask));

subplot(3,3,3);
imshow(convimage,[]);
title('Average filter with conv2()');


% Add noise to an image
% Display the noisy Image

subplot(3,3,4);
myimage = imread('grayleaf.jpg');
noisyimg = imnoise(myimage,'Salt & Pepper', 0.5);
imshow(noisyimg,[]);
title('Noisy Image');

% generate Median filter of size 3
% The command medianfilt2() is used to filter the image

mymed3img = medfilt2(noisyimg,[3 3]);
subplot(3,3,5);
imshow(mymed3img,[]), title('Output of 3 x 3 Median filter');

% generate Median filter of size 7
% The command medianfilt2() is used to filter the image

mymed7img = medfilt2(noisyimg,[7 7]);
subplot(3,3,6);
imshow(mymed7img,[]), title('Output of 7 x 7 Median filter');


% Generate a high pass filter mask
% The command conv2 is used the apply the filter mask

h = [ 1 -2 -1; -1 5 -1; 1 -2 1];
hpt3 = conv2(double(myimage),double(h)); 
subplot(3,3,7);
imshow(hpt3/100),title('Output of High pass filter');


% Generate a User defined mask for sharpening
% The command conv2 is used the apply the filter mask

h = [ -1 -1 -1; -1 9 -1; -1 -1 -1];
hpt3 = conv2(double(myimage),double(h)); 
subplot(3,3,8);
imshow(hpt3/100),title('Sharpening - User defined mask');

% Generate a unsharp filter mask with alpha = 0.3
% The command conv2 is used the apply the filter mask

h = fspecial('unsharp',0.3);
hpt3 = imfilter(myimage,h); 
subplot(3,3,9);
imshow(hpt3,[]),title('Output of Unsharp mask filter');

MATLAB CODES - Gaussian Filter , Average Filter , Median Filter ,High Pass Filter , Sharpening Filter , Unsharp Mask Filter MATLAB CODES - Gaussian Filter , Average Filter , Median Filter ,High Pass Filter , Sharpening Filter , Unsharp Mask Filter Reviewed by Suresh Bojja on 9/11/2018 03:24:00 AM Rating: 5

Subjects & Labs

AC (6) ADS (2) ATMEL (6) AWP (5) C- Language (3) CAO (5) CDAC (1) Cloud Computing (1) CMC (6) CN (10) CONSERVATION & MANAGEMENT Complete Notes (1) Control Sys (2) CVSM (2) Data Analytics (1) DC (5) Digital System Design (3) DIP (17) DLD (10) DLD Lab Manual (1) DS (4) DSD&DICA (9) DSP (6) EDC (45) Electonic Components (2) Embedded (7) EMWTL (6) ENERGY AUDIT (1) Engg. Mechanics (2) Engg.Chemistry (11) Faculty Files (6) Faculty Labs (1) Fuzzy (3) II MID (1) Job Exam Papers (4) LICA (1) Linux OS (1) Materials (1) MATLAB (27) MCU IDE 8051 (1) MEMS (4) MPMC (57) MPMC LAB Manual (3) MTECH (6) MWE (2) OC (1) PDC (9) Projects (8) RADAR (1) Research (9) RVSP (3) SC (1) Softwares (1) SS (1) STLD (18) TCSS (1) TSSN (1) TV Engg (1) VHDL (4) VLSI (8) VLSI Lab manual (1) WCN (1) Wireless Commu. (1) WSN (2)

Contact Form :

Name

Email *

Message *

Theme images by enjoynz. Powered by Blogger.