Thursday, July 28, 2011

Activity 9 – Morphological Operation


I hope I would finish this by midnight.

Now, we have an activity in which our drawing skills and thinking skills were tested. Hand-drawn images were done in order to predict the outcome of the activity.

Morphological operation is where two objects were differentiated and creating new object based on the object’s structure. It is used to enhance images for further image processing.

Erosion and Dilation are two of the operations that can be applied to an image.
  1. Predict – Observe – Explain
  2. Figure 1 shows the (top) hand – drawn and (bottom) scilab - generated objects (A1 – A4) and the structural elements (B1 – B5). This was drawn in a graphing paper. For the hand-drawn images, the green-colored part is the resulting image for erosion operation while the combination of the two-colored part is the resulting image for dilation operation.
    Figure 1. (top) Hand-drawn and (bottom) scilab-generated objects. B1 - B5 are the structural elements.
    1. A 5x5 square
      Figure 2 shows the dilation (top row) and erosion (bottom row) of object A1 which is done by (a) hand and (b) scilab. It can be observed that only the erosion operation done by two methods were the same to one another. It is also observed in the dilation part that the both are similar but the orientation of the new object were flipped about an axis.
      Figure 2. (top row)Dilation and (bottom row)Erosion of (a)hand-drawn and (b)scilab-generated object, A1
    2. A triangle, base = 4boxes, height = 3 boxes
      Figure 3 also shows the dilation (top row) and erosion (bottom row) of object A2 which is done by (a) hand and (b) scilab. The same observation is seen for dilation. For erosion, the 4th figure for both (a) and (b) is indeed a blank image since there is no way to fit B4 in A2.
      Figure 3. (top row)Dilation and (bottom row)Erosion of (a)hand-drawn and (b)scilab-generated object, A2
    3. A hollow 10x10 square, 2 boxes thick
      Figure 4 also shows the dilation (top row) and erosion (bottom row) of object A2 which is done by (a) hand and (b) scilab. The same observation is seen for dilation. For erosion, the 4th figure for both (a) and (b) has only 4 ones because those pixels/boxes are the only part of A3 that B4 can be fitted in.
      Figure 4. (top row)Dilation and (bottom row)Erosion of (a)hand-drawn and (b)scilab-generated object, A3

    4. A plus sign, one box thick, 5 boxes along each line
      Figure 5 also shows the dilation (top row) and erosion (bottom row) of object A2 which is done by (a) hand and (b) scilab. The same observation is seen for dilation. For erosion, the 1st figure for both (a) and (b) is a blank image since there is no way to fit in a 2x2 image in a plus sign.
      Figure 5. (top row)Dilation and (bottom row)Erosion of (a)hand-drawn and (b)scilab-generated object, A4

  3. Other Morphological Operations

    1. Thin Operation
      Figure 6 shows the application of the thin operation onto the objects A1 - A5. This operation makes a binary object thin. It does not always give good thinned copy of the object if the object is too thick.
      Figure 6. Application of thin operation in (a-d) A1 - A4 scilab-generated objects
    2. Skel Operation
      Figure 7 shows the application of the skel operation onto the objects A1 - A5. This operation, like thin operation, performs thinning of the object but the algorithm it uses is faster than the algorithm that thin operation uses.
      Figure 7. Application of skel operation in (a-d) A1 - A4 scilab-generated objects

So here I am again, thankful that the activity was done smoothly and faster. I don't know what happened to me last week but now I know that I am not productive the week before. I will give myself a score of 12.

Thank you and good day.

Thursday, July 21, 2011

Activity 8 - Enhancement in the Frequency Domain


Good day once more. Another activity has been done but this time, I fail to get the best image. I did not know why I was not able to get a good image but at least I have done the activity. I was a bit disappointed for this activity. I became lazy yet again. Anyway, let me start with the production of binary images with two dots in it.
  1. Convolution Theorem

    Figure 1. Two dots
    In this activity, an image was generated with two dots(one pixel each) symmetric to the y-axis. Figure 1 shows the FT of the two dots. As observed, the modulus of the FT of the image has given a series of vertical lines that also form circular pattern. After this, the two dots were given given a varying radius. Figure 2 shows the FT of the varying dots. The pattern seen are similar with the two dots only that as the radius increases, the pattern shrinks.
    Figure 2. increasing radius of two dots.

    Next is to replace the dots with a Gaussian spots. Shown by figure 3 and its corresponding FT. It is quite tricky but easy to apply. The center is just shifted and all the rest follows. It is then observed that the FT is enlarged as the variance increases.
    Figure 3. Gaussian spot

    After that, a 200x200 array was done and 10 random dots were placed on it and FT was applied, showed in figure 4. Most of the dots seen in the image are still seen on the FT.
    Figure 4. Random dots.

    Next thing is another array with equally spaced 1's. This is shown in figure 5. It is observed that with increasing space, the number of dots seen in the Fourier plane decreases.
    Figure 5. Equally spaced dots.
  2. Fingerprint: Ridge Enhancement

    Figure 6 shows the original fingerprint(left) and its FT(right). I have used a pattern that will easily capture the edges of the ridges. With this filter, the ridges should be enhanced.
    Figure 6. Fingerprint and its FT.  Taken from the PDF file

  3. Lunar Landing Scanned Pictures: Line Removal

    Next is to remove the lines seen in the image of figure 7(left). A filter was created that will remove the lines. The lines are of low frequency along the y-axis so the filter used is a horizontal line that blocks out the low frequency in the y-axis and high frequency in the x-axis.
    Figure 7. Original image(left) and processed image(right)

  4. Canvas Weave Modelling and Removal

    This is the last part of the activity. I was not able to remove the dots seen around the image that is why the original image is only seen.
    Figure 8


After a long and tiring day, I was not able to finish the whole activity on time. I will grade myself with 4 points since I was not able to finish the activity I was supposed to do by tonight. Thank you..

Thursday, July 14, 2011

Activity 7 - Properties of the 2D Fourier Tranform


Hello guys.. I have done the new activity. It is about how Fourier Transform (FT) works or simply, FT's properties.

  1. Familiarization with FT with Different Patterns

    In this part of the activity, we were tasked to create several patterns and then apply FT in each of the patterns and of course, observe what happened.

    1. Square

      Figure 1 shows the pattern(top row) I created with two different sizes with their FT (bottom row). The top-left image has an area of 0.64 and the top-right image has 0.16. Applying FT on both images resulted to the image on the bottom row of Figure 1. As you may observe, the larger the area of the square produces smaller pattern in the Fourier plane.
    2. Figure 1. Square with size of 0.8 (top left) and 0.4 (top right) with their corresponding Fourier Transform
    3. Annulus

      Next pattern is an annulus which is like a donut. Figure 2 shows the object(top row) and their corresponding FT(bottom row). The thickness of the annulus(top-left) is 0.2 while the thickness of the other annulus(top-right) is 0.4. The same observation will be seen with the Square in part A1.
    4. Figure 2. Annulus with thickness of 0.2 (top left) and 0.4 (top right) with their corresponding Fourier Transform
    5. Square Annulus

      This pattern is quite tricky to create but obviously, it is not that hard. Figure 3 shows the object(top row) and their FT(bottom row). The top-left image has an aperture area of 0.36 while the top-right image has an aperture area of 0.04. It is observable that the FT of a smaller aperture area produces sharper image compared to that of a bigger aperture area.
    6. Figure 3. Square Annulus with aperture area of 0.36 (top left) and 0.04 (top right) with their corresponding Fourier Transform
    7. Two Slits along the x-direction

      This pattern is the same with a famous experiment, Young's double slit experiment. Figure 4 shows two parts, with a separation distance of (a)0.1 and (b)0.3. Diffraction patterns are seen in their FT which differs between the slit width and the separation distance of the two slits. When their separation distance are the same and differs in slit width(a,b), more order of diffraction is seen as the slit width increases(a - bottom left to a - bottom right). When their separation distances differs and the same slit width(a - bottom left and b - bottom left), still, more order of diffraction is seen as separation distance increases.
    8. Figure 4. Two slits separated by (a) 0.1 and (b) 0.3 and slit width of (a,b - left) 0.05 and (a,b - right) 0.15 with their corresponding Fourier Transform
    9. Two Dots Symmetric about the Origin

      I encountered some difficulty in creating this dot but fortunately, I managed to create them. Figure 5 shows the objects(top row) and their FT(bottom row). Both all 3 objects are separated by 1.0 with radii, both 0.1 for the 1st image, 0.1 and 0.4 for the middle image, and both 0.4 for the 3rd image. It can be seen the pattern in the Fourier plane decreases in the number of diffraction order as the dot size increases.
    10. Figure 5. Two dots with sizes of 0.1 (top leftmost), 0.1 and 0.4 (top middle), and 0.4 (top rightmost) with their corresponding Fourier Transform
  2. Anamorphic Property of Fourier Transform

    There are many things that are needed to do in this activity but those things are not really that hard but needed a lot of time to do it.

    First in the tasks is to create sinusoid of different frequencies and applying FT on each pattern which is shown in figure 6. It can be seen that the pattern separates as the frequency increases.
    Figure 6. Sinusoid with frequency (top row, leftmost) 4, (top row, middle) 8, and (top row, rightmost) 16 with their corresponding FT

    After that, a constant bias is added to the sinusoid in order to simulate a real image that has no negative values. Figure 7 shows this simulated real image with its FT. Comparing with figure 6, it can be seen that there is an additional information at the center of the image. When a non-constant bias is added to the sinusoid, it is easy to separate the two frequencies by getting its FT and locate the frequency where the maximum value is.

    Figure 7. Biased sinusoid with frequency (top row, leftmost) 4, (top row, middle) 8, and (top row, rightmost) 16 with their corresponding FT

    Figure 8 shows the rotation of the sinusoid and their corresponding FT. It can be seen in the FT figure that the whole figure rotate.
    Figure 8. Rotated sinusoid with frequency 10 and θ = (top row, leftmost) 30°, (top row, middle) 60°, and (top row, rightmost) 90° with their corresponding FT

    Figure 9 shows the (a)combination of two sinusoid along the x- and y-directions together with their corresponding (b)FT. When two sinusoid were added to one another, its FT form a diamond structure where only the edges are seen(b - top row). When two sinusoid were multiplied to one another, its FT form a square structure where only the edges are seen(b - bottom row). After obtaining the sinusoid, a rotated sinusoid were added. Figure 10 shows the (a)combination and their (b)FT. When the rotated sinusoid was added, only the sinusoid that was rotating rotates from 30° to 90°.
    Figure 9. Addition (a,top row) and multiplication (a, bottom row) of sinusoid with frequency (left) 4 and 8, and (right) 10 and their corresponding (b)FT.

    Figure 10. Multiplication of sinusoid of frequency 10 and added to a rotated sinusoid with the same frequency at and angle θ = (top row, left) 30°, (top row, right) 60°, (bottom row, left) 90°, (bottom row, right) 120° with their corresponding FT.
Finally, once again, I have completed this activity. It was not that hard but need some time to work on it. I will rate myself with 12 points. 5 points for the Technical part, 5 points for the Quality part and 2 points for the Initiative part because I compared the patterns in different sizes.

Thank you. :0

Tuesday, July 12, 2011

Activity 6 - Fourier Transform Model of Image Formation


There was a time when you really have to go for the alternatives in order to finish an activity. I could have done this activity before but I can't use the Fourier transform (FT) in version 5.3.2 so I just use the other version. In this activity, we were tasked to observe the effect of FT.
  1. Familiarization with discrete Fast Fourier Transform (FFT)
  2. In this part of the activity, we were asked to create an 128x128 image with a white circle at the center which is shown in figure 1(leftmost). The figure to its right is the intensity of its Fourier transform which is just by taking its absolute value. It is not clearly seen in the figure but there should be white part along the corner. Beside it, another figure, which is the same as the 2nd figure, but they are centered. It was done using fftshift. The rightmost figure is the intensity of the FFT of the FFT of the original image,which is the centered circle.
    Figure 1. Original image (leftmost), Intensity of FFT of image with(2nd image) and without(3rd image) shifting and (rightmost) Intensity of the double FFT of the image.
    The same was done for figure 2. As one can observe, the two figures in the middle are the similar as the two figures in the middle in figure 1 with the 3rd image to have some kind of a ray emitting outward. The 4th image(rightmost) shown in figure 2 is now inverted.
    Figure 2. Original image (leftmost), Intensity of FFT of image with(2nd image) and without(3rd image) shifting and (rightmost) Intensity of the double FFT of the image.
  3. Simulation of an Imaging Device
  4. Figure 3. Image with letters VIP
    In this part, we were asked to create an image with VIP at its center shown in figure 3. Next is to create another image with white circle in the center with different radius, shown in figure 4 and then get the FFT of the VIP image and use fftshift function for the circles since it is already in the Fourier plane. Multiply the shifted circles and the FFT of the object (VIP image). Next, is to get the inverse FT by applying FFT on the product. Then get the intensity of the image by using abs() as shown in figure 5. It can be observed that as the radius increases, the image can be seen clearly.
    Figure 4. Aperture with radii 0.1 to 0.7
    Figure 5. Intensity after convolution
  5.  Template Matching using Correlation
  6. Next part is to investigate how correlation works. Correlation is simply to relate two independent images and show their similarities.In this activity, an image with sentence on it were created as shown in figure 6 (left) and another image with only a letter A on it (right). Next is to get their individual FFT and multiply the FFT of A with the conjugate of the FFT of the sentence. As one can see at figure 7, the sentence becomes unclear but some of the letters are still recognized because it has a similar property with A. The unclear part is due to the extraction of the letter A feature from each of the characters. So, the more it is similar to the letter A the more it will be seen clearly after the correlation.
    Figure 6. (left) Sentence and the (right) template A.
    Figure 7. Resultant image after correlation.
  7. Edge Detection using Convolution Integral
  8. Finally, edge detection was studied using convolution integral. This is simply taking a new template and correlating it with an image not necessarily the same size as the template. In this activity, similar patterns but different directions were used to get the edge of the word VIP from part B. Figure 8 shows the edge detection using these patterns. There is one matrix that was used that clearly shows the edges of the letters. It can be observed that when the negative values of the template are arranged horizontally, the resulting image will form horizontal lines and the same if it were arranged vertically.
    Figure 8. (1st and 2nd image) These two images are the images from correlation of the letters VIP and the template example in the activity, (3rd image) from the spot template and the last two images are from a random template with a large value elements.

Now, I am done with this activity. A new activity has arrive and must be done quickly. I will rate myself with 10 points. 4 points for the Technical part, 4 points for the Quality part and 2 points for the Initiative part since I extend the template not only with the use of the patterns given in the activity.

Thank you. :)

Thursday, July 7, 2011

Activity 5 - Enhancement by Histogram Manipulation

Here I am once again, trying to come up with a beautiful way in blogging this activity. Yesterday, 5 July 2011, I had difficulty in applying some of the techniques for this activity.

Histogram Manipulation
Histogram manipulation is a technique to enhance the brightness of an image, especially dark images that are hard to distinguish the objects in it. The technique is pretty simple. First, find the normalized histogram, also called as probability distribution function (PDF) and getting the cumulative distribution function (CDF), simply the cumulative sum of the PDF. Next is to generate a new CDF and finally, look fora grayscale value and change its value based on the new CDF.
On the activity,  we were given the tasked to manipulate and observe the histogram of a dark image. Just like the technique mentioned above, PDF and CDF were obtained from the original image which is figure 1.

Figure 1. (left) True color image and (right) grayscale image
Figure 2 shows the (a) PDFs and (b) CDFs of figure 1. It is shown that there are more dark colored pixels in the image compared to the light colored pixels. This is due to the black part of the panda that makes the
Figure 2. (a) PDF and (b) CDF of the original image
Figure 3 shows the desired and new CDF and figure 4 shows the image after the manipulation and its corresponding histogram. I observed that as from linear to polynomial of higher orders, the reconstructed image becomes lighted which means that the image is now brighter compared to its original image.
Figure 3. (top row) Desired and (bottom row) New CDFs with (a,d) linear, (b,e) x2 and (c,f) ln functions

Figure 4. (top row) Reconstructed images and their (bottom row) histogram, PDF
From figure 4, the natural logarithm CDF(3rd column) does not lighten up the image and it just destroy the image. So, it is not recommended to use this function in manipulating the histogram. I have used GIMP to manipulate the histogram. Figure 5 is the image I manipulated using GIMP and it is darken.

Figure 5. Image manipulation using GIMP
For this activity, I would give myself 10 points. 4 points for Technical, 5 points for Qualities and 1 point for the Initiative by using scilab 5.3.2 for this activity and making a way to use the SIVP in determining the true value of the histogram.

I would like to thank James Christopher Pang for helping me understanding the backproject from desired CDF to the image.