Wednesday, December 7, 2016

Activity 11 - Basic Video Processing

Last activity for AP 186!

Activity 10 is about video processing. Video processing is not really that different from image processing, since a video is basically a series of images. And so, what we can do is process each image that comprises the video. 

The task at hand was to experimentally determine a kinematic constant, such as the acceleration due to gravity \( g \), by processing a video capturing a kinematic event. One way to determine \( g \) was simply to drop an object from a certain height and determine the time for it to travel a certain distance. \( g \) can then be calculated using the equation
$$ g = \dfrac{2 (h_o - h)}{t^2} $$
where \(h_o\) is the initial height, \( h \) is the final height, and \(t\) is the time to reach \(h\) from \(h_o\).

The video below shows my trial in performing this activity. I dropped a red cube and captured the event using my phone. The ruler was meant to serve as reference for distance. 


The video was then converted to images using Video to JPG Converter. The series of images during the drop are shown below









To identify the object, we perform color image segmentation like we performed in one of the previous activities. I obtained the color patch of the ROI from the cube in the 1st image. However, I encountered a problem. The object is identified until the 2nd image only. Starting from the 3rd image, since the object is blurred due to its motion, it cannot be identified using the ROI used. 

Luckily, Harold offered to let me use his video (thanks Harold!) of a simple pendulum. The video is shown below. \( g \) may be calculated by knowing the period of its oscillation \(T\) and using the formula 
$$g = \dfrac{4 \pi^2 L }{T}$$
where \(L\) is the length of the string



The same thing was done, where color segmentation was performed to identify the ball. Some of the images comprising the video are shown below.
















Monday, December 5, 2016

Activity 10 - Enhancement by Histogram Manipulation

The sem's almost over! One more activity after this and I'm done with blogging for AP 186. One more activity after this and then AP 186 exam. Although, an exemption from taking the final exam is possible, and I do hope I qualify.

On to the activity! Activity 10 is about enhancement of  features in an image by manipulation of its histogram. Take for example a grayscale image. First, we take the probability distribution function (PDF) of the grayscale intensities, by taking the histogram of the grayscale intensities and normalizing it by the total number of pixels. We then take the cumulative distribution function (CDF) from the PDF (refer to the link for CDF information https://onlinecourses.science.psu.edu/stat414/node/98). To manipulate the histogram, we backproject the grayscale intensities with a desired CDF of ours. Following the discussion in out manual (thank you ma'am Jing), if we for example have \( A(x) \) as the CDF of our image, and \( B(y) \) is our desired CDF, then for each pixel intensity in out image, we transform it to \( y = B^{-1}(A(x)) \). In other words, if we have a pixel intensity \(x\), we determine its corresponding CDF value \( A(x) \), then determine the corresponding \(y\) value that produces \( B(y) = A(x) \).

Let's take for example the image shown below. We first convert this image to grayscale, which is also shown below. 


Image A

Image A in grayscale
We then manipulate the histogram of this image. The PDF and CDF of this image is shown below. We backproject this CDF using a linear CDF, which runs from (0,0) to (255,1). This equalizes the histogram of the image. The resulting image is shown below. 


PDF of image A in grayscale
CDF of image A in grayscale

Grayscale image A after histogram equalization
The colored image can also be enhanced by histogram manipulation. If we convert the \(RGB\) values to \(rgI\) values, histogram manipulation can be done on the \( I \) values. The \(I\) values were normalized with respect to the maximum value \(I_{max}\), then the histogram was obtained. The PDF as well as the CDF were then obtained, which are shown below. Backprojection was also done using a linear CDF, and the resulting image is shown below.


PDF of colored image A
CDF of colored image A

Colored image A after histogram equalization
Note that upon histogram equalization, features in the dark portions of the original image are now enhanced. Observe the differences of the encircled portions from the original image, which can also be observed in the equalized grayscale image. The distinction between legs can now be observed, and the features of the bag are more enhanced.

The image below was also histogram equalized, both the colored image and the grayscale image.

Image B

Image B in grayscale

Grayscale image B after histogram equalization

Colored image B after histogram equalization

Note that from the original image where my face was dark, the features of the face are now enhanced. The eyes and the ears are now more visible than the original image, as observed in the grayscale and colored images.

I would give myself a grade of 10 for this activity since I think I have successfully performed histogram manipulation to enhance the features in the image.