Wednesday, July 25, 2012

6th Activity: Enhancement in the Frequency Domain


The goal of this activity is to improve images using filters and Fourier transforms.

A. Convolution Theorem

Two dots with one pixel each was created along the x-axis, symmetrical about the center. The Fourier tranform of this was taken as shown in Figure 1. It can be seen that the obtained Fourier transform of the dots are lines along the y-axis.

 Figure 1(a) two dots along x-axis symmetric about center; (b) Its Fourier transform 

     Next, two circles with radius = 0.2 was made symmetric about the center along x-axis. The 3D plot of the circles and Fourier transforms are shown in Figure 2 (b) & (c). In Figure 2 (d) & (e), it can be seen that there is a bright spot surrounded by fringes. There are also vertical lines along y-axis. 


Figure 2. (a)  two circles along x-axis symmetric about center ; (b) its 3D plot; (c) Its Fourier transform in 3D;
(d) & (e) Its Fourier transform

     Figure 3 shows circles with varying radii and their corresponding Fourier transforms. It can be observed that as the radius of the circle increases, the bright spot in the Fourier transform decreases.

Figure 3. Fourier transform of circles along x-axis symmetric about center; (a) circle with r = 0.2; (b) circle with r = 0.5;       (c) circle with r = 0.8 

     This time, the circles were replaced with squares. The results are shown in Figure 4.
   

Figure 4. (a)  two sqaures along x-axis symmetric about center ; (b) its 3D plot; (c) Its Fourier transform in 3D;
(d) & (e) Its Fourier transform

      As the width of the square is increased, the Fourier transform shrinks.

Figure 5. Fourier transform of squares along x-axis symmetric about center; (a) square with side = 0.1; (b)  square with side = 0.25; (c)  square with side = 0.8

     An image containing two gaussian was created and is shown with its 3D plot in Figure 6 (a) & (b). Figure 6 (c) & (d) shows the Fourier transform of the generated image.
Figure 6. (a)  two gaussians along x-axis symmetric about center; (b) its mesh; (c) 3D plot of its Fourier transform; (d) Its Fourier transform

      As shown in Figure 7, as the value of σ is increased, the Fourier transform is reduced. 
Figure 7. Fourier transforms of gaussians with σ= 0.01, 0.1, and 0.9, respectively

     A 200x200 array of zeros was then generated with ten random locations of 1. A 5x5 pattern was also created. The Fourier transform of both arrays were taken and multiplied to each other. Then, the Inverse Fourier transform of it was obtained and shown in Figure 8. This process is called convolution.


Figure 8. Convolution of two arrays


     Another array was created with 1's at equally spaced locations in the x and y axis. It is shown at the left of Figure 9. Its Fourier transform is also shown beside it. It can be seen that its Fourier transform is composed of vertical and horizontal lines that are equally spaced. As the spacing between them is increased, the number of vertical and horizontal lines also increased accordingly. 




B. Lunar Scanned Pictures: Line removal




     An image shown in Figure 10 was provided to us. It was then converted into grayscale image. Then the Fourier transform of the image was obtained and shown at the right of Figure 10. The Fourier transform showed a bright spot at the center with a cross pattern.  
Figure 10. (left) Craters in the moon ; (right) Its Fourier transform


     It was shown in Figure 1 of Part A of this activity that the Fourier tranform of dots along the x-axis is composed of parallel lines along the y-axis. Since the image to be enhanced have lines along the x-axis, the filter that must be made must consist of series of dots along the y-axis. The created filter mask is shown in Figure 10.  




Figure 10. Filter for enhancing image of the moon


     Multiplying this filter to the Fourier transform of the original image, the original image was now enhanced as shown in Figure 11.  It can be seen in Figure 11 that the horizontal lines in the image was removed using the filter created. Thus the filter used was effective in enhancing the original image.

Figure 11. (left) Original image of the moon; (right) Enhanced image 

     C. Canvas Weave Modeling and Removal

     Same procedure were done to enhance the image shown in Figure 12.    

Figure 12. Detail of "Frederiksborg", oil on canvas by Dr. Vincent Daria

     It was then converted into grayscale image and its Fourier transform was obtained as seen in Figure 13.

Figure 13. Fourier transform of the image
     Using GIMP, a filter mask was created by drawing circles at locations corresponding to the bright spots in the frequency domain. There is a low signal to noise ratio at the black region so it was covered to remove the weave pattern.




Figure 14. Mask filter for the canvas

     Figure 15 shows the result after filtering the original image. It can be seen that the weave pattern was indeed removed.

Figure 15. Enhance image of the canvas

     In order to visualize the canvas weave pattern, the enhanced image was subtracted from the original image. Figure 16 shows the obtained weave pattern.


   




Self-evaluation:

I will give myself 10/10 for completing the job and presenting the results clearly.



Wednesday, July 11, 2012

5th Activity: Enhancement by Histogram Manipulation

     Some images taken have poor quality due to several factors such as lighting and camera settings. Due to such issues, many techniques have been developed to improve the quality of an image. 

     In this activity, histogram manipulation was utilized for enhancement of images. The original image is converted to grayscale. Its histogram is also the graylevel probability distribution function or grayscale PDF. It can be changed and can be manipulated to follow the response of various imaging systems. 

     




Figure 1. Image to be modified
      Figure 1 shows the original image. It was then converted to grayscale as shown in Figure 2. 



Figure 2. The image in grayscale




     The Cumulative Distribution Function (CDF) can be obtained and it is shown in Figure 3. It can be seen from the original CDF that there are irregularities in its shape. 






Figure 3. CDF obtained from the PDF

     From the activity sheet given to us, there is a clear illustration on how to modify the original CDF to a different CDF of interest. It is shown in Figure 4. For each pixel in the grayscale image, the value of the CDF was replaced by the value corresponding to the desired CDF.  




Figure 4. Steps on modifying the distribution function
    
     The cumulative distribution function of a uniform distribution is shown in Figure 5(a). Using this as the desired CDF, the distribution of the grayscale image was altered and shown in Figure 5(b). 




 Figure 5. (a) CDF of a uniform distribution; (b) Enhanced image after using uniform distribution 
     We were then tasked to create a nonlinear shape as the CDF.  A CDF with a nonlinear shape was used to enhance the image because our eyes have nonlinear response. It is shown in Figure 6. 




Figure 6. A CDF with nonlinear shape
       Using this as the desired CDF, the original CDF was again altered as shown in Figure 7. Backprojection was again implemented to enhance the quality of the image. 



Figure 7. Modified image using a nonlinear response


     Images can also be enhanced using GIMP (which is similar to Photoshop except that it's  free). First, I made the original image of the oblation into grayscale by going to Image ---> Mode ---> Grayscale. Then I manipulated the histogram by going to Colors ---> Curves. 





Figure 8. Original image that was grayscaled using GIMP's Adjust Color Curves  


    Figure 8 shows the grayscale image using GIMP. Figure 9 and Figure 10 are the resulting images after adjusting the color curves with nonlinear response. 




Figure 9. Enhanced image using GIMP's Adjust Color Curves 



Figure 10. Enhanced image after using a nonlinear CDF


Self-evaluation:
I would rate myself a 10 since I was able to comprehend the topic discussed in this blog. Also, I was able to produce the necessary output and was able to present my ideas in an organized manner. 


Acknowledgment:

I would like to thank Aivin Solatorio for the image used in this activity.






Tuesday, July 3, 2012

4th Activity: Area Estimation for Images with Defined Edges

This activity enables us to learn how to obtain the area of an image using Scilab. However, the image should have edges that are well-defined. There are two ways: pixel counting using logical operators and the other one is pixel counting using the Green's theorem.

Greens theorem gives the relationship between line integral and double integral of a function. It is given by the equation

                                     (1)


where D is the region while C is the curve enclosing the region and the curve is in counterclockwise direction.

The area at the region D can be calculated using the equation given by 

                                                     (2)

 Equation (2) can be represented in summation form

                                                     (3)
where Nis the number of pixels in the bounded region.

Equation 3 can be implemented using Scilab to obtain the area of an image with defined edges. 


Using GIMP, a rectangle was created and is shown in Figure 1.

Figure 1. A rectangle image

The rectangle that was created has dimensions: 350px by 250 px. So the area is analytically known to be 87,500  px2 .

To determine the number of pixels in white, the following code was implemented:

im=imread('/home/venven/Desktop/ap186/rectangle.bmp');
[ii] = find(im);
pixelcount=size(ii);

The obtained pixelcount is 87500. This matched the created image in GIMP.
The pixelcount represents the analytic area of the image.

Now what I did next was to compute for the area using Greens Theorem.

The calculated area is 86735.5 The percent error from the analytically known area is 0.8748471%.


To test again the effectiveness of the Greens Theorem, a place of interest was selected using Google Maps.
I chose the National Institute of Physics. :)


Figure 2. Location of National Institute of Physics using Google Maps

     Using GIMP, I cropped the image and converted it into black and white image.

Figure 3. Black and white image of NIP
pixelcount = 67,808 px2  
computed area = 67,097.50 px2
error = 1.0492707%.


To obtain the actual units, the scaling factor was taken.
 0.943396 ft/px or  0.289855 m/px 

The area of NIP in pixels is then multiplied to the scaling factor to get the approximate area.
The are was approximately 63,299.53 ft2 or 19,448.55 m2. I was not able to find any literature containing the actual land area of the National Institute of Physics. However, to check the validity of the result one can ask an authority of NIP.



Self-evaluation:
I give myself a 10/10 for fully understanding the concept and for being able to produce the desired output.
I was also able to present my thoughts and explanations in an organized manner.

Acknowledgment:
I would like to thank Gilian Uy for lending her laptop with an SIP Toolbox.
SIP toolbox was indeed helpful compared to the SIVP.




Sunday, June 24, 2012

3rd Activity: Image Types and Formats



In this activity, we were made to familiarize ourselves with different types and formats of images.


First, we were tasked to download examples of image types. 


Below are the images I downloaded for each image type. At the left side of each image is the corresponding information of the image obtained using <imfinfo>.


Image Types:


1.  Binary image



Figure 1. An example of binary image




Filename: /home/venven/Desktop/ap186/batmanBW.jpg
Filesize: 8072
Width: 225
Height: 225
BitDepth: 8
ColorType:grayscale










2. Grayscale images





Figure 2. An example of a grayscale image




Filename: home/venven/Desktop/ap186/gaussianG.jpg
Filesize: 11349
Width: 500
Height: 500
BitDepth: 8
ColorType: grayscale










3. Truecolor images



Figure 3. An example of truecolor image
www.whatscookingamerica.net


Filename: home/venven/Desktop/ap186/cake1.jpeg
Filesize: 10594
Width: 251
Height: 201
BitDepth: 8
ColorType: truecolor










4. Indexed Images



Figure 4. An example of indexed image
http://printplanet.com/forums/enfocus/16504
-indexed-color-spaces







Filename:/home/venven/Desktop/ap186/Indexed.jpg
Filesize: 12246
Width: 288
Height: 288
BitDepth: 8
ColorType: truecolor


















5. High dynamic range images



Figure 5. An example of high dynamic range image
http://www.cambridgeincolour.com/tutorials/high
-dynamic-range.htm



Filename:  /home/venven/Desktop/ap186/hrd.jpg
Filesize: 27848
Width: 300
Height: 200
BitDepth: 8
ColorType: truecolor












6.Multi or hyperspectral image



Figure 6. An example of hyperspectral image
http://exosky.net/exosky/?p=880



Filename: /home/venven/Desktop/ap186/orion.jpg
Filesize: 1189338
Width: 1600
Height: 1600
BitDepth: 8
ColorType: truecolor


















7. 3D images



Figure 7. An example of 3D image
http://www.aeromental.net/2011/01/11/5000-
photos-for-3d-glasses-red-and-blue-cyan/



Filename: /home/venven/Desktop/ap186/3D.jpeg

Filesize: 246364
Width: 500
Height: 378
BitDepth: 8
ColorType: truecolor








--------------------------------------------------------------------------------------------------------------------
The next task was to explain image file formats. 




1. Lossy image compression


     When compressed, some information from the image is not contained in the file.


Examples of lossy image compression:


a. GIF 
      This stands for Graphics Interchange Format. It is a compressed file format and is limited only for 256 colors. As a consequence, it is usually used only for animated images, icons, and logos [1].




b. JPG or JPEG
    This file format is named after the committee that created it. It stands for Joint Photographics Experts Group. Compared to GIF, JPEG has a wider range of colors. Thus, it is more used for colorful images and high resolution images [1]. This makes it mostly used by many people. 




2. Lossless  image compression
     When compressing an image, each pixel is maintained.


Examples of lossless image compression:


a. TIFF
    This stands for Tagged Image File Format. It ranges from 1-bit to 24-bit. It is mostly used for important images since it contains all the information of the original image. 
      
b. PNG
     Another image format is PNG which means Portable Network Graphics. It is mostly used by graphic artists and web developers.




---------------------------------------------------------------------------------------------------------------


Finally, we were told to follow the procedure given in the activity sheet.


The scanned image in Activity 1 was opened in Scilab and its size was observed. The code and the output is shown in Figure 8.


Figure 8. Code in obtaining the size of scanned image and the output




We were also made to gather examples of image types. It was shown at the first part of this blog. At the right side of the images, the image properties were shown. The properties was obtained by using the code below:


info = imfinfo('/home/venven/Desktop/ap186/batman.jpg');


From the collection of images previously, I took one of the images and converted it to grayscale. The code and the output is shown in Figure 9. 


Figure 9. Convertion of an image to grayscale
In figure 9, it can also be seen that the size of the matrix varied after conversion to grayscale.




It was then converted into black and white using 0.5 as the threshold value. Figure 10 shows the code and the output. 
Figure 10. Conversion to binary image


In figure 10, it can also be noted that the matrix size is the same with the previous one. 


Same step was done to the scanned image in Activity 1. Figure 11 shows the conversion of scanned image to grayscale. 


Figure 11. Convertion of scanned plot to grayscale


To get a good approximation of the threshold value, the histogram of the grayscale image was obtained. The code used for obtaining this is shown: 






Figure 12. Code and output of the histogram






The imhist function showed values from 0 to 256. After zooming in, the approximated lowest value was at  113. To get the threshold value, I divided this to 256. Thus, the obtained binary image is shown in Figure 13. 



Figure 13. Binary image of the scanned graph


Now, the background noise can then be eliminated since it was converted to a binary image. A binary image is an image containing only black and white. As a result, only the lines in the plot can be seen. 





Self-evaluation:



For this activity, I rate myself a 10 out of 10. 5 for technical correctness since I indeed understood all the concepts and 5 for quality of presentation since I was able to show all the figures and texts in a very understandable manner.  


It was fun searching for examples of different image types. Also, I was able to discover the differences in file formats in images. 




-------------------------------------------------------------------------------------------------------------------
References
[1]http://www.techterms.com/