Sunday, August 11, 2013

Activity 9 - Color Image Segmentation

In this activity, we learned how to extract a colored region of interest (ROI) from a colored image. This is called color segmentation, as in the activity title. We learned two techniques: parametric and non-parametric segmentation.

First, I have this simple colored image of a clothes hook mounted on a white dresser. I wanted to be familiar first with the techniques so I began with an easy image. The first thing to do is to select a monochromatic ROI in the image, as I have done below.

 Figure 1. (a) The original image. (b) Cropped monochromatic
region of interest (ROI).

Next, I took the RGB channels of the image in Scilab. Remember in the previous post, I did not know how to do it in Scilab and so I had to use GIMP. Turns out it was just an additional three lines. I then transformed the RGB channels into the normalized chromaticity coordinates (NCC), given by
Although we should have three NCC terms corresponding to RGB, note that these are normalized values, and as such the sum r + g + b = 1. Therefore, we can express b in terms of r and g, b = 1 - r - g. In short, we only need two coordinates.

Thursday, August 8, 2013

Activity 8 - Enhancement in the Frequency Domain

This activity involves applying the Fourier Transform to images and changing details in the frequency domain to enhance an image. First, for some warm-ups, I created various symmetric patterns and observed the FT of the images.

In an image, a 1-pixel dot represents a dirac delta. The FT of two dots symmetric about the center is a sinusoid pattern as shown below.

Figure 1. (a) Image of two dots symmetric about the center. Each dot is only one
pixel. (b) FT of the image in (a), a sinusoid pattern.

In general, the convolution of a pattern and a dirac delta is the repetition of that pattern at the location of the dirac delta. Thus, an image of two circles symmetric about the center can be considered as a convolution of a circle and two dots symmetric at the center. Also, we now know from the previous activity that the FT of a convolution of two images is equal to the product of the FTs of the images.

The FT of two circles symmetric about the center is equal to the product of an Airy pattern and a sinusoid. With varying radius, we can also see that the pattern changes.

 Figure 2. Left, from top to bottom: Image of two circles symmetric about the center
with radii 0.01, 0.05 and 0.1, respectively. Right, from top to bottom: FT of the
corresponding images from the left. We can see that as the radius decreases, the
Airy pattern dominates over the sinusoid pattern.

The FT of two squares symmetric about the center is equal to the product of a sinc function and a sinusoid. Here I also show the FT of squares of different sizes.

Figure 3. Left, from top to bottom: Image of two squares symmetric about the center
with sides 0.01, 0.05 and 0.1, respectively. Right, from top to bottom: FT of the
corresponding images from the left. We can see that as the length of the sides
decrease, the sinc pattern dominates over the sinusoid pattern.

I did the same for Gaussian circles and obtained the corresponding FTs.

Figure 4. Left, from top to bottom: Image of two Gaussian circles symmetric about
the center with the standard deviation σ = 0.01, 0.05 and 0.1, respectively. Right, 
from top to bottom: FT of the corresponding images from the left. We can see that
as σ decreases, the Gaussian pattern dominates over the sinusoid pattern. 

Here I placed random white dots on black background and convolved it with different patterns. I show here the convolution with a star and a pentagon. The locations of the patterns are precisely the randomly generated dirac deltas.

Figure 5. Top, left to right: A pentagon and the convolution with randomly placed
dirac deltas. Bottom, left to right: A five-pointed star and the convolution with
randomly placed dirac deltas.

And last for the preliminaries, I generated equally-spaced white patterns and obtained their corresponding FTs.

Figure 6. Left, from top to bottom: Regularly spaced white lines every 50, 20,
25 (both horizontal and vertical), 10, and 5 lines. Right, from top to bottom: FT of
the corresponding images from the left, which look like interference
patterns from a grating.

Wednesday, August 7, 2013

Activity 7 - Fourier Transform Model of Image Formation

This activity served as an introduction to manipulating images in the frequency domain to enhance or remove certain parts of an image.

Brief background: basically the Fourier Transform is a linear transform of a function f(x) into F(k) through the following equation:
In App Phy 183 and App Phy 185 we applied the Fourier Transform on various time-domain signals (sound, etc.) to convert them into frequency domain. Now, we apply the two-dimensional FT to an image to obtain the spatial frequency of an image:
However, this integral can be approximated by the Fast Fourier Transform (FFT) algorithm, which is basically the discrete FT, and is widely used in many computational and image processing programs like Python and Scilab. Now this exercise is a familiarization to the fft() and fft2() functions of Scilab.

Wednesday, July 3, 2013

Activity 6 - Enhancement by Histogram Manipulation

This activity, as the title suggests, involves playing around with the histogram of a grayscale image to correct or enhance the image. In our case, we chose a dark image and we want to enhance the image by correcting the brightness and contrast levels so that more detail will be visible.

So here's what I did. First I chose my image. I have a sunset image of Dresden, Germany (from my adviser Dr. Rene Batac who's taking up his postdoc there) as shown below:
Figure 1. Sunset in Dresden. My adviser sent this to me
because he knew how much I loved sunsets, and it was a
particularly beautiful sunset.

As you can see, the foreground is dark while the background is light, and so I cropped the image to only select the lower half of the sunset image,
Figure 2. Lower half of the sunset image above. The foliage
and a few buildings are barely visible in this half.
and used this image for the activity today. The goal now is to adjust the brightness and contrast levels to make the foreground visible.

To enhance my image, here are the steps I did. First, I converted the image to grayscale using Scilab and took the histogram of the gray values. Normalizing the histogram, I would obtain the probability density function (PDF) of my image. Strictly speaking, a PDF describes the probability that a variable may take on a specific value, but here the PDF of the image describes the likelihood that a gray value (from 0-255) will appear on the image. As we can see in the images below, the PDF peaks around the lower values, signifying that the image is mostly dark-pixeled. Another related graph is the cumulative distribution function (CDF) of the image, which describes the likelihood that a gray value will be less than or equal to some given gray value.
For my image, the CDF is rapidly increasing along low gray values and tapers of at 1. This is expected, as the probability cannot be more than 1.
Figure 3. from left to right: (a) histogram; (b) PDF; and (c) CDF of the grayscaled
image shown in Figure 2. The gray values are concentrated at the lower end.
The next task is to correct the image by applying a linear CDF onto the original image. To do this, I first created a uniformly distributed PDF and took the corresponding CDF using Scilab. For each CDF value in the image, I need to find the corresponding image pixel in the linear CDF. My first idea was to use find() and return the index of the CDF value. However this does not work, as the CDF values in the image and in the linear CDF I constructed do not correspond. The trick is to use the mathematical equations and treat the CDF as a continuous function, rather than a matrix.