Wednesday, October 8, 2008

A19 - Probabilistic Classification

I used the test image data in Activity 18.
group 1 - one peso coins
group 2 - 25 centavo coins

x - features of all data

66511 0.926294
66473 0.949915
66511 0.777889
45555 1.163125
48126 0.777889
47958 0.930314

y - group of the object of all data.
y = [1;1;1;2;2;2]

x1 - group 1
x1 = [66511 0.926294;66473 0.949915; 66511 0.777889];

x2 - group 2
x2 = [45555 1.163125; 48126 0.777889; 47958 0.930314];

u1 - mean of features of group 1
66498.333
0.8846993

u2 - mean of features of group 2
47213.
0.9571093

u - mean features of all
56855.667
0.9209043

x0 - mean corrected data

Therefore,
x01 x02
9655.333 -11300.7
0.00539 0.242221
9617.333 -8729.67
0.029011 -0.14302
9655.333 -8897.67
-0.14302 0.00941


c1 and c2 are covariance of each group.
c1 =
92981341 -349.939
-349.939 0.007108

c2 =
94360206 -524.168
-524.168 0.026404


C - group Covariance
C =
93670774 -437.053
-437.053 0.016756

We then find the inverse of C
InvC =
1.215D-08 0.000317
0.000317 67.94902

f1 and f2 are the Linear Discriminat Functions
f1 f2
74.81613 72.76803
76.69272 74.62444
62.76609 60.89518
71.22988 73.33025
42.74908 44.76578
54.94263 56.81285


We will use a test image( a 25 centavo coin). Let's pretend that we did not know what it is.
T = [48392 0.7848263]

The Linear Discriminant Functions are
f1T = 43.601981
f2T = 45.554149

From the graph, it shows that the test function is close to the 25 centavos. So I think our prediction is right. :)

Acknowledgments:
Linear Discriminant Analysis Lecture

Grade: 10/10 because I think that my result is right.

Thursday, September 18, 2008

A18 - Pattern Recognition

Pattern recognition is the act of taking in raw data and taking an action based on the category of the data.(Wikipedia)

For this activity, the goal is to classify images of one peso coins and 25 centavo coins using features extracted from the training images. I have three training images from both the one-peso coin and 25-centavo coin.


The features I extracted from the images are their area and RED-GREEN contrast. To find the area, I binarize the image and to pixel counting.

I assigned 1 for piso and 2 for 25 centavos.

The result of pattern recognition is:
There is a 100% accuracy in determing the right coin.

Acknowledgments:

Aiyin, April - for the help.

Grade: 10/10 although I had difficulty in making this activity, I think I made a correct activity.

Thursday, September 4, 2008

A17 – Basic Video Processing

This activity is all about video processing.

Video is a sequence of still images representing scenes in motion. Video processing is the use of different image processing techniques for each still images in a video.

In our video, we are concern with the diffusion of ink in water. Diffusion is the natural process of intermingling of the molecules of two substances. We are concerned with the area of the ink that is diffused in water.

Using the images below,


image 1
Finding the threshold of the image, using the image below

image 2
After finding the threshold, we can change the images to binary.

image 3
Our region of interest is the ink in the middle of the water. Finding the area of the ROI for each images by pixel counting. We can find the plot below
image 4
We will compare image 4 with the image below.
image 5
We will consider image 5 as the theoretical values for area. This plot is from 'Ink diffusion in water' by Lee S. et. al, 2004.

We can see that there is error in the area of the diffusion of ink in water. It is because of the other part of the images that is not part of the ROI but is still considered in pixel counting.

//code//
t=108/255;
c=[];
for i=1:9
im=imread('vid000'+string(i)+'.jpg');
imb=im2bw(im, t);
c(i)=sum(abs(1-imb));
end
for i=10:99
im=imread('vid00'+string(i)+'.jpg');
imb=im2bw(im, t);
c(i)=sum(abs(1-imb));
end
plot(c);

Acknowledgements:
Instru Lab- for the place
Gerold - for the code
Benj and Billy - for being my groupmates.. :)
http://mitgcm.org/eh3/Tracer_work/papers/ejp4_2_020.pdf


Grade: 10/10
because I think I did what is needed to do. :)

Tuesday, September 2, 2008

A16 – Color Image Segmentation

In image segmentation, a region of interest (ROI) is picked out from the rest of the image such that further processing can be done on it. Selection rules are based on features unique to the ROI.

normalized chromaticity coordinates
- represent color space not by the RGB but by one that can separate brightness and chromaticity (pure color) information

Per pixel, let I = R+G+B. Then the normalized chromaticity coordinates are

We note that r+g+b = 1 which implies r,g and b can only have values between 1 and 0 and b is dependent on r and g since b = 1-r-g.from R G B, the color space has been transformed to r g I where chromatic information is in r and g while brightness information is in I.
Parametric vs Non-Parametric Probability Distribution Estimation

Segmentation based on color can be performed by determining the probability that a pixel belongs to a color distribution of interest.

The probability that a pixel with chromaticity r belongs to the ROI is then
Histogram backprojection

Histogram backprojection is one such technique where based on the color histogram, a pixel location is given a value equal to its histogram value in chromaticity space.

Using the image:
cropping an the image:
Thus, we will use the yellow ball as the ROI.

We will use to techniques.
Parametric:

Non-Parametric

Acknowledgements:

Mark Leo - for the help.

Grade:
10/10
- because I think I did what is needed to do. And I think the image is well segmented.

Thursday, August 28, 2008

A15 – Color Image Processing

A colored digital image is an array of pixels each having red, green and blue light overlaid in various proportions, Per pixel, the color captured by a digital color camera is an integral of the product of the spectral power distribution of the incident light source S(l), the surface reflectance r(l) and the spectral sensitivity of the camera h(l).

White Balancing
This setting allows the user to select the white balancing constants appropriate for the capturing conditions.

White Balance Settings
Daylight - not all cameras have this setting because it sets things as fairly ‘normal’ white balance settings.
Incandescent/ Tungsten - this mode is usually symbolized with a little bulb and is for shooting indoors, especially under tungsten (incandescent) lighting (such as bulb lighting). It generally cools down the colors in photos.
Flourescent - this compensates for the ‘cool’ light of fluorescent light and will warm up your shots.
Cloudy - this setting generally warms things up a touch more than ‘daylight’ mode.

There are two popular algorithms of achieving automatic white balance. The first is Reference White Algorithm and the second is the Gray World Algorithm.

In the Reference White Algorithm, you capture an image using an unbalanced camera and use the RGB values of a known white object as the divider.

In the Gray World Algorithm, it is assumed that the average color of the world is gray.

Using a cloudy white balance, the color of the original image is yellowish. Using reference white, the image became whiter. And when we use gray world, the image is also whiter than the original but it is darker than the image using reference white.

Using an incandescent white balance, the image is bluish in color. Using reference white, the image became whiter and brighter than the original. Using gray world, the image is darker but whiter than the original.

Using daylight settings, the image became whiter in the reference white than the gray world. It also becomes brighter using reference white.

Using flourescent white balance. The image become white using both reference white and gray world. But i think it is brighter using gray world.
Using incandescent white balance, the image is bluish. After implementing reference white, the color of the leaves became green and the paper became white. After implementing gray world, the leaves became green, and the paper is close to gray.

I think that the reference white algorith is better than the gray world because of the results in the images.

-- code --
//white balance

stacksize(20000000);
image = imread('rix.jpg');
im = imread('rix-white.jpg');

RW = mean(im(:,:,1));
GW = mean(im(:,:,2));
BW = mean(im(:,:,3));

new = zeros(image);
new(:,:,1) = image(:,:,1)./RW;
new(:,:,2) = image(:,:,2)./GW;
new(:,:,3) = image(:,:,3)./BW;

maxall = max(max(max(new)));
newim = new./maxall;

imwrite(newim,'rix-new-white.jpg');

//gray world

stacksize(20000000);
image = imread('rix1.jpg'C/3B
new = zeros(image);

new(:,:,1) = image(:,:,1)./mean(image(:,:,1));
new(:,:,2) = image(:,:,2)./mean(image(:,:,2));
new(:,:,3) = image(:,:,3)./mean(image(:,:,3));

maxall = max(max(max(new)));
newim = new./maxall;

imwrite(newim,'rix1-new-gray.jpg');

Acknowledgements
Activity 15 manual
http://digital-photography-school.com/blog/introduction-to-white-balance/

Benj - for the help with the codes

Grade:
10/10
- because I think I implemented the algorithms well. The color of the images were improved. :)

Tuesday, August 26, 2008

A14 – Stereometry

Objective: To reconstruct a 3D object.

Stereo imaging is the technique we will use in this experiment and it is inspired by how our two eyes allow us to discriminate depth.

Thursday, August 7, 2008

A13 – Photometric Stereo

We can estimate the shape of the surface by capturing multiple images of the surface with the sources at different locations. The information about the surface will be coded in the shadings obtained from the images.

Let there be N sources in 3-d space. We can define a matrix
where each row is a source, each column is the x,y,z component of the source.

Procedure:
1. Load the matlab file photos.mat which contains 4 images I1, I2, I3,
and I4. The images are synthetic spherical surfaces illuminated by a far
away point source located respectively at
V1 = {0.085832, 0.17365, 0.98106}
V2 = {0.085832, -0.17365, 0.98106}
V3 = {0.17365, 0, 0.98481}
V4 = {0.16318, -0.34202, 0.92542}
Use loadmatfile in Scilab.

Sperical surfaces
2. Compute the surface normals using Equation 10 and 11.

Equation 10
To get the normal vector we simplify normalize g by its length
Equation 11

3. From the surface normals compute the elevation z=f(u,v) and display a 3D plot of the object shape.
Once the surface normals (nx, ny, nz) are estimated using photometric stereo, they are related to the partial derivative of f as
The surface elevation z at point (u,v) is given by f(u,v) and is evaluated by a line integral

This is the resulting image.
--
codes
loadmatfile('Photos.mat',['I1','I2','I3', 'I4']);
scf(1)
subplot(141);imshow(I1,[]);
subplot(142);imshow(I2,[]);
subplot(143);imshow(I3,[]);
subplot(144);imshow(I4,[]);

V = [0.085832 0.17365 0.98106; 0.085832 -0.17365 0.98106; 0.17365 0 0.98481; 0.16318 -0.34202 0.92542];
I = [I1(:)';I2(:)';I3(:)';I4(:)'];

g = inv(V'*V)*V'*I;
[A,B] = size(g);
for i=1:A;
for j=1:B;
c(j)=sqrt((g(1,j)**2)+(g(2,j)**2)+(g(3,j)**2));
c = c+ 0.000000001;
end
end

n(1,:) = g(1,:)./c';
n(2,:) = g(2,:)./c';
n(3,:) = g(3,:)./c';


dfx= -n(1,:)./(n(3,:)+0.000000001);
dfy= -n(2,:)./(n(3,:)+0.000000001);

imx = matrix(dfx,128,128);
imy = matrix(dfy,128,128);

fx =cumsum(imx,2);
fy =cumsum(imy,1);

Image = fx+fy;

mesh(Image)

Acknowledgements:
April, Lei, Mark Leo and Aiyin
- for helping me

Grade
10/10
-since I was able to find the correct 3D plot.

Thursday, July 31, 2008

A12 – Correcting Geometric Distortions

There are two types of geometric distortion.
1. pincushion - the image seems pinched in the middle and expanded in the boundaries.
2. barrel - the image seems bloated in the middle and pinched at the sides.

For this activity, we will use bilinear interpolation. "the graylevel v at an arbitrary location (x , y)
in the distorted image can be found using v (x , y )=ax+by+c xy+d.

We used a distored capiz window shown below,
I cropped the image
and using bilinear interpolation, the result is

Acknowledgements:

Activity 12 manual

Grade:
9/10 - because I think that even though I find an undistorted image. It is far from what is expected.

Wednesday, July 30, 2008

A11 – Camera Calibration

An image is a projection of brightness values from surfaces existing in 3D world space to 2D sensor space. The aim of this activity is to be able to model the physical processes involved in the geometric aspects of image formation.


Procedure:
1.Mount a 3D calibration checkerboard (to be provided) onto a surface and steady your camera with a tripod. Take an image of the checkerboard.
2. Pick an origin and a right-handed coordinate system in the grid and measure coordinates of around 20 to 25 corners of the squares of the checkerboard pattern.

I picked 23 corners.
3.From the image of the same points, find their [xi,yi] coordinates in image space. Use locate to get the coordinates in the image figure window using a mouse.

we have two coodinates since the image is flat. We will have two equations.
The o subscript corresponds to the object and i subscript corresponds to image.
finding the coordinates of selected points.

4. From Lecture 2, rederive Equation 13 this time with the z or Z axis as the camera axis, and x,y as the planar coordinates. Using all the points you've selected, set up the left and right-hand side matrices in Equation 13. Compute the elements of the matrix A using Equation 15.

Equation 13.
Thus,
5. To verify if you got the calibration correctly, predict the image coordinates of some cornerpoints of the checkerboard which were not used in the calibration. Overlay the predicted cornerpoints on the image. Comment on the accuracy of your prediction.
I found out that the average error for yi is 0.016708 and for zi is 0.0045 . And I think it this is accurate.

Using points that are not used in finding a
average error:
yi = 0.013684
zi = 0.010258

I think this is still acccurate.

--------------------------------------------------------------------
codes

stacksize(20000000);
img = imread('rix.jpg');
imshow(img);
x = locate(23);

yi = [326.66667 357.77778 424.66667 300.22222b 356.22222 393.55556 497.77778 508.66667 491.55556 150.88889 217.77778 113.55556 183.55556 118.22222 185.11111 88.666667 301.77778 241.11111 32.666667 28 147.77778 336 326.66667];
zi = [340.44444 184.88889 251.77778 161.55556 111.77778 500.66667 328 550.44444 158.44444 331.11111 178.66667 461.77778 373.11111 194.22222 505.33333 58.888889 419.77778 295.33333 366.88889 564.44444 552 534.88889 265.77778];
xo = [0 0 0 0 0 0 0 0 0 5 3 6 4 6 4 7 0 2 8 8 5 0 0];
yo = [1 2 4 1 2 3 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 1 1];
zo = [7 3 5 2 1 11 7 12 3 7 3 10 8 4 11 1 9 6 8 12 12 12 5];

//finding a
for i = 1:length(xo)
O((2*i)+1) = [xo(i) yo(i) zo(i) 1 0 0 0 0 -(yi(i)*xo(i)) -(yi(i)*yo(i)) -(yi(i)*zo(i))];
O((2*i)+2) = [0 0 0 0 xo(i) yo(i) zo(i) 1 -(zi(i)*xo(i)) -(zi(i)*yo(i)) -(zi(i)*zo(i))];
I((2*i)+1) = yi(i);
I((2*i)+2) = zi(i);
end

a = inv(O'*O)*O'*I;

//prediction
for j = 1:length(xo)
yinew(j) = ((a(1,1)*xo(j))+(a(1,2)*yo(j))+(a(1,3)*zo(j))+a(1,4))/((a(3,1)*xo(j))+(a(3,2)*yo(j))+(a(3,3)*zo(j))+1);
zinew(j) = ((a(2,1)*xo(j))+(a(2,2)*yo(j))+(a(2,3)*zo(j))+a(2,4))/((a(3,1)*xo(j))+(a(3,2)*yo(j))+(a(3,3)*zo(j))+1);
end

Acknowledgements:
Activity 11 manual.

Beth, Aiyin, Lei
- for answering my questions

Grade :
10/10 because I think that my data is accurate and I did what the activity asked. :)

Tuesday, July 22, 2008

A10 – Preprocessing Handwritten Text

In this activity, we will try to extract handwritten text from an imaged document with lines. In handwriting recognition, individual examples of letters must be extracted.

Procedure.
1. Download one of the images DSC00469.JPG or Untitled_0001.jpg.
2. Crop a portion of the image with handwritten text within lines in the form.

image 1
I cropped image 1 to
image 2 - cropped image

3. Remove the lines using image processing techniques.
To remove the horizontal lines we will use the filter below.

image 3 - filter

This filter is based on the fft of the cropped image which is shown in figure 4.

image 4 - fft of cropped image

Then we will filter the image by convolution,
image 5 - filtered image

4.Binarize the handwriting, clean the image and process such that each handwritten letter is one pixel thick.
image 6 - binarized image

image 7 - image after using opening operator

5. Use bwlabel to label each letter. Comment on the quality of your preprocessing.
image 8 - labeled image

code used:

im=imread('image.jpg');
img=imread('filter.jpg');
im = im2gray(im);
imf = im2gray(img);
ff1=fft2(im);
ff2=fftshift(imf);
imft=ff1.*ff2;
imshow(ff1);


//filtering the image
a=real(fft2(imft));
scf(1)
imshow(a,[]);

//binarize the image
b=im2bw(a, 127/255);//threshold from GIMP
c=1-b;
scf(2);
imshow(c,[]);

// structuring element
SE = ones(2,2)

//opening operation
d=erode(c,SE);
e=dilate(d,SE)
scf(3);
imshow(e,[]);

//label the image
f=bwlabel(e);
scf(4);
imshow(f,[]);


From the labeled image, the processed image is not that clear. :(

Acknowledgements:
Ed
- for the help

Grade:
10/10
- because I did my best and I was able to use what I learned in the activities before.


 
template by suckmylolly.com