Wednesday, June 30, 2010

Activity 4: Area Estimation of Images with Defined Edges

The function follow in scilab gives tremendous help in giving geometric information from images, such as area of an object of an image with defined boundaries. This object can be of any shape, all the follow function needs is the object's boundary. The follow function returns the pixel coordinates of these boundaries, to make it more accurate it is advised to convert the image to a binary type image, however, proper thresholding must be used to prevent loss of information on the objects boundary. Let us use first basic geometric shapes in testing the follow function capabilities.

Figure 1. (left) Circle with radius 8 a.u. and (right) Rectangle with sides 8 a.u. and 4 a.u.

In figure 1.we have two basic geometric shapes a circle with radius of 8 a.u. and a rectangle with side 8 a.u. and 4 a.u. The area of these figures will be computed by the help of the follow function. Since these images are already in binary type, conversion is not necessary. The follow function gets the pixel coordinates of the boundaries of the images. So now, we are not only able to get the area of the object we are also capable obtaining the object's perimeter.

Figure 2. Perimeter of (left) the circle and (right) rectangle in figure 1.

So now that we have the Boundary locations of the basic geometric shapes, we can use an elegant and powerful equation, the Green's Theorem. The Green's Theorem explains that a contour forming a smooth and close loop can be related to the area enclosed by the contour. It is given by this equation,
The equation above translates a double integral to a single closed integral. Physically it means that it can relate areas (double integral) to boundaries (single closed integral). Solving for the area, we will arrive at the following equation,
In discrete form, the area equation for an object with Nb elements would look like the equation shown below,
We now have the equation for area, all that is left now is to scale the pixel location to real physical values to get the real physical area. This is where we use the knowledge learned from activity 1, the pixel-to-real value ratio. After obtaining the area, the %error of the computed value must then be obtain to know the accuracy of the technique.

Theoretical Area of the Circle = 201.06193 a.u.
Computed Area of the Circle = 199.2072 a.u.
% Error = 0.92 %

Theoretical Area of the Rectangle = 128 a.u.
Computed Area of the Rectangle = 126.7624 a.u.
% Error = 0.97 %

We can see that the error is minimal and thus the method for this case is acceptable. Knowing this, we will try to find applications for this technique, such as land area computations. We will see if the method is still acceptable in large scale distances.

Figure 3. Satellite views of (left) Star City, (right) Enchanted Kingdom, and (bottom) Disneyland California. These photos are obtained from Google maps.

In figure 3, we see satellite images of three theme parks namely; Star City, Enchanted Kingdom, and Disneyland California. The interest from these images is to see how large does the land area of these theme are. (Well, we all know its gonna be Disneyland, its humongous!).

Since the images in figure 3 are true colored images, for accuracy, we should convert it to binary images with proper thresholding. Unfortunately, due to the colors that are present it was hard to get a very defined outline of the theme parks. Thanks to my colleague, Eugenio Leynes, an extra image tweaking was done for easy processing. An overlay was added to the image to roughly define the edges of the theme parks.

Figure 4. Images from figure 3 added with overlay for easier boundary definition.

From the images from figure 4, the binary version of the images can now be easily produced.

Figure 5. Binary version of the images from figure 4. Thresholding was quite easy due to the overlay that was added in figure 4.

The values of the elements of these binary images in figure 5 was then used in the follow function for the calculation of the pixel location of the object's boundary. Returned values from the follow function was then scaled to its real physical value via pixel-to-real value ratio. The last step to compute the land area was using the discrete area calculation via Green's Theorem.
The results obtained follows below,

Theoretical Land Area of Star City = 35,000 square meters
Computed Land Area of Star City = 30,379.163 square meters
% Error = 13.20 %

Theoretical Land Area of Enchanted Kingdom = 170,000 square meters
Computed Land Area of Enchanted Kingdom = 124,150.67 square meters
% Error = 26.97 %

Theoretical Land Area of Disneyland California = 343982.795 square meters
Computed Land Area of Disneyland California = 424,256 square meters
% Error = 23.34 %

We can see that compared to the simple geometric shapes used, the land area has a much higher % error. This high % error is may be due to the overlay added, since it is just a rough estimate where the boundaries of the object is. Also, another source of error is the largeness of the image. This can be justified by the pixel-to-real value ratio of each images.

Circle and Rectangle Pixel-to-Real Value Ratio = 0.04 a.u./pix
Star City Pixel-to-Real Value Ratio = 1.15 m/pix
Enchanted Kingdom Pixel-to-Real Value Ratio = 2.35 m/pix
Disneyland California Pixel-to-Real Value Ratio = 4 m/pix

As we can see from the pixel-to-real value ratio of each images, relatively, the higher the ratio the higher the % error of the computed area. An extra pixel included in the enclosed area would give a significant changes to the computed area if the ratio is significantly high.

Finding how large something is without even doing physical measurements on it is just fascinating. Imagine how long would it take you to measure the land area of the theme parks featured above (imagine measuring 350000 square meters land area of Disneyland! Whew!), while you can do it on your computer with you sitting down on your comfy chair in less than 15-20 mins. (Yey!)

I find this activity very exciting!I was fascinated on getting informations on an object without me even touching it! 10! 10! 10! I grade myself!

*finding the real land area of the theme parks was hard but thanks to these sites I have something to roughly compare with:
  • http://en.wikipilipinas.org/index.php?title=Star_City
  • http://www.philippines-travel-guide.com/star-ciy.html
  • http://en.wikipilipinas.org/index.php?title=Enchanted_Kingdom
  • http://en.wikipedia.org/wiki/Enchanted_Kingdom
  • http://en.wikipedia.org/wiki/Disneyland
  • http://www.ehow.com/facts_5406307_big-disneyland-california_.html
Reference:
Dr. Soriano. Applied Physics 186 activity handouts: A4 - Area Estimation of Images with Defined Edges

Saturday, June 26, 2010

Activity 3: Image Types and Formats

Digital images take different types and different formats. In this activity, these types and formats will be discussed and eventually find its use in image processing.

There are four basic types of images; these are binary, grayscale, truecolor and indexed images. Each type has different characteristics. The binary type of images stores picture elements in either ones or zeros. It is the smallest memory consuming type of image; however, the tradeoff for the small memory consumption is the loss of color of the image. Next is the grayscale type of images, these types of images stores picture elements to values between 0 (black) to 255 (white). The values in between 0 and 255 are converted into gradients of gray. Grayscaled images have larger memory consumption than binary images but it still has loss of color. The next type of images is the truecolor and it has the largest memory consumption of all the four basic types. From its name, the colors of the image is preserved by setting picture elements into three values; red, green and blue values. The last type is the indexed images, these images have smaller memory consumption compared to truecolored images but has high consumption compared to grayscaled images. Indexed images, as the name implies, turns red, green and blue values into index thus lowering the memory usage. The downside of indexed image is that it may lose color information due to the indexing of colors.

Now let us now discuss image formats, there is many kinds of image formats, each have its certain characteristics, but in this activity, only four image formats are discussed; BMP, PNG, JPEG and GIF.

BMP or bitmap, stores image pixels with color depth of 1, 4, 8, 16, 24 or 32 bits per pixel. A picture element in a picture minimally occupies n/8 bytes depending on the color depth.

PNG or Portable Network Graphics is a bitmapped image format that utilizes lossless data compression. Pallette-based, grayscale, grayscale with alpha, RGB, or RGBA images are supported by PNG image formats.

JPEG or Joint Picture Experts Group is a lossy compression image format. It compresses images file into 10:1 compression ratio, which, on the downside, produces loss in image quality.

GIF or Graphics Interchange Format, a bitmapped image format that supports up to 8 bits per pixel, allows up to 256 distinct colors to be referenced to a single image.

The following images are of different image type and image formats, image information immediately follows the image it refers to.


Figure 1. A truecolor image in Bitmap (.bmp) format. This image was taken from www.divegallery.com/wallpaper_3.html. The image was compressed to JPEG format for posting purposes only

FileSize: 2359352

Format: BMP

Width: 1024

Height: 768

Depth: 8

StorageType: truecolor

NumberOfColors: 0

ResolutionUnit: centimeter

XResolution: 28.34

YResolution: 28.34


Figure 2. A truecolor image in Portable Network Graphics (.png) format. This image was taken from www.sourceforge.net.

FileSize: 312111

Format: PNG

Width: 400

Height: 400

Depth: 8

StorageType: truecolor

NumberOfColors: 0

ResolutionUnit: centimeter

XResolution: 72.00

YResolution: 72.00


Figure 3. A true color image in Joint Picture Experts Group (.jpg) Format. This image was taken from www.deviantart.com.

FileSize: 166256

Format: JPEG

Width: 750

Height: 622

Depth: 8

StorageType: truecolor

NumberOfColors: 0

ResolutionUnit: centimeter

XResolution: 100.00

YResolution: 100.00

Figure 4. An indexed image in Graphics Interchange Format (.gif) format. This image was taken from someone very close to me XP.

FileSize: 18193

Format: GIF

Width: 345

Height: 245

Depth: 8

StorageType: indexed

NumberOfColors: 256

ResolutionUnit: centimeter

XResolution: 72.00

YResolution: 72.00


Applying the knowledge from image type and formats, a truecolor type image is converted to both binary and grayscale type image. The converted image is shown in figures 5 and 6 below,


Figure 5. A binary type of the image in figure 2.


Figure 6. A grayscale type of the image in figure 2.


A second truecolor image was also converted to both binary and grayscale images shown in figure 7.




Figure 7. A (left) truecolor image in its (right) binary type and in its (bottom) grayscale type. The original image was taken from http://fyfcolts.blogspot.com/2009/11/post-game-ceremony.html


Next we apply this conversion to image processing; the background of a scanned handmade plot will be separated from the plot itself. This will be accomplished by converting the image into a grayscale and thresholding it before it is converted into binary type image. This technique, however, is only applicable on plots which has no color on it, since binarized image will lose its color quality.

Figure 8. The scanned handmade plot from activity 1.


Figure 9. Grayscale version of handmade plot.


Figure 10. Histogram of the grayscale image (left) zoomed at the black values, (right) normal view, and (bottom) zoomed at the white values.


Figure 11. The binarized image of the handmade plot. The background was separated by thresholding the grayscale image before it was binarized.


This technique on separating the background from the image is very useful in cleaning scanned images from unwanted noise in the image. This removal of unwanted noise can be seen by comparing figures 8 and 11. The gray area on the top right part of the image in figure 8 is removed in figure 11.

This activity is very interesting because it is like photoshop-ing an image, the difference is in this activity is that the approach is mathematic and scientific. This activity is very interesting and I find a lot of applications for this technique. Again, I give myself a grade of 10 for enjoying and learning in this activity.

Reference:

Dr. Soriano. Applied Physics 186 activity handouts: A3 - Image Types and Formats.