Tuesday, June 23, 2009

Activity 3 - Image Types and Basic Image Enhancement

This activity has 2 major parts. First, different image types which are Binary, Grayscale, Truecolor, and Indexed image were collected. Their respective properties including the pixel dimensions, resolution, image type, file size file type were also determined. The second part involves the conversion of scanned image to grayscale for histogram and threshold determination. Then, the area of the region of interest (ROI) of the Binary-converted image from being a Grayscale type is calculated using Green's theorem which is similar to the method utilized in Activity 2.

Note that the second part was only started after the SIP Toolbox and ImageMagick which are needed for Scilab to handle images, were installed thus the first part was finished before Activity 2 was completed.

Using the internet, I searched some images then I was able to determine their image type and other image properties using the software GIMP 2.6.6.

1. Binary Image
The first image is somehow resembling an optical illusion. It is only composed of 2 colors by mere observation.


Width = 405 pixels
Height = 397 pixels
Horizontal Resolution = 72 dpi (dots per inch) or ppi (points per inch)
Vertical Resolution = 72 dpi
Color Space = Indexed (2 Colors)
File Size = 4.3 kb
File Type = GIF Image
Source: http://acjournal.org/holdings/vol5/iss1/articles/radwan.htm

Notice that the color space from the properties of the image above is indexed, but it only comprises 2 colors which represent pure black and white, thus it is a Binary image indeed.

2. Grayscale Image
I found a grayscale image of the lake at the summit of Mt. Pinatubo which is shown as follows.


Width = 640 pixels
Height = 433 pixels
Horizontal Resolution = 72 dpi
Vertical Resolution = 72 dpi
Color Space = Grayscale
File Size = 48.8 kb
File Type = JPEG Image
Source: http://www.volcano.si.edu/world/volcano.cfm?vnum=0703-083&volpage=var

Obviously, the image above is a grayscale one because it contains the different shades between black and white.

3. Truecolor Image
The next image is a panoramic view of Taal Volcano as seen from Tagaytay Ridge.


Width = 500 pixels
Height = 338 pixels
Horizontal Resolution = 96 dpi
Vertical Resolution = 96 dpi
Color Space = RGB Color
File Size = 105.9 kb
File Type = JPEG Image
Source: http://www.flickr.com/search/?q=taal+volcano

Since the image of Taal Volcano above has color space of Red-Green-Blue (RGB), then it is a Truecolor image.

4. Indexed Image
The following image illustrates the location of major volcanoes in the Philippines. This is apparently an Indexed image because there is less color information compared to a Truecolor image.


Width = 351 pixels
Height = 752 pixels
Horizontal Resolution = 96 dpi
Vertical Resolution = 96 dpi
Color Space = Indexed (51 Colors)
File Size = 23.8 kb
File Type = GIF Image
Source: http://www.absoluteastronomy.com/topics/Pacific_Ring_of_Fire

From the image property color space, the image above is an Indexed image type which has 51 representative colors independent from each other.

For the second part of this activity, I scanned an old 2-peso coin for its area calculation. The scanned image is shown below.


Using the command im2gray in Scilab, I was able to convert the scanned image to a Grayscale-type one. Then im2bw made it into a Binary image type. Finally, I used Microsoft Paint to make the text and image of Andres Bonifacio to black and invert them to white and the white background to black. The 3 images in order of Grayscale, Binary, and inverted Binary are displayed below.



The Grayscale image has the following properties.

Width = 476 pixels
Height = 520 pixels
Horizontal Resolution = 72 dpi
Vertical Resolution = 72 dpi
Color Space = Grayscale
File Size = 12.6 kb
File Type = JPEG Image

The histogram plot of the Grayscale image is as follows.



From the histogram plot above, the horizontal axis is the Grayscale values from 0 to 255 and the vertical axis is the number of pixels. The Grayscale range between 100 and 150 represents the ROI and the spike between 200 and 250 represents the background. I can infer from the histogram plot that the ROI is well separated from the background. A threshold of 0.7 for converting the Grayscale image to Binary is best suited based from this plot.

Finally, the following data for area calculation of the 2-peso coin are obtained.

Calculated Area using Green's Theorem = 46300 square pixels
Theoretical Area = 46005 square pixels
Percent Error = 0.64 %

Since the object under area calculation is no longer a basic geometric shape, hence the best way to get its theoretical area is simply summing all the elements of the imported Binary image which only consists of zeroes and ones. But due to the fact that the followed contour is not included to the Green's calculation of area (the followed contour is the white perimeter before the transition to the black background), then it is subtracted to the summation of ones for more accurate theoretical area.

I grade myself 10/10 here because first, I was able to complete all types of image asked in this activity and identify their properties, and second, because of the very small deviation of the calculated area of the 2-peso coin using Green's theorem from the theoretical value I got.

This activity is done successfully through the help of Gary and Ed in search of different image types and Raffy for the proper syntax in Scilab.

Appendix
The following Scilab code is implemented in converting the scanned image to Grayscale and Binary, acquiring the histogram plot of the Grayscale image, and calculating the theoretical and Green's area of the 2-peso coin.

coin = imread('coin.jpg'); // For Image Conversion
coin_gray = im2gray(coin);
imwrite(coin_gray, 'coin_gray.jpg');
coin_bw = im2bw(coin_gray, 0.7);
imwrite(coin_bw, 'coin_bw_inv.jpg');
imfinfo('coin_gray.jpg');

gray = imread('coin_gray.jpg'); // For Histogram

a = 1;
grayscale = [];
pixels = [];
for j = 0:255
[x_gray, y_gray] = find(gray == j);
grayscale(a) = j;
pixels(a) = length(x_gray);
a = a + 1;
end

plot(grayscale, pixels);

coin_pic = imread('coin_bw_inv.jpg'); // For Area Calculation
coin = im2bw(coin_pic, 0.5);
[x_coin, y_coin] = follow(coin);

n = length(x_coin);
A_coin = [];
for i = 1:n-1
A_coin(i) = x_coin(i)*y_coin(i+1) - y_coin(i)*x_coin(i+1);
end

Theo_coin = sum(coin) - length(x_coin)
Area_coin = sum(A_coin)/2
percent_error_coin = abs(((Theo_coin - Area_coin)/Theo_coin))*100

No comments:

Post a Comment