Saturday, 24 March 2012

Lab 3.2 - Spatial Filtering

Hye there.. it's Aan again...do u still remember previous post by my course-mate, Balqis about INTENSITY TRANSFORMATION ?? feel free to click here if u missed it..since it has slight relation with this post topic, i recommend u to go through the intensity transformation first.

Now, I would like to share about Spatial Filtering..

Spatial Filtering can be used to smooth, blur, sharpen, or find the edges of an image. It is also known as neighbourhood processing.

Lets try on how to do average filter that apply at location 2,2
This 2,2 location is referred to the pixel of the image


the original image of stock_cut



stock_cut after being filtered



The following table, modified from page 94 of Digital Image Processing, Using MATLAB by Rafael C. Gonzalez, Richard E. Woods, and Steven L.Eddins, summarizes the additional options available with imfilter function.





The imfilter function which applied on stock_cut image above have inherent problem when working with corners and edges. the problem is that some of the "neigbours" are missing. 
the solutions for this problem are : ZERO-PADDING and REPLICATING

Lets try these 'zero-padding' and 'replicating' on cat image.
Note that the filter used below is a 5x5 averaging filter which can be carry out using this syntax:




Next, read the image to be filtered by using this command.



original image of 'cat.jpg'


Below are the command function to do zero-padding, replicate, symmetric, and circular to an image



The results of filtering are shown as below:



The disadvantage of zero-padding is that it leaves dark artifacts around the edges of the filtered image (with white background). You can see this as a dark border along the bottom and right-hand edge in the zero-padded image above.


Ok, lets move to next sub-topic : Filtering Mode (Correlation vs Convolution)

Convolution rotates the filter by 180 degrees before performing multiplication. Diagram below demonstrates the two operations for position 3,3 of the image:




The following are example codes to demonstrate Correlation and Convolution on 'cat.jpg' image:







Next, we will go through on Size Options in imfilter process.
The two size options are 'FULL' and 'SAME'. The 'full' will be as large as the padded image, whereas the 'same' will be the same size as the input image.

Below are MATLAB syntax  on how to create a 'full' and 'same' image:





Last but not least, we can also create SPECIAL FILTERS by using a fspecial function which requires an argument that specifies the kind of desired filter.

The following examples will show you three filters created by fspecial and the results of 'cat.jpg' image:



Alright...that's all for Spatial Filtering lesson. Hope this will help.. Feel free to give any comment below :)
Keep following our update.. Thanks for reading... Bye 
Smiley






No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...