Thursday, July 15, 2010

Entry 12: Fourier Transform Model of Image Formation

In this activity, we performed exercises to understand the properties of Fourier Transform.  Also, we applied the Fourier Transform technique to model image formation of a system of optical devices.  The rationale of this implementation lies on the fact that the projection of an image  through a lens at a large distance is equivalent to the Fourier Transform of the object.

The activity has four parts and each part introduces a different application of Fourier Transform on image processing.

The objective of the first part of the activity is to familiarize us with the nature of Fourier Transform.  It is inclined towards visualizing the effects of certain programming commands, related to Fourier Transform, on the original image.  We simulated some methods to emphasize some important concepts needed in applying Fourier Transform to an image.

Figure 1: First row - original images, second row - fft of images, third row - fftshifted second row, last row - fft of fft of original images.

In Fig. 1, the subject images - the circle and the letter A in the top most layer were subjected to a 2D Fourier Transform which results to the set of images shown on the second layer.  The set of images on the third layer is the result of using fftshift() to the images on the second layer.  The lowest layer represents the subject images after undergoing two successive 2D Fourier transformations.

It is observed in the images after applying Fourier Transform that most of the values are located at the corners of the image.  When fftshift() was applied to it, the diagonal quadrants of the images in the second layer were interchanged resulting to the images in the third layer.  Hence, the fftshift() function corrects the redistribution of the quadrants after applying the 2D Fourier Transform to the original image.

Observing the lowest layer in Fig. 1, it can be concluded that two successive application of 2D Fourier Transform to an image results to an inverted version of the image.

Now, in the second part of the activity, the method of Convolution is introduced.

Figure 2: Convolution of circles with varying radius and the letters VIP.

Convolution, basically, is the combination of two objects (in our case - images) to obtain a resulting object having the characteristic of the two original objects smeared together.

In Fig. 2, the top layer are circles with varying radius, the middle layer is the image to be convolved with the circles and the bottom layer shows the images of the convolution of the top and middle layers.

It can be inferred here that the smaller the radius of the circle convolved with the other image, the bigger the distortion of the resulting image.

In the third part of the activity we studied correlation.  Correlation is the process of of finding similarities between two signals.  In image processing, the method of correlation is a very powerful tool especially in matching algorithms.


Figure 3: Last column is the correlation of the characters in a phrase in the left column with the letter A in the middle column.

In Fig. 3, we can see the correlation between the image containing a phrase and the letter A.  It can be observed in the resulting image that at the locations of letter A's in the phrase, the correlation value is high.  This implies that the method can be utilized in rough searching of similarities between a template and an image.

In the last part, we performed the method of edge detection using the convolution integral.

Figure 4: Edge detection of patterns in the middle column with the letters VIP.
We can observe here that in Fig. 4, the detection pattern when applied to the original image, the resulting image highlights the edges of the original image.  Also, the detection level vary depending on the detection pattern used.


In this activity I would rate myself 10/10 for the complete results.

Source:
    Activity Sheet for Activity 6 - Dr. Maricor Soriano


Tuesday, July 6, 2010

Entry 11: Enhancement by Histogram Manipulation

Figure 1: RGB image to be used for analysis
Manipulation of pixel value distribution is a method of enhancing image's quality by adjusting the number of pixels having a certain pixel value to a desired distribution defined by the user.

We performed manipulation on the distribution of pixel values of a sample image shown in Fig. 1.

The colored image was first converted into grayscale to assess the value associated for each of the pixels.  The original image shown in Fig. 1 is depicted in grayscale - Fig. 2.

The grayscale version of the original image has its own characteristic pixel value distribution.  We computed the distribution of the pixel value and plotted the histogram of the values.
Figure 2: Grayscale image to be manipulated
In Fig. 3, the histogram of the pixel values in the grayscale image is shown.  The histogram shows that there is a

To start the enhancement of the image, we utilized the method of histogram back projection to reassign the pixels of the image with new values in accordance with the user's specified pixel value distribution.
As shown in Fig. 4, we used a uniform distribution as our target enhancement distribution for the image.  It is displayed in cumulative distribution.
 
Figure 4: Cumulative distribution of the uniform distribution
After applying the method of histogram back projection to the original grayscale image in Fig. 2, the resulting image is shown in Fig. 5.

Figure 5: Enhanced image using pixel values with uniform distribution
Notice that after applying the method to the original grayscale image, the resulting image seems to look brighter and equalized.

The next thing that we did is to investigate the changes in the original grayscale image when it is to be subjected in histogram enhancement using a pseudo-Gaussian distribution of pixel values.

We simulated a pseudo-Gaussian distribution histogram centered at 0.5 and has a spread of 0.2 as its parameters (Fig. 6).

Figure 6: pseudo-Gaussian distribution histogram for image enhancement

The CDF of the histogram in Fig. 6 is shown in Fig.7 which will be essential to perform the necessary image manipulation technique. 

Figure 7: Cumulative distribution of a pseudo-Gaussian distribution (0.5, 0.2)
The resulting image after using the pseudo-Gaussian distribution in the image histogram manipulation is shown in Fig. 8. 

 
Figure 8: Enhanced image using pseudo-Gaussian distribution.
It is quite obvious in the result that the resulting image is depicted by pixel values that are distributed about a central pixel value.  The variation of the intensity across the entire image is less as a result of the histogram used in the back projection method.  The resulting CDF of the enhanced histogram simply follows the histogram of the desired distribution used in the back projection method (Fig. 9).
 
Figure 9: CDF of the enhanced image using the pseudo-Gaussian distribution.
This time around, we used GIMP which is an image editor to manipulate the original grayscale image.  GIMP has a functionality with the same concept as in histogram back projection which is the "adjust color curve".

As seen in Fig. 10, by adjusting the "before-after-intensity curve", the GIMP is capable of changing the pixel value distribution of the input image.

Figure 10: Image manipulation in GIMP using the "adjust color curve"


Now, it must be realized that histogram back projection is a very powerful tool in image processing.  One of the possible applications of the method is when the raw image has a poor lighting, through histogram manipulation it is possible to remedy the problem.


In this activity I would give myself a 10/10 because even I posted this blog late  I was able to make all the necessary results.  Also, the important thing is that I learned a new GIMP functionality. :D

Tuesday, June 29, 2010

Entry 10: Area Estimation of Images with Defined Edges

Hello guys! I'm back again.  This time, we are tasked to play around with a method for computing the area of closed curves with defined edges in images.  This exercise will make way for us to understand the capability and flexibility of image processing in useful applications like measuring the area of a lot defined in Google map.  Applying the computational method used in this activity, for example, in evaluating the extent of a catastrophic event such as forest fire using its aerial images; we can save a lot of resources as compared to actual evaluation of the place.


FAQ

What method can be used in evaluating the area of a figure with defined edge?
  • The Green's Theorem is the most utilized method in finding the area in this activity.

What is Green's Theorem?
  • Green's Theorem is a mathematical construct which relates the line integral of the contour of a figure to the area of the figure enclosed by that specific contour.  The Green's Theorem is mathematically represented by

                                          (1)


How can we use Green's Theorem to derive the area of a closed figure with defined edge? 
  • From the Green's Theorem, the area of a continuous curve can be evaluated by the following equation

                                                        (2)

 In computational approach, this formula will be helpful after applying discretization method.  The discretized form of (2) is given by
                                                     (3)

This equation can now be used to create a programming algorithm to derive the area of a closed figure with defined edge.


Are the numerical calculations of the area accurate using the Green's Theorem method?
Applying the method to a circle wherein we know the actual analytic area, we can estimate the error produced by the method.


First Test:
  • Circle: r = 70 px
  • Numerically computed area = 15, 071 px^2
  • Analytically computed area = 15, 394 px^2
  • Error = 2.10%

Second Test:

  • Circle: r = 140 px
  • Numerically computed area = 60, 865 px^2
  • Analytically computed area = 61, 575 px^2
  • Error = 1.15%

Third Test:

  • Circle: r = 280 px
  • Numerically computed area = 244, 905 px^2
  • Analytically computed area = 246, 301 px^2
  • Error = 0.57%


From the three tests, we can observe that as the pixel dimension of the object whose area is to be calculated is larger, then the error of the computed area using Green's Theorem decreases relative to its analytic area.


How can you apply the computation of area using Green's Theorem in daily life?

One of its vast applications include the determination of area of a certain region in a map.  As an example, I chose to measure the area of the College of Science Administration Building using this method.

Map Calculation (College of Science Area):
Computed Area in pixels = 20852 px^2

Scale:
0.934579439 ft/px
0.285714285 m/px

Using the scaling factor taken from the scale accompanying the image of the map, we can approximate the area of the CS by simply multiplying the scaling factor with the calculated value returned by the Green's method.

Approximated Land Area of CS = 5, 957.71 m^2
Actual Land Area  = ?



Image of the CS admin bulding taken from Google Maps!..

Summing up everything discussed in this How-To++, we can say that the Green's method offers a convenient way of calculating the area of a region shown in a map.  This is quite a resourceful and less rigorous approach to measuring area of regions with defined edges.

It must also be noted that the larger the size of the region in pixels the more accurate the result of the area measurement.  Thus, the converse of the event must be taken with high caution.  Take into consideration that if you dealt with a region with a small pixel area, the resulting measurement has a high margin of error which may lead to wrong conclusions.

In finality, I want to consider treating myself a 12/10 for this activity for the effort I expended in putting things together and tried to be creative (A simple FAQ outline) in presenting this blog... :)

Source:
    Activity Sheet for Activity 4 - Dr. Maricor Soriano
    Google Maps