Monday, August 16, 2010

A9 – Morphological Operations

Predicted outcomes upon application of erosion and dilation operations:

Before using scilab to simulate the results when we apply the erosion and dilation operations, we were first asked to predict what these results would be. I used Microsoft word to illustrate my predictions by putting gridlines and drawing squares as pixels.

Here are my predictions...


Figure 1: Predictions for erosion

NOTE: The resulting image is comprised ONLY of the yellow pixels. The white pixels are only included to illustrate how much of the original image are removed.


Figure 2: Predictions for dilation

NOTE: The resulting image is the combination of the yellow and white pixels.



Outcomes upon application of erosion and dilation operators using SCILAB:

EROSION:

Figure 3: Erosion using a 2x2 ones strel


Figure 4: Erosion using a 2x1 ones strel


Figure 5: Erosion using a 1x2 ones strel



Figure 6: Erosion using a cross (3x3) strel


Figure 7: Erosion using a diagonal (0 1; 1 0) strel

NOTE: Blank figure means that no pixel remained after the erosion operation.


DILATION:

Figure 8: Dilation using a 2x2 ones strel


Figure 9: Dilation using a 2x1 ones strel


Figure 10: Dilation using a 1x2 ones strel


Figure 11: Dilation using a cross (3x3) strel


Figure 12: Dilation using a diagonal (0 1; 1 0) strel

I'm glad to see that my predictions are correct! :D

Other morphological operators:

1. Thin: performs a thinning operation on binary objects




Figure 13: objects(left), objects after thinning operation(right)

2. Skel: another thinning operation where the output object can be further pruned by thresholding

below are examples of what your object will look like after skel operation:



Figure 14: objects(left), objects after skel operation(right)

CODE:

stacksize(1000000);

o1 = zeros(11,11);
o1(4:8,4:8) = 1
//imshow(o1,[])

o2 = zeros(8,8);
o2(4,3) = 1;
o2(5,3:4) = 1;
o2(6,3:6) = 1;
//imshow(o2,[])


o3 = zeros(14,14);
o3(3:12,3:12) = 1;
o3(5:10,5:10) = 0;
//imshow(o3,[])


o4 = zeros(9,9);
o4(3:7,5) = 1;
o4(5,3:7) = 1;
//imshow(o4,[])

//Structuring elements
a = [1 1; 1 1];
b = [1; 1];
c = [1 1];
d = [0 1 0; 1 1 1; 0 1 0]
e = [0 1; 1 0]

////////////////////////////////////////////////////////////////

//erode

a1 = erode(o1, a, [1,1]);
a2 = erode(o2, a, [1,1]);
a3 = erode(o3, a, [1,1]);
a4 = erode(o4, a, [1,1]);

subplot(1, 4, 1);imshow(a1, []);
subplot(1, 4, 2);imshow(a2, []);
subplot(1, 4, 3);imshow(a3, []);
subplot(1, 4, 4);imshow(a4, []);

b1 = erode(o1, b, [1,1]);
b2 = erode(o2, b, [1,1]);
b3 = erode(o3, b, [1,1]);
b4 = erode(o4, b, [1,1]);

subplot(1, 4, 1);imshow(b1, []);
subplot(1, 4, 2);imshow(b2, []);
subplot(1, 4, 3);imshow(b3, []);
subplot(1, 4, 4);imshow(b4, []);

c1 = erode(o1, c, [1,1]);
c2 = erode(o2, c, [1,1]);
c3 = erode(o3, c, [1,1]);
c4 = erode(o4, c, [1,1]);

subplot(1, 4, 1);imshow(c1, []);
subplot(1, 4, 2);imshow(c2, []);
subplot(1, 4, 3);imshow(c3, []);
subplot(1, 4, 4);imshow(c4, []);

d1 = erode(o1, d, [2,2]);
d2 = erode(o2, d, [2,2]);
d3 = erode(o3, d, [2,2]);
d4 = erode(o4, d, [2,2]);

subplot(1, 4, 1);imshow(d1, []);
subplot(1, 4, 2);imshow(d2, []);
subplot(1, 4, 3);imshow(d3, []);
subplot(1, 4, 4);imshow(d4, []);

e1 = erode(o1, e, [2,1]);
e2 = erode(o2, e, [2,1]);
e3 = erode(o3, e, [2,1]);
e4 = erode(o4, e, [2,1]);

subplot(1, 4, 1);imshow(e1, []);
subplot(1, 4, 2);imshow(e2, []);
subplot(1, 4, 3);imshow(e3, []);
subplot(1, 4, 4);imshow(e4, []);

/////////////////////////////////////////////////////////

//dilate

a1 = dilate(o1, a, [1,1]);
a2 = dilate(o2, a, [1,1]);
a3 = dilate(o3, a, [1,1]);
a4 = dilate(o4, a, [1,1]);

subplot(1, 4, 1);imshow(a1, []);
subplot(1, 4, 2);imshow(a2, []);
subplot(1, 4, 3);imshow(a3, []);
subplot(1, 4, 4);imshow(a4, []);

b1 = dilate(o1, b, [1,1]);
b2 = dilate(o2, b, [1,1]);
b3 = dilate(o3, b, [1,1]);
b4 = dilate(o4, b, [1,1]);

subplot(1, 4, 1);imshow(b1, []);
subplot(1, 4, 2);imshow(b2, []);
subplot(1, 4, 3);imshow(b3, []);
subplot(1, 4, 4);imshow(b4, []);

c1 = dilate(o1, c, [1,1]);
c2 = dilate(o2, c, [1,1]);
c3 = dilate(o3, c, [1,1]);
c4 = dilate(o4, c, [1,1]);

subplot(1, 4, 1);imshow(c1, []);
subplot(1, 4, 2);imshow(c2, []);
subplot(1, 4, 3);imshow(c3, []);
subplot(1, 4, 4);imshow(c4, []);

d1 = dilate(o1, d, [2,2]);
d2 = dilate(o2, d, [2,2]);
d3 = dilate(o3, d, [2,2]);
d4 = dilate(o4, d, [2,2]);

subplot(1, 4, 1);imshow(d1, []);
subplot(1, 4, 2);imshow(d2, []);
subplot(1, 4, 3);imshow(d3, []);
subplot(1, 4, 4);imshow(d4, []);

e1 = dilate(o1, e, [2,1]);
e2 = dilate(o2, e, [2,1]);
e3 = dilate(o3, e, [2,1]);
e4 = dilate(o4, e, [2,1]);

subplot(1, 4, 1);imshow(e1, []);
subplot(1, 4, 2);imshow(e2, []);
subplot(1, 4, 3);imshow(e3, []);
subplot(1, 4, 4);imshow(e4, []);


I would like to give my self a grade of 10/10 for this activity since I was able to achieve the desired results.

Thanks to Joseph and Dane for helping me with this activity!

Thanks to BA for keeping me company while finishing this activity. :P

references:
1. 187 activity 9 handout
2. http://homepages.inf.ed.ac.uk/rbf/HIPR2/skeleton.htm


Sunday, August 8, 2010

A8.D - Canvas Weave Modeling and Removal

For this part of the activity we want to enhance this patch of a painting(from the UP Vargas Museum collection) by removing the canvas weave pattern such that only the paint texture is seen.

Given the painting patch...


Figure 1: Patch of painting
Take its FT...

Figure 2: FT

Design a filter that would get rid of those dirac deltas we see in the FT...(remember that the FT of addition of sine patterns are dirac deltas... :D)


Figure 3: Filter

How do we know that we are choosing the right areas to be filtered you might ask...well let's take the FT of the filter to be sure...


Figure 4: FT of filter

I would say that the FT somehow resembles that of the canvas weave pattern so it means that we are on the right track. :D

Multiply the FT of the patch of painting to the filter...


Figure 5: Image of patch of painting multiplied by filter

Resulting image...no more canvas weave pattern! or atleast reduced..hehe.

Figure 6: Resulting image

CODE: same as in act.8.B with filter input being figure 3.

A8.C - Lunar Landing Scanned Pictures : Line removal

Yey! for another exercise that makes use of what we have learned about FTs.

Basically, we want to enhance this image of the moon's surface by removing the lines that are not supposed to be part of the image.

So given this image of the moon's surface...


Figure 1: Moon's surface
from: http://www.lpi.usra.edu/lunar/missions/apollo/apollo_11/images

we take its FT...


Figure 2: FT of moon's surface image

-we know that when we inverse a crossed-shaped FT, this would results to square patterns. Therefore this corresponds to the lines that we want to remove. From this...

...a filter is designed as...


Figure 3: Filter

To select only the areas we want to retain, we multiply the FT with the filter that we designed...


Figure 4: FT multiplied by filter

Taking the inverse of figure 4 results to...


Figure 5: Enhanced image
...which is an enhanced image of the moon's surface(without the lines)...yey!!! :D

CODE: same as activity A8.B with the filter input being image illustrated by figure 3.