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.