100% found this document useful (4 votes)
2K views

Filters in Matlab (Filter Codes)

This document discusses different filters that can be applied to images in MATLAB, including the Laplacian filter, high boost filter with Laplacian, gradient filter, Robert filter, Sobel filter, and custom masks. It provides code examples for applying each filter to an image called 'img' and plotting the results.

Uploaded by

Zarnigar Altaf
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
2K views

Filters in Matlab (Filter Codes)

This document discusses different filters that can be applied to images in MATLAB, including the Laplacian filter, high boost filter with Laplacian, gradient filter, Robert filter, Sobel filter, and custom masks. It provides code examples for applying each filter to an image called 'img' and plotting the results.

Uploaded by

Zarnigar Altaf
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT

FILTERS IN MATLAB

Submitted to:
Miss Bushra Sikander

Submitted by:
Nousheen hashmi

Date:
6/7/2012

Department:
BS(CS)-VIII

Laplacian Filter:
lap_mask=[0 -1 0;-1 4 -1;0 -1 0]; H1 = fspecial('laplacian'); L_img=imfilter(img,H1); figure; imshow(L_img); title('Edge Detected(Laplacian) Image');

High Boost with Laplacian Filter:


[r c]=size(img); A=1.5; for j=1:r for i=1:c pixel_value=img(j,i); if (pixel_value<0) h8_lap_mask=[0 -1 0;-1 A+4 -1;0 -1 0]; B=imfilter(img,h8_lap_mask); end if (pixel_value>=0) h8_lap_mask2=[-1 -1 -1;-1 A+8 -1;-1 -1 -1]; B=imfilter(img,h8_lap_mask2); end end end figure; imshow(B);

title('High Boost With Laplacian Image');

Gradient Filter:
%Horizontal G_H_mask=[-1 1]; G_H_img=imfilter(img,G_H_mask); %Vertical G_V_mask=[-1;1]; G_V_img=imfilter(img,G_V_mask); figure; title('Gradient image'); subplot(1,2,1);imshow(G_H_img); title('Gradient Horizontal image'); subplot(1,2,2);imshow(G_V_img); title('Gradient Vertical Image');

Robert Filter:
R_H_mask=[-1 0;0 1]; R_H_img=edge(img,'roberts'); figure; imshow(R_H_img); title('Robert Filtered Image');

Sobel Filter:
S_H_mask=[-1 -2 -1;0 0 0;1 2 1]; S_H_img=edge(img,'sobel'); figure; imshow(S_H_img); title('Sobel Filtered Image');

My Masks Filter:
%Mask1 mask1=[-1 -2 -1;-2 12 -2;-1 -2 -1]; mask1_img=imfilter(img,mask1); %Mask2 mask2=[-1 -2 -1;-2 -12 -2;-1 -2 -1]; mask2_img=imfilter(img,mask2); figure; subplot(1,2,1);imshow(mask1_img); title('Mask1 Filtered Image'); subplot(1,2,2);imshow(mask2_img); title('Mask2 Filtered Image')

You might also like