Activity 8 – Morphological Operations

in this activity we were tasked to perform morphological operations. morphological operations affect the shape of a binary object, whether to enlarge it, or eliminate it, or to combine two blobs together, or whatever task needed. this is important, since it can be used to clear out any noise in a signal, or to enhance the information that is needed to be extracted.

to perform a morphological operation one needs a binary image, containing the object/s to be modified, and a structuring element, which would determine the shape of the modification. there are two main types of morphological operation: erosion and dilation. the former chips off parts of the object, while the latter expands it.

the binary objects used were:

  1. a 5 x 5 square
  2. a triangle, with base = 4 px, height = 3 px
  3. a hollow 10 x 10 square. 2 boxes thick
  4. a plus sign

and the structuring elements used were:

  1. 2 x 2 ones matrix
  2. 2 x 1 ones matrix
  3. 1 x 2 ones matrix
  4. 3 px-wide cross
  5. a diagonal line, 2 px long

below are the results of the morphological operations. the lower left corresponds to the dilation, while the lower right corresponds to the erosion.

to expand on morphological operations, we were tasked to determine the area of the circles shown below:

Circles002

this would require isolating the circles using image segmentation, after which morphological operations can now be used.

three new morphological operations are introduced: Open, Close, and TopHat. the Open operator is a combination of the erosion and dilation operations. the object is eroded first, and then dilated. it opens the gaps between two connected blobs, and eliminates objects smaller than the structuring element. the Close operator dilates, and then erodes the object. this closes the gaps between two objects, and can be used to coagulate many objects with potentially the same characteristics. TopHat is basically the difference between the opening of the image and the original image.

the original image was split into 12 equally sized sub-images (256 x 256) in order to have many samples for the determination of the area of the circle.

the morphological operation used here was the Open operator, to eliminate the noise the might result from the thresholding. after performing the opening, the blobs are then labeled and the areas of each individual blob were determined. this was done by using the MATLAB function regionprops.

the area was found to be around 572 px, with standard deviation of 258 px.

one can then used this information to determine abnormally large cells (cancer cells) in an image. below is an image of normal cells wixed together with cancer cells.

Circles with cancer

using the Open operator, and by isolating the normal cells using the MATLAB function bwareaopen, i was able to extract the normal cells:

Normal_cells

as well as the cancer cells (green = normal cells; purple = cancer cells)Cancer_cells

Activity 6 – Properties and Applications of the 2D FFT

when one performs an FFT on a 2D signal, sometimes the axis of the signal on the spatial frequency plane would be shifted 90 degrees from the original axis of the input signal. what may be wide in the spatial plane may be narrow in the frequency plane. this is known as anamorphism. here are some figures that illustrate this phenomenon.

This slideshow requires JavaScript.

the next few slideshows demonstrate the FFT’s of different sinusoidal patterns. this one shows the FFT of sinusoidal patterns with different frequencies. the larger the frequency of the sine pattern, the larger the gap between the two dots in the frequency plane.

This slideshow requires JavaScript.

below is the effect of putting a bias on a sinusoidal pattern. the larger the bias, the more prominent the intensity of the center dot, and the less prominent the two dots on either side of the center.

This slideshow requires JavaScript.

this slideshow shows the FFT of rotated sine patterns. notice that the resulting FFT pattern is always shifted 90 degrees from the original sine pattern.

This slideshow requires JavaScript.

this slideshow shows the FFT of the addition of two sinusiodal patterns in different axes, with different frequencies.

This slideshow requires JavaScript.

this slideshow illustrate the FFT of the multiplication of two sine patterns with same frequencies, but with varying phase differences.

This slideshow requires JavaScript.

the next 6 slideshows display the FFT’s of the following:

  1. two dots with different gap distances
  2. two circles with different radii
  3. two squares with different sizes
  4. two gaussian shapes with different variances
  5. random dirac deltas convolved with different patterns
  6. equally spaced dirac deltas with increasing gap size

This slideshow requires JavaScript.

This slideshow requires JavaScript.

This slideshow requires JavaScript.

This slideshow requires JavaScript.

This slideshow requires JavaScript.

This slideshow requires JavaScript.

the following figures show how to remove the lines in a photograph of the lunar surface (1). first the image was converted to grayscale, and its FFT was generated (2). a filter was made to remove the horizontal and vertical line present in the fourier domain (3), since these lines contribute to the lines in the original image. note that there is a gap in the center of the filter. this is to preserve the information of that original image, which is located in the center of the fourier plane. the FFT and the filter was multiplied, and then shifted back to the spatial domain, resulting to the cleaned image (4).

the following figure used the same technique that was utilized in the previous exercise, except that the filter used was different (3). from the FFT (2) one can see the presence of big dots surrounding the center, which account for the noise present in the original image (1). the final image is found in (4).

Activity 5 – Fourier Transform Model or:

in this activity we try to determine how the output would look like if one applies a Fourier Transform on an image. the Fast Fourier Transform is a powerful algorithm that basically recasts a signal into another complex plane showing the image’s spatial frequency.

in the first slideshow, input images (1) were applied with an FFT using fft2(), and the resulting pattern was applied with abs() to get it’s intensity values (2). fftshift() was then applied to show more clearly the intensity plot (3). then from (2) another fft2() was applied to revert back to its original (albeit inverted) form. (to avoid this, one can use ifft().)

This slideshow requires JavaScript.

in the second set of figures, i used convolution to simulate the effect of changing the size of the aperture to the quality of the image. convolution is a method used to combine two signals such that the resulting signal would look similar to both input signals. the primary image used was “VIP”, and the apertures used were of radii from 0.1, 0.2, … , 1.0. the final output reveals that the smaller the aperture, the lesser the quality of the output. higher quality outputs were generated with bigger apertures.

in these set of figures, i used correlation to determine the similarity of a given pattern and the whole image. the pattern is “rolled” across the main image and the amount of correlation is determined. using this technique one could determine more of less the positions of the letter A’s through correlation and thresholding.

correlation

the final figure illustrates edge detection using convolution. three sets of patterns were used (left), and these patterns were convolved around the image (previously used in the correlation part). the results show that the edges that were being detected would depend on the pattern used. a horizontal pattern would yield horizontal edges, vertical patterns would lead to vertical edges, and dot patterns would detect all possible edges and corners.