Monday, July 26, 2010

AP 186 Activity 5: Enhancement by Histogram Manipulation

There are so many digital ways to manipulate images. Basically, an image can be represented by sets of numbers and from there controlled as wanted. Paint, Photoshop and Gimp are among the mainstream image editing software available today.

I used two pictures in this activity, one from my personal library and one from the internet. However, I used the latter image as my main image in analysis because it is smaller. (Faster! :p)

Sunset at the beach.


The Fray.

Below is the initial conversion to grayscale of the 'fray' image.
Now, a quantitative property of grayscale images are Probability Distribution Functions (PDFs) and Cummulative Distribution Functions (CDFs). The PDF of an image is basically the distribution of the pixels in the image corresponding to the gray levels equal to 0-255. On the other hand, the CDF on an image is the like the cummulative summation of the PDF. Below are the normalized PDF and CDF of the grayscale fray image.

With this information, we can remap the CDF to correspondingly adjust the levels of the image. Below are the transformed CDFs and images, linearly, exponentially and parabolically (coined term? hehe) respectively.
I also did this for the sunset image, from left to right and then top to bottom: the original conversion to grayscale, the linear CDF, the exponential CDF, and the prabolic CDF.
Histogram manipulation can also be done using software available, such as GIMP. Open an image, set its mode to grayscale and then go to Colors  > Curves.


I must admit that I did this activity in MATLAB. It's too costly to run a virtual Windows on Mac and to process images at the same time. I was not very much progressive during the time we did this in class, so I finished this at home.

--

I'd like to thank Aivin, Che and BA for the helpful discussions. Also to Kuya Jeric and Tisza for their codes.

http://www.aiaccess.net/English/Glossaries/GlosMod/e_gm_distribution_function.htm
--
Technical Correctness: 5
Quality of Presentation: 4
Initiative: processed other images to see the effects

Thursday, July 1, 2010

AP 186 Activity 4: Area Estimation for Images with Defined Edges

While estimation is a certain degree very much reliant on probabilities, it is always good to get as close to the actual value as much as possible. In this activity we are to estimate, at the very least, the actual area of a specified part of an image. To start off, we used regular shapes. In my case, I used a quadrilateral.


Binary image

Using the follow command, the edges of the quadrilateral image (white) was traced, and the corresponding coordinates listed. Below is a plot of the coordinates gathered from this function. From the graph, the area of the shape can be measures crudely by noting how many pixels the width and the length measure. The gathered minimum for x, is 94 pixels and the maximum is 444 pixels,  that is 350 pixels in width. For y on the other hand, the minimum is at 73 pixels and the maimum is at 257 pixels, that is 184 pixels in length. From this method, the area is 64400 square pixels. Green's method resulted to 64400 square pixels as well. Summing the image on the other hand gave 64935 square pixels. This was a particularly easy shape to measure, being a well defined quadrilateral. The analytic result was the same as that of Green's method. However, the sum of the image had a 535 pixel difference. Perhaps there are still some scattered 1's in the image that are not part of the shape in case.
Plot of the quadrilateral.


For this activity, I am using the Moses Mabhida Stadium as my object of interest. According to South Africa's official website, the ground is formerly the Kings Park Soccer Stadium and the current Stadium was built especially for this year's World Cup. Here is a Google Earth snapshot of the 2010 World Cup arena.


From Google Maps is this image of the stadium, taken as a screen shot.


I measured the total area of the stadium, using image analysis. First, it should be noted that the image is 634x478 pixels, and it has 96 dpi. I loaded the image into Scilab and then converted it into black and white.
I used paint go get the coordinates of the scale of the image. From there, the measured scale equivalent to 100 meters is to 66 pixels. Also by using Paint, I isolated the area I wanted to measure so to exclude (darkened) the unwanted details.


Using the follow command, I measured the area of the field by summing the image and Green's theorem, which are 31816 and 31522.5 respectively. These are in terms of pixels, so using the initially noted scale factor of 66 pixels : 100 meters, 4356 square pixels : 10000 square meters. This is a factor of 0.4356 to be multiplied to the pixel area measured to get the true value of the area.

Wikipedia lists its field area to beWith the Green's theorem result, the stadium measures 13744.269 square meters. With the summing of the image, the stadium measures 13859.0496 square meters. There is a 0.83% difference in these two measurements. This, I think, is good enough for an approximation.


--
Code for the Green's method:

A=imread('C:\Documents and Settings\2006-54324\Desktop\mosesbw085-3.bmp');
[x,y]=follow(A);

lenx=length(x);
leny=length(y);

x1=zeros(lenx);
xs=lenx-1;
x1(1:xs)=x(2:lenx);
x1(lenx)=x(1);

y1=zeros(leny);
ys=leny-1;
y1(1:ys)=y(2:leny);
y1(lenx)=y(1);
                          
T=0.5.*((x.*y1)-(y.*x1));
TAR=sum(T);

 --
Acknowledgements:
Aivin, for the helpful conversations
Che, for sharing the idea that I can sum the image as another way of finding the area :)

--
Technical correctness: 5
Quality of presentation: 5
Initiative: