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






Wednesday 21 March 2012

LAB 3: INTENSITY TRANSFORMATION (MATLAB)

assalamualaikum to our fellow lecturer and friends. have you ever heard about intensity transformation and spatial filtering? this week, we have learned something new about matlab which are intensity transformation and spatial filtering. there are four main function of intensity transformation:

  • photographic negative (using imcomplement)
  • gamma transformation (using imadjust)
  • logaritmic transformation (using c*log(1+f))
  • contrast-stretching transformations (using 1./(1+(m./(double(f)+eps)).^E)

photographic negative (using imcomplement) 
then what is photographic negative? ok, in the easiest words, it means that the true black becomes true white and vise versa. matlab has a function to create this photographic negative by imcomplement (f). lets see our coding example that we have done during lab session :)

>>   I=imread('cat.JPG')
>>  J=imcomplement(I);
>>  imshow(I)
>>  figure, imshow(J)

original image
after photographic negative










































gamma tranformation (using imadjust)
next is about gamma transformations. what is gamma transformation? with gamma transformation, we can curve the grayscale components either to brighten the intensity or to darken the instensity. when the component grayscale darken, it means the gamma is less than one and vice versa. lets see the coding example of gamma transformation :)

>>   I = imread('tire.tif');
>>   J=imadjust(I,[],[],1);
>>   J2=imadjust(I,[],[],3);
>>   J3=imadjust(I,[],[],0.4);
>>   imshow(J);
>>   figure, imshow (J2);
>>   figure, imshow (J3);


J

J2

J3


logaritmic transformations (using c*log(1+f))
usually, logarithmic transformation used to brighten the intensities of an image of lower intensity values. its function in matlab can be shown as,    g = c*log(1+double(f)) . here, we paste some matlab code example  for logaritmic transformation :)

>>   I = imread('tire.tif');
>>   I2=im2double(I);
>>   J=1*log(1+I2);
>>   J2=2*log(1+I2); 
>>   J3=5*log(1+I2); 
>>   imshow(I) 
>>   figure, imshow(J)
>>   figure, imshow(J2)
>>   figure, imshow(J3)

original image







J

J2

J3


contrast-stretching transformations (using 1./(1+(m./(double(f)+eps)).^E) 
this is the last part of intensity transformation for our lab. what is contrast-stretching transformation? urm, contrast-stretching transformation results in increasing the contrast between the darks and the lights. this will end up the dark being darker and the lights being lighter, with only few levels of gray in between. lets see our coding example and screenshot in plot form to enable readers to make contrast comparison easily :)

a)  light to lighter

>> I = imread('tire.tif');
>> I2=im2double(I);

>> m=mean2(I2)
>> contrast1=1./(1+(m./(I2+eps)).^4);
>> contrast2=1./(1+(m./(I2+eps)).^5);
>> contrast3=1./(1+(m./(I2+eps)).^10);
>> figure(1), subplot(2,2,1),imshow(I2),xlabel('I2')
>> figure(1), subplot(2,2,2),imshow(contrast1),xlabel('contrast 1')
>> figure(1), subplot(2,2,3),imshow(contrast2),xlabel('contrast 2')
>> figure(1), subplot(2,2,4),imshow(contrast3),xlabel('contrast 3')

(a) contrast-stretching transformation. bright to brighter. 



a)  dark to darker

>> I = imread ('tire.tif');
>> I2=im2double(I);
>> contrast1 = 1./(1+(0.2./(I2+eps)).^4);
>> contrast2 = 1./(1+(0.5./(I2+eps)).^4);
>> contrast3 = 1./(1+(0.7./(I2+eps)).^4);
>>figure(1), subplot(2,2,1), imshow(I2), xlabel('I2')
>>figure(1), subplot(2,2,2), imshow(contrast1), xlabel('contrast1')
>>figure(1), subplot(2,2,3), imshow(contrast2), xlabel('contrast2')
>>figure(1), subplot(2,2,4), imshow(contrast3), xlabel('contrast3')

(b) contrast-stretching transformation. dark to darker. 





we hope our post on this time will help you to understand a little bit about intensity transformation. in the next post, we will update about the spatial filtering in matlab. thanks you :)

Tuesday 13 March 2012

IMAGE ACQUISITION AND BASIC OPERATION(MATLAB)

IMAGE PROCESSING TOOLBOX


In this lab, we have performed some basic image processing exercise by matlab. The main purpose of this lab is to :
1.       Read and display image
2.       Check how the image appears in the workspace
3.       Perform histogram equalization on the image
4.       Write the image to a disk file
5.       Get information about graphic file



Below is the commands and example output:

>>I = imread (‘pout2.png’)     % Output the array

>>Imshow(I)                          % To display image

Original   'pout2.png'



>>whos    % To see how I is stored in memory
Input and output of 'whos' command



>>figure, imhist(I)    % To display histogram of I in the new figure

Histogram equilization




>>I2 = histeq(I)      %Equalize I and output in new array

>>figure, imshow(I2)    %Display the new equalized image I2.




Equilized   'pout2.png'



>>imwrite(I2, 'pout2.png')      % To write the newly adjusted image I2 back to disk.

>>imfinfo(‘pout2.png’)     % To check the content of newly written file

Check info







Next, we also learn on how to edit image
This command shows original image

>> x = imread ('obama.png');
>> figure,  imshow (x)

The original image


This command functions to convert original image to be gray scaled:
>> x_g = rgb2gray(x);
>> figure, imshow (x_g)


The image has been converted to gray scale


This command allow cropping image:-
>> imshow (x_g' imcrop);



This command function will flip the image:

>> figure(1); image(x)
x(:, :, 1) = fliplr (x(:, :, 1));
x(:, :, 2) = fliplr (x(:, :, 2)); 
x(:, :, 3) = fliplr (x(:, :, 3)); 
figure(2); image(x)


The flipped image


Commands function below will show how an image being flipped vertically and horizontally

>> xMirror = flipdim(x,2);             % horizontal flip
>>  xUpsideDown = flipdim(x,1);  % vertical flip
>> xHorizontalAndVerticalFlip = flipdim (xUpsideDown, 2);  % horizontal and vertical flip

>> subplot(2,2,1), imshow(x)
>> subplot(2,2,2), imshow(xMirror)
>> subplot(2,2,3), imshow(xUpsideDown)
>> subplot(2,2,4), imshow(xHorizontalAndVerticalFlip)

Flipped image in both vertical and horizontal









Image info by using command function >> iminfo(x)



Monday 5 March 2012

LAB MODULE 2.

There are three (3) basic objects in matlab which are scalar, vector and matrices. Below is an example for each object:

Scalar
a = 5
there is only a value presents in scalar object.

Vector
v = [1 5 6]
vector usually displayed in matrices form


In MATLAB, there are some  commands to allow matrice operation to be formulated.

Some of the commands are:

1) When create a matrice




2) To determine the coordinate of matrice





3) Below are the examples to calculate the value of summation, mean, maximum, and minimum values of a matrix MatrixBITI









4) Below are examples to write the location of the pixel 4 and 10 in the matrix Exe











Related Posts Plugin for WordPress, Blogger...