Monday, July 20, 2009

Activity 8 | Morphological Operations

Morphological operations simply refers to operating on the structure of something and these operations can be thought of like operations on sets like 'union', 'intersection', 'complement' and many others. An example of operations is the XOR which is union minus intersection and [NOT(A)] AND B which is the intersection of 'complement of A' and 'B'.

In this activity morphological operations like 'dilate' and 'erode' are implemented on 5 images namely a square, triangle, circle, a hollow square and a cross. Four structuring elements are used in the dilation and erosion of these images and these are a 4x4 square, 2x4 and 4x2 rectangles, and a 5x5 cross with a width=1. Figure 1 shows the structuring elements while Figure 2 shows the original image (column 1) and the respective resulting images for the dilation of the original with the order the same as the order of the structuring elements in Figure 1 while Figure 3 shows the results for erosion.


Figure 1. Structuring elements.


Figure 2. Resulting images after dilation.


Figure 2. Resulting images after erosion.


Before erosion a dilation was applied to the images by simulating the predicted resulting images. The shape of the predicted images are the same as the simulations. Only the dimensions of the resulting images were a bit different than the simulated ones but were close estimations. An simple example is for the 50x50 square when dilated with the 4x4 square. The predictions made resulted to a 54x54 square but the simulations gave a 53x53 square. This error is due to the assumption that the center and the axes used for the operations did occupy pixels.

I give myself a grade of 9 for this activity for the successful predictions of the shape of the resulting dilated and eroded imaged and for the good estimation of the dimensions.

Activity 7 | Enhancement in the Frequency Domain

The Fourier Transform properties had been familiarized already in the previous activities. With this knowledge we use it to enhance images not by changing the image itself but its Fourier Transform. Now we examine the FTs of different patterns such as two dots with increasing radius where the smallest dots are two separate pixels as shown in Figure 1.

The FT of the two pixels is a series of lines that looks like a sinusoid. We can remember from previous activities that the FT of a sinusoid are two small dots along the axis of propagation of the sinusoid. Taking the FT of the two separate pixels is like doing the inverse FT of the FT of a sinusoid. The FTs of the two small circles on the other hand is like the product of the FT of the two pixels and a circle like that from Activity 5, and it is observed that increasing the size of the spots decreases the size of the resulting FT.




Figure 1. Two dots with increasing radius and their respective FTs.

We know that a pixel is square in shape. If we enlarge these squares the FT will change from that of a sinusoid pattern to like that of the two small circles only instead of the product of the FT two dots and a circle, the patterns looks like the product of two dots and a scquare. Increasing the size of the squares also decreases the size of the FT pattern just like in Figure 1. The images for the squares and their FTs are shown in Figure 2.




Figure 2. Two squares with increasing size and their respective FTs.

Now Figure 3 shows the two gaussian of varying variance and their FT while Figure 4 shows the Gaussian dots and the inverted counterparts and the real and imaginary parts of their FTs. It may not be visible but there is a small faint set of vertical lines shaped in a circle centered at the bright spot.



Figure 3. Two Gaussians with increasing variance and their respective FTs.




Figure 4. Two Gaussians with increasing variance and their respective FTs' real (middle row) and imaginary (last row) parts.


Using the concepts above we apply them in enhancing images in the frequency domain. We perform enhancement on three images namely a fingerprint for ridge enhancement, lunar landing scanned pictures for line removal, and a digital painting for canvas weave modeling and removal.

RIDGE ENHANCEMENT - Fingerprint


Figure 5. To be enhanced fingerprint image and its FT.

Enhancing this fingerprint such that the ridges are defined is the main goal for this part of the activity. Looking at the FT of the fingerprint we can see areas that are the brightest and could possibly be the FT pattern for the ridges. Basing from the FT we then create a mask to obtain the ridges of the fingerprint alone.

Mask 1: Thresholding


LINE REMOVAL - Lunar landing scanned pictures


Figure 5. To be enhanced fingerprint image and its FT.

CANVAS WEAVE MODELING and REMOVAL - painting

Thursday, July 9, 2009

Activity 6 | Properties of the 2D Fourier Transform

Previously in Activity 5, we applied image processing techniques involving the Fourier Transform such as edge detection and template matching using convolution and correlation. Now we investigate further the properties of the 2D Fourier Transform. The properties to investigate are that the Fourier Transform expresses any signal or image into a superposition of sinusoids and that the rotation of the sinusoids result to the rotation of the Fourier Transform.[1]

Before anything else let us familiarize the Fourier Transforms of some 2D patterns (left) namely a square, an annulus or donut, a square annulus, two slits, and two dots along the x-axis that are symmetric about the center which are shown below together with their corresponding FTs (right) shown in Figure 1.

Figure 1. 2D patterns and their corresponding Fourier Transforms.

Now we investigate the anamorphic property of the Fourier Transform through the investigation of the superposition and rotation of sinusoids and their FTS in relation to the FT of different 2D patterns.

We create a 100x100 sinusoid with frequency f = (1, 4, 16) and get the modulus of its Fourier Transform. The images in Figure 2 show the produced 2D sinusoids (upper row) and their corresponding FTs (lower row) with increasing frequency values from left to right. The Fourier Transform of a 2D sinusoid results to an image with a peak at the frequency (+f or -f) of the said sinusoid thus we see two points along the axis of the sinusoid and symmetric from the center which is f = 0. As the frequency increases, the distances between the two points increases as expected. Code is taken from the AP186 Activity 6 sheet.

nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 1; //frequency
z = sin(2*%pi*f*X);
imshow(z, []);



Figure 2. 2D sinusoids with frequencies f = 1, 4, and 16 and their corresponding FTs.

Figure 3 shows how the Fourier Transform of the resulting sinusoids would look like if a constant bias (upper row) or another sinusoid of low frequency (lower row) is added to the original sinusoids shown in Figure 2. The frequency order is the same as in Figure 2.



Figure 3. Fourier Transform of a sinusoid with a constant bias (upper row) or with an added low frequency sinusoid (lower row.)

Adding a constant bias to the original sinusoids resulted to the addition of a peak (which is the bias) at f = 0 to the respective Fourier Transforms of the sinusoids. If another sinusoid is added to a sinusoid the FT will show the frequencies of the two sinusoids like if a sinusoid with f=4 is added with a sinusoid with f=1 then their FT will show a peak at f=4 and f=1.

Rotating the sinusoids will also rotate their FTs as shown in Figure 4 for theta = 30, 45, and 60. Then we combine these rotated sinusoids to make patterns.



Figure 4. Rotated sinusoids (upper row) with f = 4 and the FTs (lower row) at theta = 0, 45, and 60 degrees respectively.

Now if we combine a sinusoid running in the x direction with another running in the y direction by addition or multiplication we get patterns as shown by Figure 5 below. Their FTs are just the superposition of their individual FTs. The code that generated these combinations are the following:

z_sum = sin(2*%pi*4*X) + sin(2*%pi*4*Y);
z_prod = sin(2*%pi*4*X) * sin(2*%pi*4*Y);
z_prod2 = sin(2*%pi*4*X). * sin(2*%pi*4*Y);




Figure 5. Combinations of a vertical and horizontal sinusoid using the equations shown above and their FTs.

If we add series of arbitrary rotated sinusoids to the patterns in Figure 5 we get patterns that looks like twisted checkered patterns as shown in Figure 6 below. The FTs of the patterns below is the same as the predicted results except for the matrix multiplication (middle row) where its FT is the same as the original pattern. It can be observed that the pattern itself has little deviation from the original pattern. As for the addition and the element by element multiplication, their FTs is the same as predicted which will be again, a superposition of the FTs of the original pattern and the added rotated patterns. If the added rotated sinusoids have rotations that scan from 0 t0 90 degrees in small increments then we expect a circle to form in the FT of that image which is partially shown by the FTs for the addition and the element by element multiplication.




Figure 6. Combinations of a vertical and horizontal sinusoids added with arbitrary rotated sinusoids and their corresponding FTs.

I give myself a 10 for this activity since the FTs produced were correct and they matched what was expected.