Winter 2013 EECS 332 Digital Image Analysis Machine Problem 1 Connect Component Analysis

Size: px
Start display at page:

Download "Winter 2013 EECS 332 Digital Image Analysis Machine Problem 1 Connect Component Analysis"

Transcription

1 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 1 Connect Component Analysis Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 22 January Introduction In this report, I applied the sequential algorithm for connect component labelling which was introduced in class on January 15th, There are four programs: CCL.m, E table.m, size filter.m, and show result.m. 2 Algorithm Description In CCL.m, I realized the sequential solution which was described on slide 9 and 10, Lecture Binary Image Analysis II. Basically I followed the pseudocodes provided by professor, scanned the image from left to right and from top to bottom. There is one trick which I used. Suppose that the size of image is m n, then I add one zero-column to the left and one zero-row on the top to expand the size of image to (m + 1) (n + 1), in the end, I transferred the image to the original size. This trick is necessary when any component touched the edges of the image. In E table.m, I used an array to store the equivalent table. It is the simplest way to realize the equivalent table as professor suggested. If neither the index of upper pixel nor the index of left pixel has been changed, we only need to make these two indices equal. Otherwise, we need to go over the whole equivalent table to update all indices. In size filter.m, when the area of one region is less than a pre-determined parameter, we treat this area as noises, and change this area to background. In show result.m, I showed the result of component detection by using a grey figure. 1

2 3 Results analysis I applied my program onto three test file, with and without size filter. The results are presented in Figure 1 and 2. I also drew one graph to test the algorithm, which is shown in Figure 3. Figure 1: test.bmp and face.bmp Figure 2: gun.bmp (Left: without filter, Right: with filter, threshold = 50) 4 MATLAB codes 1 function MP1 main 2 % Jiangtao Gou 3 % f i l e n a m e = f a c e ; 2

3 Figure 3: My own test image file 5 f i l e n a m e = t e s t ; 6 f i l e n a m e = gun ; 7 f i l e n a m e = china ; 8 img = imread ( [ filename,.bmp ] ) ; % For gun. bmp, use s m a l l e s t s i z e = % 10 [ label i m g, num ] = CCL( img ) ; 11 % 12 s m a l l e s t s i z e = 5 0 ; 13 [ label i m g, num ] = s i z e f i l t e r ( label img, num, s m a l l e s t s i z e ) ; 14 % 15 s h o w r e s u l t ( l a b e l img, num, f i l e n a m e ) ; 1 function [ l a bel i m g, num ] = CCL( img ) 2 % % Jiangtao Gou 4 i m g s i z e = size ( img ) ; 5 temp img = zeros ( i m g s i z e + [ 1, 1 ] ) ; 6 temp img ( 2 : 1 : ( i m g s i z e ( 1, 1 ) +1), 2 : 1 : ( i m g s i z e ( 1, 2 ) +1) ) = img ; % Add one zero row on the top and one zero colum on the l e f t. 7 temp label img = zeros ( i m g s i z e + [ 1, 1 ] ) ; 8 l a b e l i m g = zeros ( i m g s i z e ) ; 9 l a b e l v e c s i z e = 1000; 3

4 10 l a b e l v e c = 1 : 1 : l a b e l v e c s i z e ; 11 num = 0 ; 12 l a b e l = 0 ; 13 for u = 2 : 1 : ( i m g s i z e ( 1, 1 ) +1) 14 for v = 2 : 1 : ( i m g s i z e ( 1, 2 ) +1) 15 i f temp img (u, v ) == 1 16 u p p e r l a b e l = temp label img (u 1,v ) ; % Upper l a b e l 17 l e f t l a b e l = temp label img (u, v 1) ; % L e f t l a b e l 18 i f ( u p p e r l a b e l == l e f t l a b e l ) && ( u p p e r l a b e l = 0) && ( l e f t l a b e l = 0) % The same l a b e l 19 temp label img (u, v ) = u p p e r l a b e l ; 20 e l s e i f ( u p p e r l a b e l = l e f t l a b e l ) && ( u p p e r l a b e l && l e f t l a b e l ) % E i t h e r i s 0 21 temp label img (u, v ) = max( u p p e r l a b e l, l e f t l a b e l ) ; 22 e l s e i f ( u p p e r l a b e l = l e f t l a b e l ) && ( u p p e r l a b e l > 0) && ( l e f t l a b e l > 0) % Both 23 temp label img (u, v ) = min( u p p e r l a b e l, l e f t l a b e l ) ; 24 l a b e l v e c = E table ( l a b e l, l a b e l v e c, u p p e r l a b e l, l e f t l a b e l ) ; 25 else 26 l a b e l = l a b e l + 1 ; 27 temp label img (u, v ) = l a b e l ; 28 i f l a b e l > l a b e l v e c s i z e 29 error ( The S i z e o f Equivalent Table i s NOT big enough. Please I n c r e a s e i t. ) ; 30 end 31 end 32 end 33 end 34 end 35 l a b e l i m g = temp label img ( 2 : 1 : ( i m g s i z e ( 1, 1 ) +1), 2 : 1 : ( i m g s i z e ( 1, 2 ) +1) ) ; 36 l a b e l v e c = l a b e l v e c ( 1 : 1 : l a b e l ) ; 37 u n i q u e l a b e l = unique ( l a b e l v e c ) ; 38 for u = 1 : 1 : i m g s i z e ( 1, 1 ) 39 for v = 1 : 1 : i m g s i z e ( 1, 2 ) 40 i f img (u, v ) == 1 41 l a b e l i m g (u, v ) = l a b e l v e c ( l a b e l i m g (u, v ) ) ; % Merger Regions 42 l a b e l i m g (u, v ) = find ( u n i q u e l a b e l == l a b e l i m g (u, v ) ) ; % Use 1, 2, 3,... as the region numbers. 43 end 44 end 4

5 45 end 46 num = length ( u n i q u e l a b e l ) ; 1 function l a b e l v e c = E table ( l a b e l, l a b e l v e c, L u, L l ) 2 % % Jiangtao Gou 4 min L = min( l a b e l v e c ( L u ), l a b e l v e c ( L l ) ) ; 5 i f ( l a b e l v e c ( L u ) == L u ) && ( l a b e l v e c ( L l ) == L l ) % Neither o f i n d e x e s has been changed 6 l a b e l v e c ( L u ) = min L ; 7 l a b e l v e c ( L l ) = min L ; 8 else 9 for i =1:1: l a b e l 10 i f ( l a b e l v e c ( i ) == l a b e l v e c ( L u ) ) ( l a b e l v e c ( i ) == l a b e l v e c ( L l ) ) 11 l a b e l v e c ( i ) = min L ; 12 end 13 end 14 end 1 function [ l a bel i m g, num ] = s i z e f i l t e r ( label img, num, s m a l l e s t s i z e ) 2 % % Jiangtao Gou 4 i m g s i z e = size ( l a b e l i m g ) ; 5 p i x e l p o i n t c o u n t e r = zeros ( 1,num) ; 6 for i =1:1:num 7 p i x e l p o i n t c o u n t e r ( i ) = length ( find ( l a b e l i m g == i ) ) ; 8 end 9 i f sum( p i x e l p o i n t c o u n t e r < s m a l l e s t s i z e ) 10 n o t n o i s e l a b e l = ( p i x e l p o i n t c o u n t e r >= s m a l l e s t s i z e ) ; 11 n o t n o i s e l a b e l l o c = find ( n o t n o i s e l a b e l > 0) ; 12 for u = 1 : 1 : i m g s i z e ( 1, 1 ) 13 for v = 1 : 1 : i m g s i z e ( 1, 2 ) 14 i f l a b e l i m g (u, v ) > 0 15 i f n o t n o i s e l a b e l ( l a b e l i m g (u, v ) ) == 0 16 l a b e l i m g (u, v ) = 0 ; 17 else 18 l a b e l i m g (u, v ) = find ( n o t n o i s e l a b e l l o c == l a b e l i m g (u, v ) ) ; 19 end 20 end 21 end 22 end 23 else 5

6 24 n o t n o i s e l a b e l l o c = ones ( size ( p i x e l p o i n t c o u n t e r ) ) ; 25 end 26 num = length ( n o t n o i s e l a b e l l o c ) ; 1 function s h o w r e s u l t ( l a b el img, num, f i l e n a m e ) 2 % % Jiangtao Gou 4 i m g s i z e = size ( l a b e l i m g ) ; 5 gray img = l a b e l i m g ; 6 for u = 1 : 1 : i m g s i z e ( 1, 1 ) 7 for v = 1 : 1 : i m g s i z e ( 1, 2 ) 8 i f l a b e l i m g (u, v ) > 0 9 gray img (u, v ) = round( l a b e l i m g (u, v ) /num 255) ; 10 end 11 end 12 end 13 imshow ( gray img, [ ] ) ; 14 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 15 picname = [ mp1, filename,. eps ] ; 16 saveas ( gcf, picname, epsc ) ; 17 eps2pdf ( picname ) ; 6

7 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 2 Morphological Operators Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 24 January Introduction In this report, I realized some basic morphological operators which were introduction on January 17th. By following slides Binary Image Analysis III by Prof Wu, and Jain, Kasturi and Schunck s Machine Vision (1995), page 61-69, the following morphological operators are defined below. Erosion A B = {p B p A}. (1) Dilation Opening Closing Boundary A B = bi BA bi. (2) A B = (A B) B. (3) A B = (A B) B. (4) β B (A) = A (A B). (5) In order to get clear boundary, I tried to combine those morphological operators above. In the end, this one below worked well, and I called it Clear Boundary, as shown below. Clear Boundary γ B (A) = (A B) (A B). (6) Meanwhile, in order to get rid of the noise, I used the techniques in Machine Problem 1, where I labelled different component, and treated the small components as noise. 1

8 2 Algorithm Description For erosion and dilation, I went through the whole picture, and decided the output image. For opening, closing, boundary, and clear boundary, I simply used the combination of erosion and dilation. In order to get rid of the noise, I ran the size filter at first, then I ran clear boundary function. The threshold need to be specified ahead. 3 Results analysis First, I tried to apply a 3 by 3 square structure element (Figure 1) on gun.bmp. Figure 1: Structure Element: 3 by 3 Square As shown in Figure 2, function clear boundary works well, except some noises. By using size filter, we can achieve better boundary, as shown in Figure 3. Second, I tried to apply a 5 by 5 square structure element on gun.bmp. As shown in Figure 5, function clear boundary works well, except some noises. By using size filter, we can achieve better boundary, as shown in Figure 6. Third, I tried to apply a 3 by 3 square structure element (Figure 1) on palm.bmp. As shown in Figure 7, function clear boundary works well, except some noises. It looks that the boundary in Figure 7 for Palm was not very clear. We will see by change the structure element, we will get a clear boundary. 2

9 Figure 2: Structure Element: 3 by 3 Square. Erosion (top left), Dilation (top right), Opening (middle left), Closing (middle right), Boundary (bottom left), Clear Boundary (bottom right) 3

10 Figure 3: Structure Element: 3 by 3 Square. Clear Boundary after Filtering. Threshold = 9 (left), Threshold = 100 (right) Figure 4: Structure Element: 5 by 5 Square 4

11 Figure 5: Structure Element: 5 by 5 Square. Erosion (top left), Dilation (top right), Opening (middle left), Closing (middle right), Boundary (bottom left), Clear Boundary (bottom right) 5

12 Figure 6: Structure Element: 5 by 5 Square. Clear Boundary after Filtering. Threshold = 9 (left), Threshold = 100 (right) 8. By using size filter, we can achieve better boundary, as shown in Figure Fourth, I tried to apply a 5 by 9 rectangle structure element on palm.bmp. As shown in Figure 10, function clear boundary works well, except some noises. By using size filter, we can achieve better boundary, as shown in Figure MATLAB codes 1 function MP2 main 2 % Jiangtao Gou 3 % f i l e n a m e = palm ; 5 img in = imread ( [ filename,.bmp ] ) ; 6 SE = ones ( 5, 9 ) ; 7 % SE = [ 0, 1, 0 ; 1, 1, 1 ; 0, 0, 0 ] ; 8 % 9 img out = Erosion ( img in, SE) ; 10 imshow ( img out, [ 0 1 ] ) ; 11 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 12 picname = [ e r o s i o n, filename,. eps ] ; 13 saveas ( gcf, picname, epsc ) ; 14 eps2pdf ( picname ) ; 6

13 Figure 7: Structure Element: 3 by 3 Square. Erosion (top left), Dilation (top right), Opening (middle left), Closing (middle right), Boundary (bottom left), Clear Boundary (bottom right) 7

14 Figure 8: Structure Element: 3 by 3 Square. Clear Boundary after Filtering. Threshold = 5 (left), Threshold = 10 (right) Figure 9: Structure Element: 5 by 9 rectangle 8

15 Figure 10: Structure Element: 5 by 9 rectangle. Erosion (top left), Dilation (top right), Opening (middle left), Closing (middle right), Boundary (bottom left), Clear Boundary (bottom right) 9

16 Figure 11: Structure Element: 5 by 9 rectangle. Clear Boundary after Filtering. Threshold = % 16 img out = D i l a t i o n ( img in, SE) ; 17 imshow ( img out, [ 0 1 ] ) ; 18 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 19 picname = [ d i l a t i o n, filename,. eps ] ; 20 saveas ( gcf, picname, epsc ) ; 21 eps2pdf ( picname ) ; 22 % 23 img out = Opening ( img in, SE) ; 24 imshow ( img out, [ 0 1 ] ) ; 25 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 26 picname = [ opening, filename,. eps ] ; 27 saveas ( gcf, picname, epsc ) ; 28 eps2pdf ( picname ) ; 29 % 30 img out = Closing ( img in, SE) ; 31 imshow ( img out, [ 0 1 ] ) ; 32 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 33 picname = [ c l o s i n g, filename,. eps ] ; 34 saveas ( gcf, picname, epsc ) ; 35 eps2pdf ( picname ) ; 36 % 37 img out = Boundary ( img in, SE) ; 38 imshow ( img out, [ 0 1 ] ) ; 39 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 40 picname = [ boundary, filename,. eps ] ; 41 saveas ( gcf, picname, epsc ) ; 10

17 42 eps2pdf ( picname ) ; 43 % 44 img temp = D i l a t i o n ( img in, SE) ; 45 img out = Boundary ( img temp, SE) ; 46 imshow ( img out, [ 0 1 ] ) ; 47 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 48 picname = [ clearboundary, filename,. eps ] ; 49 saveas ( gcf, picname, epsc ) ; 50 eps2pdf ( picname ) ; 51 % 52 % F i l t e r i n g at f i r s t 53 img = imread ( [ filename,.bmp ] ) ; % For gun. bmp, use s m a l l e s t s i z e = [ label i m g, num ] = CCL( img ) ; 55 s m a l l e s t s i z e = 1 00; 56 [ label i m g, num ] = s i z e f i l t e r ( label img, num, s m a l l e s t s i z e ) ; 57 s i z e i m g = size ( l a b e l i m g ) ; 58 img in = l a b e l i m g 59 for i = 1 : 1 : s i z e i m g ( 1, 1 ) 60 for j = 1 : 1 : s i z e i m g ( 1, 2 ) 61 i f l a b e l i m g ( i, j ) > 0 62 img in ( i, j ) = 1 ; 63 end 64 end 65 end 66 img temp = D i l a t i o n ( img in, SE) ; 67 img out = Boundary ( img temp, SE) ; 68 imshow ( img out, [ 0 1 ] ) ; 69 set ( gcf, p a p e r s i z e, [ 4 4 ] ) ; 70 picname = [ f i l t e r B o u n d a r y, filename,. eps ] ; 71 saveas ( gcf, picname, epsc ) ; 72 eps2pdf ( picname ) ; 1 function img out = Erosion ( img in, SE) 2 % Note : SEs s i d e l e n g t h s should be odd numbers, e. g., 3by3, 1by3, 5 by % Jiangtao Gou 4 % s i z e S E = size (SE) ; 6 extenderr = ( s i z e S E ( 1, 2 ) 1) / 2 ; 7 extenderc = ( s i z e S E ( 1, 1 ) 1) / 2 ; 8 s i z e i m g = size ( img in ) ; 9 img out = zeros ( size ( img in ) ) ; 10 for i = ( extenderc +1) : 1 : ( s i z e i m g ( 1, 1 ) extenderc ) 11 for j = ( extenderr+1) : 1 : ( s i z e i m g ( 1, 2 ) extenderr ) 11

18 12 i f sum(sum( img in ( ( i extenderc ) : 1 : ( i+extenderc ), ( j extenderr ) : 1 : ( j+extenderr ) ). SE) ) == sum(sum(se) ) 13 img out ( i, j ) = 1 ; 14 else 15 img out ( i, j ) = 0 ; 16 end 17 end 18 end 19 % Test data 20 % img in = [ 0, 0, 1, 0, 0 ; 0, 1, 1, 1, 0 ; 0, 0, 1, 0, 0 ; 0, 1, 1, 1, 1 ; 0, 0, 0, 0, 0 ] ; 21 % SE = [ 1, 1, 1 ] ; 1 function img out = D i l a t i o n ( img in, SE) 2 % Note : SEs s i d e l e n g t h s should be odd numbers, e. g., 3by3, 1by3, 5 by % Jiangtao Gou 4 % s i z e S E = size (SE) ; 6 extenderr = ( s i z e S E ( 1, 2 ) 1) / 2 ; 7 extenderc = ( s i z e S E ( 1, 1 ) 1) / 2 ; 8 s i z e i m g = size ( img in ) ; 9 img out temp = zeros ( size ( img in ) +[2 extenderc, 2 extenderr ] ) ; 10 for i = ( extenderc +1) : 1 : ( s i z e i m g ( 1, 1 )+extenderc ) 11 for j = ( extenderr+1) : 1 : ( s i z e i m g ( 1, 2 )+extenderr ) 12 i f img in ( i extenderc, j extenderr ) == 1 13 for k1 = 1 : 1 : s i z e S E ( 1, 1 ) 14 for k2 = 1 : 1 : s i z e S E ( 1, 2 ) 15 i f SE( k1, k2 ) == 1 16 img out temp ( i+k1 extenderc 1, j+k2 extenderr 1) = 1 ; 17 end 18 end 19 end 20 end 21 end 22 end 23 img out = img out temp ( ( extenderc +1) : 1 : ( s i z e i m g ( 1, 1 )+extenderc ), ( extenderr+1) : 1 : ( s i z e i m g ( 1, 2 )+extenderr ) ) ; 1 function img out = Opening ( img in, SE) 2 % Note : SEs s i d e l e n g t h s should be odd numbers 3 % Jiangtao Gou 4 % img temp = Erosion ( img in, SE) ; 6 img out = D i l a t i o n ( img temp, SE) ; 12

19 1 function img out = Closing ( img in, SE) 2 % Note : SEs s i d e l e n g t h s should be odd numbers 3 % Jiangtao Gou 4 % img temp = D i l a t i o n ( img in, SE) ; 6 img out = Erosion ( img temp, SE) ; 1 function img out = Boundary ( img in, SE) 2 % Note : SEs s i d e l e n g t h s should be odd numbers 3 % Jiangtao Gou 4 % img temp = Erosion ( img in, SE) ; 6 img out = img in img temp ; 13

20 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 3 Histogram Techniques Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 27 January Introduction In this report, I implied the histogram equalization and the lighting correction to adjust the gray scale of pictures, and made it easy to be distinguished by human eyes. Histogram equalization is a technique to stretch the histogram of the pixels grayscale, and make the histogram as uniform as possible. In statistics, when a p-value is used as a test statistic for a simple null hypothesis, then for any continuously distributed test statistic, the p-value is uniformly distributed between 0 and 1 if the null hypothesis is true. Similarly, histogram equalization normalizes the original grayscale histogram at first, then uses the distribution function as the new variables, and scales the new variable between 0 and 255 to form a new histogram. This histogram is approximately uniformly distribution. A new picture is got correspondingly. Lighting correction is used to set the brightness all over a certain picture to a nearly same level. By treating the grayscale as a function of the position of pixels, a plan and quadratic surface can be estimated as the background. By submitting the background from the original picture, we will get a lighting correction. In application, I added the median of the estimated background surface back, and then either used truncation technique, where I set all number bigger than 255 as 255 and all number smaller than 0 as 0, or used scale technique, where I set the biggest number as 255 and smallest number as 0, then all other number were determined linearly by linear interpolation. 1

21 2 Algorithm Description Code in HistoEqualization.m is for histogram equalization, where a histogram of original picture is constructed at first, then the grayscale is stretched in order to make the new histogram approximately uniform. Code in LightingCorrection.m calls either LightingCorrectionLinear.m or LightingCorrectionQuadratic.m. Code in LightingCorrectionLinear.m applies a linear lighting correction. First a plane is estimated by using the least square estimation to estimate a, b and const. Then get the correction CG p (R, C) this way. P (R, C) = ar + bc + const. (1) CG p (R, C) = G(R, C) P (R, C) + median R,C (P (R, C)). (2) In the end, either a truncated version 0, if CG p (R, C) < 0, CG pt (R, C) = CG p (R, C), if 0 CG p (R, C) 255, 255, if CG p (R, C) > 255, or a scaled version CG ps (R, C) = 255 CG p (R, C) min CG p (R, C) max CG p (R, C) min CG p (R, C) gives the corrected pictures. Similarly, code in LightingCorrectionQuadratic.m applies a quadratic lighting correction. First a quadratic surface is estimated by using the least square estimation to estimate a, b, c, d, e and const. S(R, C) = ar 2 + brc + cc 2 + dr + ec + const. (5) Then get the correction CG s (R, C) by using the formula below. CG s (R, C) = G(R, C) S(R, C) + median R,C (S(R, C)). (6) In the end, either a truncated version 0, if CG s (R, C) < 0, CG st (R, C) = CG s (R, C), if 0 CG s (R, C) 255, 255, if CG s (R, C) > 255, 2 (3) (4) (7)

22 or a scaled version CG ss (R, C) = 255 CG s (R, C) min CG s (R, C) max CG s (R, C) min CG s (R, C) (8) gives the pictures after correction. 3 Results analysis Figure 1 shows the original moon.bmp and its Histogram Density Gray Scale Figure 1: The original moon.bmp and its Histogram. Figure 2 represents the distribution function and the transformation of moon.bmp. Figure 3 shows the equalized moon.bmp and its Histogram. By comparing with Figure 1, a lot of details can be got from this picture. Figure 4 shows the background plane of linear Lighting Correction of moon.bmp. Figure 5 shows the results of linear Lighting Correction of moon.bmp. Figure 6 shows the background quadratic surface of quadratic Lighting Correction of moon.bmp. Figure 7 shows the results of quadratic Lighting Correction of moon.bmp. 3

23 Distribution Function Gray Scale Figure 2: Distribution Function and the Transformation of moon.bmp Density Gray Scale Figure 3: The equalized moon.bmp and its Histogram. 4

24 Figure 4: Linear Lighting Correction of moon.bmp: the background plane. Figure 5: Truncated Version (left) and Scaled Version (right): Linear Lighting Correction of moon.bmp. 5

25 Figure 6: Quadratic Lighting Correction of moon.bmp: the background surface. Figure 7: Truncated Version (left) and Scaled Version (right): Quadratic Lighting Correction of moon.bmp. 6

26 By comparing with Figure 3, pictures in Figure 5 and Figure 7 have more uniformly distributed grayscales. I also computed an additional example, the original picture is from http: //info.cndsi.com/html/ / html, which was about Fighter-10 in China Air Force. By applying histogram equalization and lighting correction, more details were discovered, especially the runway Density Gray Scale Figure 8: The original nightfighter.jpg and its Histogram Density Gray Scale Figure 9: The equalized nightfighter.jpg and its Histogram. 7

27 Figure 10: Linear Lighting Correction of nightfighter.jpg: the background plane. 8

28 Figure 11: Truncated Version (top) and Scaled Version (bottom): Linear Lighting Correction of nightfighter.jpg. 9

29 Figure 12: Quadratic Lighting Correction of nightfighter.jpg: the background plane. 10

30 Figure 13: Truncated Version (top) and Scaled Version (bottom): Quadratic Lighting Correction of nightfighter.jpg. 11

31 4 MATLAB codes 1 function MP3 main 2 % Jiangtao Gou 3 % f i l e n a m e = moon ; 5 img in = rgb2gray ( imread ( [ filename,.bmp ], bmp ) ) ; 6 img out = H i s t o E q u a l i z a t i o n ( img in ) ; 7 imshow ( img out, [ 0, ] ) ; 8 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 9 picname = [ filename, e q u a l i z e d. eps ] ; 10 saveas ( gcf, picname, epsc ) ; 11 eps2pdf ( picname ) ; 12 % L i g h t i n g Correction 13 img in = img out ; 14 method = 2 ; 15 [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c t i o n ( img in, method ) ; 16 imshow ( img out truncated, [ 0, ] ) ; 17 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 18 picname = [ filename, truncated method,num2str( method ),. eps ] ; 19 saveas ( gcf, picname, epsc ) ; 20 eps2pdf ( picname ) ; 21 imshow ( i m g o u t s c a l e d, [ 0, ] ) ; 22 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 23 picname = [ filename, scaled method,num2str( method ),. eps ] ; 24 saveas ( gcf, picname, epsc ) ; 25 eps2pdf ( picname ) ; 1 function img out = H i s t o E q u a l i z a t i o n ( img in ) 2 % Jiangtao Gou 3 % plotsgn = 1 ; % Whether p l o t or not 5 histplotsgn1 = 1 ; % Whether p l o t histgram or not 6 histplotsgn2 = 1 ; % Whether p l o t d i s t r i b u t i o n or not 7 histplotsgn3 = 0 ; 8 histplotsgn4 = 0 ; 9 histplotsgn5 = 1 ; % Whether p l o t histgram or not 10 i m g s i z e = size ( img in ) ; 11 R = i m g s i z e ( 1, 1 ) ; 12 C = i m g s i z e ( 1, 2 ) ; 13 % Construct a Histogram 14 h = zeros ( 1, ) ; 15 for r = 1 : 1 :R 16 for c = 1 : 1 :C 12

32 17 h ( img in ( r, c ) +1) = h ( img in ( r, c ) +1)+1; 18 end 19 end 20 x = 0 : 1 : ; 21 y1 = h ; 22 y2 = 1/sum( h ) h ; 23 i f plotsgn && h i s t PlotSgn1 24 plot ( x, y2, k, LineWidth, 3 ) ; 25 axis ( [ ] ) ; 26 xlabel ( Gray S c a l e, f o n t s i z e,16) ; 27 ylabel ( Density, f o n t s i z e,16) ; 28 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 29 picname = [ h i s t o r i g i n a l. eps ] ; 30 saveas ( gcf, picname, epsc ) ; 31 eps2pdf ( picname ) ; 32 end 33 %x = reshape ( img in, R C, 1 ) ; [ f, x i ] = k s d e n s i t y ( x ) ; p l o t ( xi, f ) ; 34 y3 = zeros ( size ( y2 ) ) ; 35 y3 ( 1 ) = y2 ( 1 ) ; 36 for i =2:1: length ( h ) 37 y3 ( i ) = y3 ( i 1)+y2 ( i ) ; 38 end 39 i f plotsgn && h i s t PlotSgn2 40 plot ( x, y3, k, LineWidth, 3 ) ; 41 axis ( [ ] ) ; 42 xlabel ( Gray S c a l e, f o n t s i z e,16) ; 43 ylabel ( D i s t r i b u t i o n Function, f o n t s i z e,16) ; 44 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 45 picname = [ d i s t r o r i g i n a l. eps ] ; 46 saveas ( gcf, picname, epsc ) ; 47 eps2pdf ( picname ) ; 48 end 49 x2 = round( y3 255) ; 50 i f plotsgn && h i s t PlotSgn3 51 plot ( x2, y2, r, LineWidth, 3 ) ; 52 axis ( [ ] ) ; 53 xlabel ( Gray S c a l e, f o n t s i z e,16) ; 54 ylabel ( Density, f o n t s i z e,16) ; 55 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 56 picname = [ h i s t e q u a l i z e d t r y. eps ] ; 57 saveas ( gcf, picname, epsc ) ; 58 eps2pdf ( picname ) ; 59 end 60 i f plotsgn && h i s t PlotSgn4 61 plot ( x2, y3, r, LineWidth, 3 ) ; 13

33 62 axis ( [ ] ) ; 63 xlabel ( Gray S c a l e, f o n t s i z e,16) ; 64 ylabel ( D i s t r i b u t i o n Function, f o n t s i z e,16) ; 65 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 66 picname = [ d i s t r e q u a l i z e d. eps ] ; 67 saveas ( gcf, picname, epsc ) ; 68 eps2pdf ( picname ) ; 69 end 70 for r = 1 : 1 :R 71 for c = 1 : 1 :C 72 img out ( r, c ) = x2 ( img in ( r, c ) +1) ; 73 end 74 end 75 % Construct an E q u a l i z e d Histogram 76 hh = zeros ( 1, ) ; 77 for r = 1 : 1 :R 78 for c = 1 : 1 :C 79 hh ( img out ( r, c ) +1) = hh ( img out ( r, c ) +1)+1; 80 end 81 end 82 yy1 = hh ; 83 yy2 = 1/sum( hh ) hh ; 84 i f plotsgn && h i s t PlotSgn5 85 plot ( x, yy2, k, LineWidth, 3 ) ; 86 axis ( [ ] ) ; 87 xlabel ( Gray S c a l e, f o n t s i z e,16) ; 88 ylabel ( Density, f o n t s i z e,16) ; 89 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 90 picname = [ h i s t e q u a l i z e d. eps ] ; 91 saveas ( gcf, picname, epsc ) ; 92 eps2pdf ( picname ) ; 93 end 1 function [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c t i o n ( img in, method ) 2 % img in i s an e q u a l i z e d image 3 % Jiangtao Gou 4 % switch method 6 case 1 7 [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c t i o n L i n e a r ( img in ) ; 8 case 2 9 [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c tionquadratic ( img in ) ; 14

34 10 o t h e r w i s e 11 error ( Only Linear method and Quadratic method are a v a i l a b l e t e m p o r arily. ) 12 end 1 function [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c t i o n L i n e a r ( img in ) 2 % Jiangtao Gou 3 % imgsgn = 1 ; 5 i m g s i z e = size ( img in ) ; 6 R = i m g s i z e ( 1, 1 ) ; 7 C = i m g s i z e ( 1, 2 ) ; 8 xyz = zeros (R C, 3 ) ; 9 for r = 1 : 1 :R 10 for c = 1 : 1 :C 11 xyz ( ( r 1) C+c, 1 ) = r ; 12 xyz ( ( r 1) C+c, 2 ) = c ; 13 xyz ( ( r 1) C+c, 3 ) = img in ( r, c ) ; 14 end 15 end 16 x = xyz ( :, 1 ) ; 17 y = xyz ( :, 2 ) ; 18 z = xyz ( :, 3 ) ; 19 const = ones ( size ( xyz ( :, 1 ) ) ) ; % Vector o f ones f o r constant term 20 C o e f f i c i e n t s = [ x y const ] \ z ; % Find the c o e f f i c i e n t s 21 XCoeff = C o e f f i c i e n t s ( 1 ) ; % X c o e f f i c i e n t 22 YCoeff = C o e f f i c i e n t s ( 2 ) ; % X c o e f f i c i e n t 23 CCoeff = C o e f f i c i e n t s ( 3 ) ; % constant term 24 xx = ( 1 : 1 :R) ones ( 1,C) ; 25 yy = ones (R, 1 ) ( 1 : 1 :C) ; 26 %[ yy, xx ] = meshgrid ( 1 : 1 :C, 1 : 1 :R) ; % Generating a r e g u l a r g r i d f o r p l o t t i n g 27 zz = XCoeff xx + YCoeff yy + CCoeff ; 28 i f imgsgn == 1 29 surf ( xx, yy, zz ) % P l o t t i n g the s u r f a c e 30 t i t l e ( sprintf ( P l o t t i n g plane z=(%f ) x+(%f ) y+(%f ), XCoeff, YCoeff, CCoeff ) ) ; 31 xlabel ( Row Number ( x ) ) ; ylabel ( Column Number ( y ) ) ; zlabel ( Gray S c a l e ( z ) ) ; 32 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 33 picname = [ LinearPlane. eps ] ; 34 saveas ( gcf, picname, epsc ) ; 35 eps2pdf ( picname ) ; 36 end 15

35 37 % 38 zzround = round( zz ) ; 39 i f imgsgn == 1 40 imshow ( zzround, [ 0, ] ) ; 41 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 42 picname = [ LinearPlaneGray. eps ] ; 43 saveas ( gcf, picname, epsc ) ; 44 eps2pdf ( picname ) ; 45 end 46 img plane = zz ; 47 midpoint = median(median( img plane ) ) ; 48 img out = midpoint + img in img plane ; 49 img out truncated = round( img out ) ; 50 % imshow ( i m g o u t t r u ncated, [ 0, ] ) ; 51 for r = 1 : 1 :R 52 for c = 1 : 1 :C 53 i f img out truncated ( r, c ) > img out truncated ( r, c ) = 255; 55 e l s e i f img out truncated ( r, c ) < 0 56 img out truncated ( r, c ) = 0 ; 57 end 58 end 59 end 60 graymax = max(max( img out ) ) ; 61 graymin = min(min( img out ) ) ; 62 i m g o u t s c a l e d = round(255/( graymax graymin ) ( img out graymin ones ( size ( img out ) ) ) ) ; 1 function [ img out truncated, i m g o u t s c a l e d ] = L i g h t i n g C o r r e c t i o n Q u adratic ( img in ) 2 % Jiangtao Gou 3 % imgsgn = 1 ; 5 i m g s i z e = size ( img in ) ; 6 R = i m g s i z e ( 1, 1 ) ; 7 C = i m g s i z e ( 1, 2 ) ; 8 xyz = zeros (R C, 3 ) ; 9 for r = 1 : 1 :R 10 for c = 1 : 1 :C 11 xyz ( ( r 1) C+c, 1 ) = r ; 12 xyz ( ( r 1) C+c, 2 ) = c ; 13 xyz ( ( r 1) C+c, 3 ) = img in ( r, c ) ; 14 end 15 end 16 x = xyz ( :, 1 ) ; 16

36 17 y = xyz ( :, 2 ) ; 18 z = xyz ( :, 3 ) ; 19 xy = x. y ; 20 xsquare = x. x ; 21 ysquare = y. y ; 22 const = ones ( size ( xyz ( :, 1 ) ) ) ; % Vector o f ones f o r constant term 23 C o e f f i c i e n t s = [ xsquare xy ysquare x y const ] \ z ; % Find the c o e f f i c i e n t s 24 xsquarecoeff = C o e f f i c i e n t s ( 1 ) ; 25 xycoeff = C o e f f i c i e n t s ( 2 ) ; 26 ysquarecoeff = C o e f f i c i e n t s ( 3 ) ; 27 XCoeff = C o e f f i c i e n t s ( 4 ) ; % X c o e f f i c i e n t 28 YCoeff = C o e f f i c i e n t s ( 5 ) ; % X c o e f f i c i e n t 29 CCoeff = C o e f f i c i e n t s ( 6 ) ; % constant term 30 xx = ( 1 : 1 :R) ones ( 1,C) ; 31 yy = ones (R, 1 ) ( 1 : 1 :C) ; 32 %[ yy, xx ] = meshgrid ( 1 : 1 :C, 1 : 1 :R) ; % Generating a r e g u l a r g r i d f o r p l o t t i n g 33 zz = zeros (R,C) ; 34 for r = 1 : 1 :R 35 for c = 1 : 1 :C 36 zz ( r, c ) = xsquarecoeff xsquare ( ( r 1) C+c, 1 ) + xycoeff xy ( ( r 1) C+c, 1 ) + ysquarecoeff ysquare ( ( r 1) C+c, 1 ) + XCoeff x ( ( r 1) C+c, 1 ) + YCoeff y ( ( r 1) C+c, 1 ) + CCoeff ; 37 end 38 end 39 %z z = xsquarecoeff xsquare + xycoeff xy + ysquarecoeff ysquare + XCoeff xx + YCoeff yy + CCoeff ; 40 i f imgsgn == 1 41 surf ( xx, yy, zz ) % P l o t t i n g the s u r f a c e 42 t i t l e ( sprintf ( P l o t t i n g Quadratic Surface ) ) ; 43 xlabel ( Row Number ( x ) ) ; ylabel ( Column Number ( y ) ) ; zlabel ( Gray S c a l e ( z ) ) ; 44 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 45 picname = [ QuadraticPlane. eps ] ; 46 saveas ( gcf, picname, epsc ) ; 47 eps2pdf ( picname ) ; 48 end 49 % 50 zzround = round( zz ) ; 51 i f imgsgn == 1 52 imshow ( zzround, [ 0, ] ) ; 53 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 54 picname = [ QuadraticPlaneGray. eps ] ; 17

37 55 saveas ( gcf, picname, epsc ) ; 56 eps2pdf ( picname ) ; 57 end 58 img plane = zz ; 59 midpoint = median(median( img plane ) ) ; 60 img out = midpoint + img in img plane ; 61 img out truncated = round( img out ) ; 62 % imshow ( i m g o u t t r u ncated, [ 0, ] ) ; 63 for r = 1 : 1 :R 64 for c = 1 : 1 :C 65 i f img out truncated ( r, c ) > img out truncated ( r, c ) = 255; 67 e l s e i f img out truncated ( r, c ) < 0 68 img out truncated ( r, c ) = 0 ; 69 end 70 end 71 end 72 graymax = max(max( img out ) ) ; 73 graymin = min(min( img out ) ) ; 74 i m g o u t s c a l e d = round(255/( graymax graymin ) ( img out graymin ones ( size ( img out ) ) ) ) ; 75 %% Test Example 76 % img in = [ 0, 1 0 0, ; 5 0, 2 5 5, ] ; 18

38 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 4 Color Models and Color Segmentation Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 31 January Introduction In this report, I applied Histogram methods based on RGB, N-RGB, HSI systems. Meanwhile, I applied Gaussian methods based on HSI systems as well. The first step is to collect flesh tone training data. My flesh tone training data were collected from the 19 pictures which were shown in Figure 1. I took 2 rectangular patches from each picture by using MATLAB imcrop() function. I got 100,725 pixels in total. The second step is to choose a color space among all three choices which we mentioned in class. For HSI system, I applied MATLAB functions rgb2hsv() and hsv2rgb(). Finally we either use histogram method or Gaussian method. 2 Algorithm Description For histogram method, basically there are two parameters need to be tuned. The first one is the grid of histogram, I used grid up to The second one is the threshold of percentage. I assume the top 90%, 95% or 99% pixels should represent the skin color. After I decided these two parameters, I could got whether one point in a color space belongs skin color or not. Then we use this criteria to find the skin in our test examples. For Gaussian method, it is easier to program than histogram method. 1

39 Figure 1: My Flesh Tone Training DataBase 2

40 Note there is a typo in lecture slides. (c µ) T Σ 1 (c µ) > t (1) should conclude that c(u, v) is not a skin color. I first estimated µ and Σ, then for each point, I compute its (c µ) T Σ 1 (c µ), and compared it with t. I used t = 2, t = 3, and t = 4. 3 Results analysis Let me try histogram method and Gaussian method on gun1.bmp at first. First, I tried RGB system. By using RGB system, I think taking threshold 99%, and using grid for histogram is a good choice for gun1.bmp. Second, I tried N-RGB system. From Figure 5, we noted that the histogram concentrated at three corners. I tried several parameters and thresholds, but N-RGB could not give good results. One result was shown in Figure 5. Third, I tried HSI system. For gun1.bmp, when using histogram method and based on my training data, it seem that RGB > HSI >> NRGB. (2) Fourth, I tried to apply Gaussian Model on HSI system. Estimated parameters are shown below. µ = [ , ] (3) ( ) Σ = (4) The results in Figure 9 look better than the results by histogram method. Then I tried joy1.bmp and pointer1.bmp, as shown in Figure Note the wedding bind on the hand. 4 MATLAB codes 3

41 Figure 2: R-G Histogram based on RGB. Top: 8 by 8, Middle, 16 by 16, Bottom Left, 32 by 32, Bottom Right 64 by 64. 4

42 Figure 3: Skin Regions of gun1.bmp based on RGB by using n n bins 2-D histogram. Threshold 95%. Top Left: n=8, Top Right: n=16, Middle Left: n=32, Middle Right: n=64, Bottom Left: n=128, Bottom Right: n=256. 5

43 Figure 4: Skin Regions of gun1.bmp based on RGB by using n n bins 2-D histogram. Threshold 99%. Left: n=32, Right: n=256. Figure 5: NR-NG Histogram based on N-RGB. Skin Regions of gun1.bmp based on N-RGB. 6

44 Figure 6: H-S Histogram based on HSI. Grid: 64 by function t h r e s h o l d h i s t = bisectionmp4 ( t h r e s h o l d p e r c e n t, leftend, rightend, nhistn ) 2 % Jiangtao Gou 3 % a = leftend ; 5 b = rightend ; 6 c =(a+b ). / 2 ; 7 p = t h r e s h o l d p e r c e n t ; 8 sizen = size ( nhistn ) ; 9 f a = sum(sum( nhistn. ( nhistn>=a ) ) ) ; 10 fb = sum(sum( nhistn. ( nhistn>=b ) ) ) ; 11 f c = sum(sum( nhistn. ( nhistn>=c ) ) ) ; 12 cc = 0 ; 13 while abs ( fb f a )>1e 3 14 cc = cc + 1 ; 15 i f ( fc p ) ( fb p )<0 16 a = c ; 17 f a = f c ; 18 else 19 b = c ; 20 fb = f c ; 21 end 7

45 Figure 7: Skin Regions of gun1.bmp based on HSI by using bins 2-D histogram. Threshold 90% (Top), 95% (Middle), 99% (Bottom). 8

46 HSI Gaussian S H Figure 8: H-S Gaussian Distribution based on HSI. 22 c = ( a+b ) / 2 ; 23 f c = sum(sum( nhistn. ( nhistn>=c ) ) ) ; 24 x = c ; 25 i f cc > break ; 27 end 28 end 29 t h r e s h o l d h i s t = x ; 1 function FleshToneCollector 2 % Jiangtao Gou 3 % PicNum = 1 9 ; 5 SelectTime = 2 ; 6 for i = 1 : 1 : PicNum 7 picname = [ num2str( i ),. jpg ] ; 8 I = imread ( picname ) ; 9 for j = 1 : 1 : SelectTime 10 picname = [ s k i n,num2str( i ),, num2str( j ),. jpg ] ; 11 I2 = imcrop ( I ) ; 12 imwrite ( I2, picname, jpg ) ; 13 end 9

47 Figure 9: Gaussian Method: Skin Regions of gun1.bmp based on HSI. Threshold t = 2 (Top), 3 (Middle), 4 (Bottom). 10

48 Figure 10: Skin Regions of joy1.bmp and pointer1.bmp based on RGB. Grid 64 64, threshold = 99%. 11

49 Figure 11: Skin Regions of joy1.bmp and pointer1.bmp based on HSI. Grid 64 64, threshold = 99%. 12

50 Figure 12: Gaussian Method: Skin Regions of joy1.bmp and pointer1.bmp based on HSI. Threshold t = 4. 13

51 14 end 1 function t h r e s h o l d p e r c e n t = verifybisectionmp4 ( t h r e s h o l d h i s t, nhistn ) 2 % Jiangtao Gou 3 % t = t h r e s h o l d h i s t ; 5 t h r e s h o l d p e r c e n t = sum(sum( nhistn. ( nhistn>=t ) ) ) ; 1 function colorspacedata = c o l o r S p a c e D a t a C o l l e c t o r ( spacetype ) 2 % Jiangtao Gou 3 % switch spacetype 5 case 1 6 colorspacedata = colorspacedatacollectorrgb ; 7 case 2 8 colorspacedata = colorspacedatacollectornrgb ; 9 case 3 10 colorspacedata = colorspacedatacollectorhsi ; 11 o t h e r w i s e 12 error ( Only RGB, nrgb, HSI are a v a i l a b l e t emporarily. ) 13 end 1 function colorspacedata = colorspacedatacollectorrgb 2 % Jiangtao Gou 3 % PicNum = 1 9 ; 5 SelectTime = 2 ; 6 colorspacedata = [ ] ; 7 for i = 1 : 1 : PicNum 8 for j = 1 : 1 : SelectTime 9 picname = [ s k i n,num2str( i ),, num2str( j ),. jpg ] ; 10 J = imread ( picname ) ; 11 s i z e J = size ( J ) ; 12 % A Faster way 13 mat2d1 = J ( :, :, 1 ) ; 14 mat2d2 = J ( :, :, 2 ) ; 15 mat1d1 = reshape (mat2d1, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 16 mat1d2 = reshape (mat2d2, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 17 colorspacedata = [ colorspacedata ; [ mat1d1, mat1d2 ] ] ; 18 % A Slower way 19 % f o r k1 = 1 : 1 : s i z e J (1,1) 20 % f o r k2 = 1 : 1 : s i z e J (1,2) 21 % colorspacedata = [ colorspacedata ; [ J ( k1, k2, 1 ), J ( k1, k2, 2 ) ] ] ; 14

52 22 % end 23 % end 24 end 25 end 26 colorspacedata = double ( colorspacedata ) ; 27 %% Test 28 % mat3d ( :, :, 1 ) = [ 1, 3, 5, 6 ; 2, 8, 4, 9 ] ; 29 % mat3d ( :, :, 2 ) = [ 1 7, 3 7, 5 7, 6 7 ; 2 7, 8 7, 4 7, 9 7 ] ; 30 % mat2d1 = mat3d ( :, :, 1 ) ; 31 % mat2d2 = mat3d ( :, :, 2 ) ; 32 % mat1d1 = reshape (mat2d1, prod ( s i z e (mat2d1) ),1) ; 33 % mat1d2 = reshape (mat2d2, prod ( s i z e (mat2d2) ),1) ; 34 % mat1d = [ mat1d1, mat1d2 ] ; 1 function colorspacedata = colorspacedatacollectornrgb 2 % Jiangtao Gou 3 % PicNum = 1 9 ; 5 SelectTime = 2 ; 6 colorspacedata = [ ] ; 7 for i = 1 : 1 : PicNum 8 for j = 1 : 1 : SelectTime 9 picname = [ s k i n,num2str( i ),, num2str( j ),. jpg ] ; 10 J = imread ( picname ) ; 11 s i z e J = size ( J ) ; 12 mat2dsum = J ( :, :, 1 )+J ( :, :, 2 )+J ( :, :, 3 ) ; 13 mat2d1 = J ( :, :, 1 ). / mat2dsum ; 14 mat2d2 = J ( :, :, 2 ). / mat2dsum ; 15 mat1d1 = reshape (mat2d1, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 16 mat1d2 = reshape (mat2d2, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 17 colorspacedata = [ colorspacedata ; [ mat1d1, mat1d2 ] ] ; 18 end 19 end 20 colorspacedata = double ( colorspacedata ) ; 1 function colorspacedata = colorspacedatacollectorhsi 2 % Jiangtao Gou 3 % PicNum = 1 9 ; 5 SelectTime = 2 ; 6 colorspacedata = [ ] ; 7 for i = 1 : 1 : PicNum 8 for j = 1 : 1 : SelectTime 9 picname = [ s k i n,num2str( i ),, num2str( j ),. jpg ] ; 10 J = imread ( picname ) ; 15

53 11 rgb image = J ; 12 hsv image = rgb2hsv ( rgb image ) ; 13 J = hsv image ; 14 s i z e J = size ( J ) ; 15 mat2d1 = J ( :, :, 1 ) ; 16 mat2d2 = J ( :, :, 2 ) ; 17 mat1d1 = reshape (mat2d1, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 18 mat1d2 = reshape (mat2d2, s i z e J ( 1, 1 ) s i z e J ( 1, 2 ), 1 ) ; 19 colorspacedata = [ colorspacedata ; [ mat1d1, mat1d2 ] ] ; 20 end 21 end 22 colorspacedata = double ( colorspacedata ) ; 1 function n h i s t = h i s t P l o t 1 ( colorspacedata, nbins ) 2 % From MATLAB h i s t 3 B i v a r i a t e histogram 3 % Jiangtao Gou 4 % dat = colorspacedata ; 6 kk = 256/ nbins ; 7 %h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Draw histogram in 2 D 8 h i s t 3 ( dat, { 0 : kk :255 0 : kk : }, FaceAlpha,. 6 5 ) ; 9 hold on ; 10 xlabel ( R ) ; 11 ylabel ( G ) ; 12 %n = h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Extract histogram data ; 13 n= h i s t 3 ( dat, { 0 : kk :255 0 : kk : }, FaceAlpha,. 6 5 ) ; 14 n1 = n ; 15 n1 ( size (n, 1 ) + 1, size (n, 2 ) + 1 ) = 0 ; 16 % Generate g r i d f o r 2 D p r o j e c t e d view o f i n t e n s i t i e s 17 xb = linspace (min( dat ( :, 1 ) ),max( dat ( :, 1 ) ), size (n, 1 ) +1) ; 18 yb = linspace (min( dat ( :, 2 ) ),max( dat ( :, 2 ) ), size (n, 1 ) +1) ; 19 % Make a p s e u d o c o l o r p l o t on t h i s g r i d 20 h = pcolor ( xb, yb, n1 ) ; 21 % Set the z l e v e l and colormap o f the d i s p l a y e d g r i d 22 set (h, zdata, ones ( size ( n1 ) ) max(max( n ) ) ) 23 colormap ( hot ) % heat map 24 t i t l e ( RGB ) ; 25 zlabel ( Count ) ; 26 set ( gcf, r e n d e r e r, opengl ) ; 27 grid on 28 % Display the d e f a u l t 3 D p e r s p e c t i v e view 29 view ( 3 ) ; 30 hold o f f ; 16

54 31 n h i s t = n ; 32 %% 33 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 34 picname = [ h i s t. eps ] ; 35 saveas ( gcf, picname, epsc ) ; 36 eps2pdf ( picname ) ; 1 function n h i s t = h i s t P l o t 2 ( colorspacedata, nbins ) 2 % Jiangtao Gou 3 % dat = colorspacedata ; 5 kk = 1/ nbins ; 6 %h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Draw histogram in 2 D 7 h i s t 3 ( dat, { 0 : kk : 1 0 : kk : 1 }, FaceAlpha,. 6 5 ) ; 8 hold on ; 9 xlabel ( NR ) ; 10 ylabel ( NG ) ; 11 %n = h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Extract histogram data ; 12 n= h i s t 3 ( dat, { 0 : kk : 1 0 : kk : 1 }, FaceAlpha,. 6 5 ) ; 13 n1 = n ; 14 n1 ( size (n, 1 ) + 1, size (n, 2 ) + 1 ) = 0 ; 15 % Generate g r i d f o r 2 D p r o j e c t e d view o f i n t e n s i t i e s 16 xb = linspace (min( dat ( :, 1 ) ),max( dat ( :, 1 ) ), size (n, 1 ) +1) ; 17 yb = linspace (min( dat ( :, 2 ) ),max( dat ( :, 2 ) ), size (n, 1 ) +1) ; 18 % Make a p s e u d o c o l o r p l o t on t h i s g r i d 19 h = pcolor ( xb, yb, n1 ) ; 20 % Set the z l e v e l and colormap o f the d i s p l a y e d g r i d 21 set (h, zdata, ones ( size ( n1 ) ) max(max( n ) ) ) 22 colormap ( hot ) % heat map 23 t i t l e ( N RGB ) ; 24 zlabel ( Count ) ; 25 set ( gcf, r e n d e r e r, opengl ) ; 26 grid on 27 % Display the d e f a u l t 3 D p e r s p e c t i v e view 28 view ( 3 ) ; 29 hold o f f ; 30 n h i s t = n ; 31 %% 32 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 33 picname = [ h i s t n. eps ] ; 34 saveas ( gcf, picname, epsc ) ; 35 eps2pdf ( picname ) ; 17

55 1 function n h i s t = h i s t P l o t 3 ( colorspacedata, nbins ) 2 % Jiangtao Gou 3 % dat = colorspacedata ; 5 minh = min( dat ( :, 1 ) ) ; 6 maxh = max( dat ( :, 1 ) ) ; 7 mins = min( dat ( :, 2 ) ) ; 8 maxs = max( dat ( :, 2 ) ) ; 9 kh = (maxh minh) / nbins ; 10 ks = ( maxs mins ) / nbins ; 11 %h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Draw histogram in 2 D 12 h i s t 3 ( dat, { minh : kh :maxh mins : ks : maxs}, FaceAlpha,. 6 5 ) ; 13 hold on ; 14 xlabel ( H ) ; 15 ylabel ( S ) ; 16 %n = h i s t 3 ( dat, [ nbins nbins ], FaceAlpha,. 6 5 ) ; % Extract histogram data ; 17 n= h i s t 3 ( dat, { minh : kh :maxh mins : ks : maxs}, FaceAlpha,. 6 5 ) ; 18 n1 = n ; 19 n1 ( size (n, 1 ) + 1, size (n, 2 ) + 1 ) = 0 ; 20 % Generate g r i d f o r 2 D p r o j e c t e d view o f i n t e n s i t i e s 21 xb = linspace (min( dat ( :, 1 ) ),max( dat ( :, 1 ) ), size (n, 1 ) +1) ; 22 yb = linspace (min( dat ( :, 2 ) ),max( dat ( :, 2 ) ), size (n, 1 ) +1) ; 23 % Make a p s e u d o c o l o r p l o t on t h i s g r i d 24 h = pcolor ( xb, yb, n1 ) ; 25 % Set the z l e v e l and colormap o f the d i s p l a y e d g r i d 26 set (h, zdata, ones ( size ( n1 ) ) max(max( n ) ) ) 27 colormap ( hot ) % heat map 28 t i t l e ( HSI ) ; 29 zlabel ( Count ) ; 30 set ( gcf, r e n d e r e r, opengl ) ; 31 grid on 32 % Display the d e f a u l t 3 D p e r s p e c t i v e view 33 view ( 3 ) ; 34 hold o f f ; 35 n h i s t = n ; 36 %% 37 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 38 picname = [ h i s t h s. eps ] ; 39 saveas ( gcf, picname, epsc ) ; 40 eps2pdf ( picname ) ; 1 function [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearcherrgb ( 18

56 picname, sgnhist, nbins ) 2 % Jiangtao Gou 3 % k = 256/ nbins ; 5 sgnrgb = kron ( sgnhist, ones ( k, k ) ) ; 6 % picname = gun1. bmp ; 7 SK = imread ( picname ) ; 8 r e s u l t P i c C o l o r = SK; 9 sizesk = size (SK) ; 10 r e s u l t P i c = zeros ( sizesk ( 1, 1 ), sizesk ( 1, 2 ) ) ; 11 for i = 1 : 1 : sizesk ( 1, 1 ) 12 for j = 1 : 1 : sizesk ( 1, 2 ) 13 i f sgnrgb(sk( i, j, 1 ) +1,SK( i, j, 2 ) +1) == 1 14 r e s u l t P i c ( i, j ) = 1 ; 15 else 16 r e s u l t P i c ( i, j ) = 0 ; 17 r e s u l t P i c C o l o r ( i, j, 1 ) = 0 ; 18 r e s u l t P i c C o l o r ( i, j, 2 ) = 0 ; 19 r e s u l t P i c C o l o r ( i, j, 3 ) = 0 ; 20 end 21 end 22 end 1 function [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearchernrgb ( picname, sgnhist, nbins ) 2 % Jiangtao Gou 3 % k = 1/ nbins ; 5 % picname = gun1. bmp ; 6 SK = imread ( picname ) ; 7 SKsum = SK ( :, :, 1 )+SK ( :, :, 2 )+SK ( :, :, 3 ) ; 8 SKN1 = SK ( :, :, 1 ). /SKsum ; 9 SKN2 = SK ( :, :, 2 ). /SKsum ; 10 r e s u l t P i c C o l o r = SK; 11 sizesk = size (SK) ; 12 r e s u l t P i c = zeros ( sizesk ( 1, 1 ), sizesk ( 1, 2 ) ) ; 13 for i = 1 : 1 : sizesk ( 1, 1 ) 14 for j = 1 : 1 : sizesk ( 1, 2 ) 15 xx = c e i l (SKN1( i, j ) /k ) ; 16 yy = c e i l (SKN2( i, j ) /k ) ; 17 i f xx == 0 18 xx = 1 ; 19 end 20 i f yy == 0 21 yy = 1 ; 19

57 22 end 23 i f sgnhist ( xx, yy ) == 1 24 r e s u l t P i c ( i, j ) = 1 ; 25 else 26 r e s u l t P i c ( i, j ) = 0 ; 27 r e s u l t P i c C o l o r ( i, j, 1 ) = 0 ; 28 r e s u l t P i c C o l o r ( i, j, 2 ) = 0 ; 29 r e s u l t P i c C o l o r ( i, j, 3 ) = 0 ; 30 end 31 end 32 end 1 function [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearcherhsi ( picname, sgnhist, nbins, colorspacedata ) 2 % Jiangtao Gou 3 % dat = colorspacedata ; 5 minh = min( dat ( :, 1 ) ) ; 6 maxh = max( dat ( :, 1 ) ) ; 7 mins = min( dat ( :, 2 ) ) ; 8 maxs = max( dat ( :, 2 ) ) ; 9 kh = (maxh minh) / nbins ; 10 ks = ( maxs mins ) / nbins ; 11 % picname = gun1. bmp ; 12 SK = imread ( picname ) ; 13 rgb image = SK; 14 hsv image = rgb2hsv ( rgb image ) ; 15 SK = hsv image ; 16 r e s u l t P i c C o l o r = SK; 17 sizesk = size (SK) ; 18 r e s u l t P i c = zeros ( sizesk ( 1, 1 ), sizesk ( 1, 2 ) ) ; 19 for i = 1 : 1 : sizesk ( 1, 1 ) 20 for j = 1 : 1 : sizesk ( 1, 2 ) 21 hh = c e i l ( (SK( i, j, 1 ) minh) /kh) ; 22 s s = c e i l ( (SK( i, j, 2 ) mins ) /ks ) ; 23 i f (SK( i, j, 1 ) >= maxh) ( SK( i, j, 1 ) <= minh) ( SK( i, j, 2 ) >= maxs) ( SK( i, j, 2 ) <= mins ) 24 r e s u l t P i c ( i, j ) = 0 ; 25 r e s u l t P i c C o l o r ( i, j, 1 ) = 0 ; 26 r e s u l t P i c C o l o r ( i, j, 2 ) = 0 ; 27 r e s u l t P i c C o l o r ( i, j, 3 ) = 0 ; 28 e l s e i f sgnhist ( hh, s s ) == 0 29 r e s u l t P i c ( i, j ) = 0 ; 30 r e s u l t P i c C o l o r ( i, j, 1 ) = 0 ; 31 r e s u l t P i c C o l o r ( i, j, 2 ) = 0 ; 20

58 32 r e s u l t P i c C o l o r ( i, j, 3 ) = 0 ; 33 else 34 r e s u l t P i c ( i, j ) = 1 ; 35 end 36 end 37 end 38 r e s u l t P i c C o l o r = hsv2rgb ( r e s u l t P i c C o l o r ) ; 1 function r e s u l t P i c C o l o r = skinregionsearchergaussian ( picname,mu, sigma, colorspacedata, c ) 2 % For HSI only 3 % Jiangtao Gou 4 % SK = imread ( picname ) ; 6 rgb image = SK; 7 hsv image = rgb2hsv ( rgb image ) ; 8 SK = hsv image ; 9 r e s u l t P i c C o l o r = SK; 10 sizesk = size (SK) ; 11 for i = 1 : 1 : sizesk ( 1, 1 ) 12 for j = 1 : 1 : sizesk ( 1, 2 ) 13 vec = [SK( i, j, 1 ) ; SK( i, j, 2 ) ] mu ; 14 normdev = vec inv ( sigma ) vec ; 15 i f normdev > c 16 r e s u l t P i c C o l o r ( i, j, 1 ) = 0 ; 17 r e s u l t P i c C o l o r ( i, j, 2 ) = 0 ; 18 r e s u l t P i c C o l o r ( i, j, 3 ) = 0 ; 19 end 20 end 21 end 22 r e s u l t P i c C o l o r = hsv2rgb ( r e s u l t P i c C o l o r ) ; 1 function MP4 main 2 % Jiangtao Gou 3 % FleshToneCollector ; 5 % 1 RGB, 2 nrgb, 3 HSI 6 colorspacedata = c o l o r S p a c e D a t a C o l l e c t o r ( 1 ) ; 7 nbins = 6 4 ; 8 n h i s t = h i s t P l o t 1 ( colorspacedata, nbins ) ; 9 nhistn = 1/sum(sum( n h i s t ) ) n h i s t ; 10 leftend = min(min( nhistn ) ) ; 11 rightend = max(max( nhistn ) ) / 4 ; 12 t h r e s h o l d p e r c e n t = ; 21

59 13 t h r e s h o l d h i s t = bisectionmp4 ( t h r e s h o l d p e r c e n t, leftend, rightend, nhistn ) ; 14 % 15 t h r e s h o l d p e r c e n t = verifybisectionmp4 ( t h r e s h o l d h i s t, nhistn ) ; 16 % 17 sgnhist = ( nhistn >= t h r e s h o l d h i s t ) ; 18 % 19 picname1 = p o i n t e r 1.bmp ; 20 f i l e n a m e 1 = p o i n t e r 1 ; 21 [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearcherrgb ( picname1, sgnhist, nbins ) ; 22 %imshow ( r e s u l t P i c, [ 0, 1 ] ) ; 23 imshow ( r e s u l t P i c C o l o r ) ; 24 f i l e n a m e = f i l e n a m e 1 ; 25 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 26 picname = [ filename,. eps ] ; 27 saveas ( gcf, picname, epsc ) ; 28 eps2pdf ( picname ) ; 1 function MP4 main 2 2 % Jiangtao Gou 3 % % 1 RGB, 2 nrgb, 3 HSI 5 colorspacedata = c o l o r S p a c e D a t a C o l l e c t o r ( 2 ) ; 6 nbins = 1 6 ; 7 n h i s t = h i s t P l o t 2 ( colorspacedata, nbins ) ; 8 nhistn = 1/sum(sum( n h i s t ) ) n h i s t ; 9 leftend = min(min( nhistn ) ) ; 10 rightend = max(max( nhistn ) ) ; 11 t h r e s h o l d p e r c e n t = ; 12 t h r e s h o l d h i s t = bisectionmp4 ( t h r e s h o l d p e r c e n t, leftend, rightend, nhistn ) ; 13 % 14 t h r e s h o l d p e r c e n t = verifybisectionmp4 ( t h r e s h o l d h i s t, nhistn ) ; 15 % 16 sgnhist = ( nhistn >= t h r e s h o l d h i s t ) ; 17 % 18 picname1 = gun1. bmp ; 19 f i l e n a m e 1 = gun1 n ; 20 [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearchernrgb ( picname1, sgnhist, nbins ) ; 21 %imshow ( r e s u l t P i c, [ 0, 1 ] ) ; 22 imshow ( r e s u l t P i c C o l o r ) ; 23 f i l e n a m e = f i l e n a m e 1 ; 24 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 22

60 25 picname = [ filename,. eps ] ; 26 saveas ( gcf, picname, epsc ) ; 27 eps2pdf ( picname ) ; 1 function MP4 main 3 2 % Jiangtao Gou 3 % % 1 RGB, 2 nrgb, 3 HSI 5 colorspacedata = c o l o r S p a c e D a t a C o l l e c t o r ( 3 ) ; 6 nbins = 6 4 ; 7 n h i s t = h i s t P l o t 3 ( colorspacedata, nbins ) ; 8 % 9 nhistn = 1/sum(sum( n h i s t ) ) n h i s t ; 10 leftend = min(min( nhistn ) ) ; 11 rightend = max(max( nhistn ) ) ; 12 t h r e s h o l d p e r c e n t = ; 13 t h r e s h o l d h i s t = bisectionmp4 ( t h r e s h o l d p e r c e n t, leftend, rightend, nhistn ) ; 14 % 15 t h r e s h o l d p e r c e n t = verifybisectionmp4 ( t h r e s h o l d h i s t, nhistn ) ; 16 % 17 sgnhist = ( nhistn >= t h r e s h o l d h i s t ) ; 18 % 19 picname1 = joy1. bmp ; 20 f i l e n a m e 1 = j o y 1 h s ; 21 [ r e s u l t P i c, r e s u l t P i c C o l o r ] = skinregionsearcherhsi ( picname1, sgnhist, nbins, colorspacedata ) ; 22 %imshow ( r e s u l t P i c, [ 0, 1 ] ) ; 23 imshow ( r e s u l t P i c C o l o r ) ; 24 f i l e n a m e = f i l e n a m e 1 ; 25 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 26 picname = [ filename,. eps ] ; 27 saveas ( gcf, picname, epsc ) ; 28 eps2pdf ( picname ) ; 1 function MP4 main Gaussian 2 % For HSI only 3 % Jiangtao Gou 4 % colorspacedata = colorspacedatacollectorhsi ; 6 mu = mean( colorspacedata ) ; 7 sigma = cov ( colorspacedata ) ; 8 % 9 c = 4 ; 10 picname1 = p o i n t e r 1.bmp ; 23

61 11 f i l e n a m e 1 = p o i n t e r 1 g a u s s i a n ; 12 r e s u l t P i c C o l o r = skinregionsearchergaussian ( picname1,mu, sigma, colorspacedata, c ) ; 13 imshow ( r e s u l t P i c C o l o r ) ; 14 f i l e n a m e = f i l e n a m e 1 ; 15 set ( gcf, p a p e r s i z e, [ 5 6 ] ) ; 16 picname = [ filename,. eps ] ; 17 saveas ( gcf, picname, epsc ) ; 18 eps2pdf ( picname ) ; 19 % 20 minhs = min( colorspacedata ) ; 21 maxhs = max( colorspacedata ) ; 22 x = minhs ( 1 ) : ( ( maxhs( 1 ) minhs ( 1 ) ) /10) : maxhs( 1 ) ; 23 y = minhs ( 2 ) : ( ( maxhs( 2 ) minhs ( 2 ) ) /10) : maxhs( 2 ) ; 24 [X,Y]=meshgrid ( x, y ) ; 25 p=mvnpdf ( [X( : ),Y( : ) ],mu, sigma ) ; 26 P=reshape (p, size (X) ) ; 27 surf (X,Y,P) 28 shading f l a t 29 xlabel ( H ) ; 30 ylabel ( S ) ; 31 t i t l e ( HSI Gaussian ) ; 32 set ( gcf, p a p e r s i z e, [ 5 8 ] ) ; 33 picname = [ g a u s s i a n h s. eps ] ; 34 saveas ( gcf, picname, epsc ) ; 35 eps2pdf ( picname ) ; 36 % 24

62 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 5 Canny Edge Detector Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 26 February Introduction In this report, I implemented the Canny edge detector by using MATLAB. 2 Algorithm Description The first step is to use Gaussian smoothing as a filter to get rid of image noise by using Gaussian kernel. When the picture is relatively smooth, I compute the image gradient by Sobel operators, which used 3 by 3 grid to compute, and should give better results than Robert Cross operators, which used 2 by 2 grid. Then I choose high and low thresholds. As Professor suggested, I choose high threshold to achieve 80% above, and choose low threshold as half of high threshold. The fourth step is to supress non-maxima. In the following I linked the edges by using the recursive algorithm, where I randomly choose the start point, and link edges. Parameter N and σ were changed to see the different effects. 3 Results analysis Some computation could be slow. The results are shown in those pictures below. 1

63 I tested my edge detector on all four pictures which provided by professor. Meanwhile, I use the whole body picture of Lena as the case of my own to test this edge detector. The results are presented in these pictures. 4 MATLAB codes 1 function E=EdgeLinking ( Mag low, Mag high ) 2 3 [ row, c o l ]= find ( Mag high >0) ; 4 for t =1:1: size ( c o l ) 5 i f ( row ( t )<size ( c o l ) & c o l ( t )<size ( c o l ) ) 6 i f ( Mag low ( row ( t ) +1, c o l ( t ) ) >0) 7 Mag high ( row ( t ) +1, c o l ( t ) ) =1; 8 Mag low ( row ( t ) +1, c o l ( t ) ) =0; 9 end 10 i f ( Mag low ( row ( t ), c o l ( t ) +1)>0) 11 Mag high ( row ( t ), c o l ( t ) +1)=1; 12 Mag low ( row ( t ), c o l ( t ) +1)=0; 13 end 14 i f ( Mag low ( row ( t ) +1, c o l ( t ) +1)>0) 15 Mag high ( row ( t ) +1, c o l ( t ) +1)=1; 16 Mag low ( row ( t ) +1, c o l ( t ) +1)=0; 17 end 18 i f ( Mag low ( row ( t ) 1, c o l ( t ) 1)>0) 19 Mag high ( row ( t ) 1, c o l ( t ) 1)=1; 20 Mag low ( row ( t ) 1, c o l ( t ) 1)=0; 21 end 22 i f ( Mag low ( row ( t ) +1, c o l ( t ) 1)>0) 23 Mag high ( row ( t ) +1, c o l ( t ) 1)=1; 24 Mag low ( row ( t ) +1, c o l ( t ) 1)=0; 25 end 26 i f ( Mag low ( row ( t ) 1, c o l ( t ) +1)>0) 27 Mag high ( row ( t ) 1, c o l ( t ) +1)=1; 28 Mag low ( row ( t ) 1, c o l ( t ) +1)=0; 29 end 30 i f ( Mag low ( row ( t ) 1, c o l ( t ) ) >0) 31 Mag high ( row ( t ) 1, c o l ( t ) ) =1; 32 Mag low ( row ( t ) 1, c o l ( t ) ) =0; 33 end 34 i f ( Mag low ( row ( t ), c o l ( t ) 1)>0) 35 Mag high ( row ( t ), c o l ( t ) 1)=1; 36 Mag low ( row ( t ), c o l ( t ) 1)=0; 2

64 Figure 1: Result: N=3, Sigma=3, PercentageOfNonEdge=

65 Figure 2: Result: N=3, Sigma=3, PercentageOfNonEdge=

66 Figure 3: Result: N=3, Sigma=3, PercentageOfNonEdge= end 38 end 39 end 40 E=Mag high ; 1 function [ T low, T high ]= FindThreshold (Mag, percentageofnonedge ) 2 [ n,m]= size (Mag) ; 3 binnum=64; 4 counts=i mhist (Mag, binnum) ; 5 6 maxv=max(mag ( : ) ) ; 7 %minimum v a l u e i s zero 8 minv =0; 9 T high = ( find (cumsum( counts ) > percentageofnonedge m n, 1, f i r s t ) / (binnum 1) ) (maxv minv )+minv ; 10 T low =0.5 T high ; 1 function s=gausssmoothing ( I, N, sigma ) 2 %N=3 3 %Sigma=3 5

67 Figure 4: Result: N=3, Sigma=5, PercentageOfNonEdge= Gmask=f s p e c i a l ( g aussian, [N,N], sigma ) ; 5 s=conv2( I, Gmask, same ) ; 1 function [ Mag, Theta]= ImageGradient ( s ) 2 % S o b e l f i l t e r 3 [ n,m]= size ( s ) ; 4 Theta=zeros (n,m) ; 5 h = [ ; 0 0 0; 1 2 1]; 6 op = h / 8 ; % S o b e l approximation to d e r i v a t i v e 7 x mask = op ; % g r a d i e n t in the X d i r e c t i o n 8 y mask = op ; 9 10 % compute t he g r a d i e n t in x and y d i r e c t i o n 11 bx = i m f i l t e r ( s, x mask, r e p l i c a t e ) ; 12 by = i m f i l t e r ( s, y mask, r e p l i c a t e ) ; 13 % compute t he magnitude and d i r e c t i o n 14 Mag = sqrt ( bx. bx + by. by ) ; Theta ( find ( by =0) )=atan ( bx ( find ( by =0) ). / by ( find ( by =0) ) ) ; 17 Theta ( find ( by==0)) =3.14/2; 6

68 Figure 5: Result: N=5, sigma=5, PercentageOfNonEdge= % Get t he i n i t i a l image lena. g i f 2 f i l e n a m e = gun1 ; 3 %binary 4 img in = rgb2gray ( imread ( [ filename,.bmp ], bmp ) ) ; 5 figure ; 6 colormap ( gray ) ; 7 % s u b p l o t (2,3,1) ; 8 imagesc ( img in ) ; 9 t i t l e ( O r i g i n a l image ) 10 %Gaussian smooth with two parameters N and sigma 11 N=5; 12 sigma =5; 13 s=gausssmoothing ( img in, N, sigma ) ; 14 figure ; 15 colormap ( gray ) ; 16 % s u b p l o t (2,3,2) ; 17 imagesc ( s ) ; 18 t i t l e ( Gaussian smoothing ) 19 %c a l c u l a t i n g image g r a d i e n t with S obel 20 [ Mag, Theta]= ImageGradient ( s ) ; 7

69 Figure 6: Result: The image right after gaussian smoothing. 21 %f i n d maximum v a l u e 22 maxv=max(mag ( : ) ) ; 23 %normalize v a l u e s 24 Mag=Mag/maxv ; 25 figure ; 26 colormap ( gray ) ; 27 % s u b p l o t (2,3,3) ; 28 imagesc (Mag) ; 29 t i t l e ( C a l c u l a t i n g image g r a d i e n t by Sobel ) 30 %f i n d two t h r e s h o l d s with one parameter percentageofnonedge 31 percentageofnonedge = 0. 6; 32 [ T low, T high ]= FindThreshold (Mag, percentageofnonedge ) ; 33 %s u p r e s s i n g nonmaxima 34 Mag supress=nonmaximasupress (Mag, Theta ) ; 35 figure ; 36 colormap ( gray ) ; 37 % s u b p l o t (2,3,4) ; 38 imagesc ( Mag supress ) ; 39 t i t l e ( Non maxima s u p r e s s i n g ) % Applying T high 8

70 Figure 7: Result: N=3, Sigma=3, PercentageOfNonEdge=

71 Figure 8: Result: N=3, Sigma=3, PercentageOfNonEdge=

72 Figure 9: Result: N=3, Sigma=3, PercentageOfNonEdge=

73 Figure 10: Result: N=3, Sigma=3, PercentageOfNonEdge=

74 Figure 11: Result: N=3, Sigma=3, PercentageOfNonEdge=

75 Figure 12: Result: N=3, Sigma=3, PercentageOfNonEdge=

76 Figure 13: Result: N=3, Sigma=3, PercentageOfNonEdge=

77 Figure 14: Result: N=3, Sigma=3, PercentageOfNonEdge=

78 42 Mag high=mag supress ; 43 Mag high ( find ( Mag supress<t high ) ) =0; 44 Mag high ( find ( Mag supress>=t high ) ) =1; 45 figure ; 46 colormap ( gray ) 47 % s u b p l o t (2,3,5) ; 48 imagesc ( Mag high ) ; 49 t i t l e ( Applying T high ) ; % Applying T low 52 Mag low=mag supress ; 53 Mag low ( find ( Mag supress<t low ) ) =0; 54 Mag low ( find ( Mag supress>=t low ) ) =1; 55 figure ; 56 colormap ( gray ) 57 % s u b p l o t (2,3,6) ; 58 imagesc ( Mag low ) 59 t i t l e ( Applying T low ) ; 60 %Edge l i n k i n g 61 E=EdgeLinking ( Mag low, Mag high ) ; 62 figure 63 colormap ( gray ) 64 imagesc (E) ; 65 t i t l e ( f i n a l Canny ) ; figure 68 edge ( img in, s o b e l ) 69 t i t l e ( s o b e l by MATLAB f u n c t i o n edge ) 70 figure 71 edge ( img in, r o b e r t s ) 72 t i t l e ( r o b e r t s by MATLAB f u n c t i o n edge ) 73 figure 74 edge ( img in, z e r o c r o s s ) 75 t i t l e ( z e r o c r o s s by MATLAB f u n c t i o n edge ) 76 figure 77 edge ( img in, canny ) 78 t i t l e ( canny by MATLAB f u n c t i o n edge ) t t =1; 1 function Mag supress=nonmaximasupress (Mag, Theta ) 2 %s u p r e s s i n g nonmaxima by the i n t e r p o l a t i o n method 3 [ n,m]= size (Mag) ; 4 for i =2:n 1, 5 for j =2:m 1, 17

79 6 7 X=[ 1,0,+1; 1,0,+1; 1,0,+1]; 8 Y=[ 1, 1, 1;0,0,0;+1,+1,+1]; 9 Z=[Mag( i 1, j 1),Mag( i 1, j ),Mag( i 1, j +1) ; 10 Mag( i, j 1),Mag( i, j ),Mag( i, j +1) ; 11 Mag( i +1, j 1),Mag( i +1, j ),Mag( i +1, j +1) ] ; 12 XI=[ sin ( Theta ( i, j ) ), sin ( Theta ( i, j ) ) ] ; 13 YI=[cos ( Theta ( i, j ) ), cos ( Theta ( i, j ) ) ] ; ZI=interp2 (X,Y, Z, XI, YI ) ; 16 i f Mag( i, j ) >= ZI ( 1 ) & Mag( i, j ) >= ZI ( 2 ) 17 Mag supress ( i, j )=Mag( i, j ) ; 18 else 19 Mag supress ( i, j ) =0.0; 20 end end 23 end 18

80 Winter 2013 EECS 332 Digital Image Analysis Machine Problem 6 Hough Transform: Line Detection Jiangtao Gou Department of Statistics, Northwestern University Instructor: Prof. Ying Wu 4 March Introduction In this report, I implemented Hough transform, which is an algorithm for line detection. My main references are Prof. Wu s lecture notes Hough Transform and Jain, Kasturi and Schunck s book Machine Vision, section 6.8.4, Hough Transform. For Hough Transform itself, I basically followed Algorithm 6.4 Hough Transform Algorithm, which is described on page 220 of the book Machine Vision. The basic idea is to use the dual space, where points and lines are dual elements to each other. For line detection, we can either use rectangular coordinate system or polar system. In this report, I use polar system (ρ, θ). 2 Algorithm Description The first step is edge detection. We can either use the programs in Machine Problem 5 last time or use edge(), which is a MATLAB function. Here I directly use edge(). For each edge point (x, y) in original image (size R C), I will use ρ = x cos θ + y sin θ to transform the point (x, y) to a curve in ρ-θ space, where ρ ( R 2 + C 2, R 2 + C 2 ) and θ ( π/2, π/2). Accumulators will count how many times each point has satisfied the curve equation. In the third step, I will choose a threshold, choose the points in ρ-θ space which have large count numbers. 1

81 Finally, I transform these points in ρ-θ space back to several lines in x-y space. x = ρ y sin θ. cos θ It is really a very smart idea to use dual elements. 3 Results analysis In this report, without special claim, I use a picture as my ρ-θ picture. In the plot of significant intersections, I enlarged each intersection in order to make each point easy to be observed. 3.1 Picture test.bmp For Picture test.bmp, I used canny as the edge detector, and the accumulator got 119 as the maximal count. 3.2 Picture test2.bmp For Picture test2.bmp, I used canny as the edge detector, and the accumulator got 122 as the maximal count. 3.3 Picture input.bmp For Picture input.bmp, when I used canny as the edge detector, and the accumulator got 54 as the maximal count. The results by using Canny edge detector as a pre-processor were presented in Figure 5 and 6. We could see that it was OK to detect the paper, but it is relatively difficult to detect the finger (or you need to bring in a lot of noise lines). We need to change the edge detector. Now I used sobel as the edge detector, and the accumulator got 56 as the maximal count. The results by using Sobel edge detector as a pre-processor were presented in Figure 7 and 8. 2

82 Figure 1: Original picture test.bmp, edge detected picture, curves in parameter space. 3

83 Figure 2: Top-down: threshold 90, 85, 80, 60, significant intersections and detected lines. 4

84 Figure 3: Original picture test2.bmp, edge detected picture, curves in parameter space. 5

85 Figure 4: Top-down: threshold 80, 75, 70, 60, significant intersections and detected lines. 6

86 Figure 5: Original picture input.bmp, edge detected picture, curves in parameter space. (Canny Edge Detection) 7

87 Figure 6: Top-down: threshold 38, 30, significant intersections and detected lines. (Canny Edge Detection) 8

88 By using Sobel edge detector, detecting finger is still not easy, but we can observe that Sobel edge detector achieved better result than Canny edge detector. I also tried different quantization scheme. I tried , , , and I felt that gave the best results. So neither using too coarse nor too fine quantization achieve good result Nissan Altima 2.5 SV I got a picture from I used sobel as the edge detector, and the accumulator got 244 as the maximal count, as shown in Figure 12. By setting the threshold as 195, we got the detected lines, as shown in Figure 13. The result looks good. We can observe that the edges of windshield, the edge of front door, the edge of shift selector area and the edge of glove box are all detected. 4 MATLAB codes 1 % main MP6 2 f i l e n a m e = altima i n t 2 ; 3 picname = [ filename,. jpg ] ; 4 % 5 I1 = imread ( picname ) ; 6 I2 = rgb2gray ( I1 ) ; 7 % 8 imshow ( I2, [ 0, ] ) ; 9 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 10 picname = [ filename, 1. eps ] ; 11 saveas ( gcf, picname, epsc ) ; 12 eps2pdf ( picname ) ; 13 % 14 % BW = edge ( I2, canny ) ; 15 BW = edge ( I2, s o b e l ) ; 16 % 17 imshow (BW, [ 0, 1 ] ) ; 18 set ( gcf, p a p e r s i z e, [ 5 5 ] ) ; 19 picname = [ filename, 2. eps ] ; 9

89 Figure 7: Original picture input.bmp, edge detected picture, curves in parameter space. (Sobel Edge Detection) 10

90 Figure 8: Top-down: threshold 30, 20, significant intersections and detected lines. (Sobel Edge Detection) 11

91 Figure 9: Parameter space, Significant intersections, Detected lines, Sobel detector, picture as the ρ-θ picture. Maxima 71, threshold

92 Figure 10: Parameter space, Significant intersections, Detected lines, Sobel detector, picture as the ρ-θ picture. Maxima 117, threshold

93 Figure 11: Parameter space, Significant intersections, Detected lines, Sobel detector, picture as the ρ-θ picture. Maxima 200, threshold

94 Figure 12: Original picture altima-int2.jpg, and edge detected picture (Sobel). 15

95 Figure 13: Line Detection of altima-int2.jpg. 16

ECE661: Homework 6. Ahmed Mohamed October 28, 2014

ECE661: Homework 6. Ahmed Mohamed October 28, 2014 ECE661: Homework 6 Ahmed Mohamed (akaseb@purdue.edu) October 28, 2014 1 Otsu Segmentation Algorithm Given a grayscale image, my implementation of the Otsu algorithm follows these steps: 1. Construct a

More information

Problem Session #5. EE368/CS232 Digital Image Processing

Problem Session #5. EE368/CS232 Digital Image Processing Problem Session #5 EE368/CS232 Digital Image Processing 1. Solving a Jigsaw Puzzle Please download the image hw5_puzzle_pieces.jpg from the handouts webpage, which shows the pieces of a jigsaw puzzle.

More information

Experiment 1: Linear Regression

Experiment 1: Linear Regression Experiment 1: Linear Regression August 27, 2018 1 Description This first exercise will give you practice with linear regression. These exercises have been extensively tested with Matlab, but they should

More information

Statistics Assignment 2 HET551 Design and Development Project 1

Statistics Assignment 2 HET551 Design and Development Project 1 Statistics Assignment HET Design and Development Project Michael Allwright - 74634 Haddon O Neill 7396 Monday, 3 June Simple Stochastic Processes Mean, Variance and Covariance Derivation The following

More information

Reading. 3. Image processing. Pixel movement. Image processing Y R I G Q

Reading. 3. Image processing. Pixel movement. Image processing Y R I G Q Reading Jain, Kasturi, Schunck, Machine Vision. McGraw-Hill, 1995. Sections 4.-4.4, 4.5(intro), 4.5.5, 4.5.6, 5.1-5.4. 3. Image processing 1 Image processing An image processing operation typically defines

More information

Lesson 13: More Factoring Strategies for Quadratic Equations & Expressions

Lesson 13: More Factoring Strategies for Quadratic Equations & Expressions : More Factoring Strategies for Quadratic Equations & Expressions Opening Exploration Looking for Signs In the last lesson, we focused on quadratic equations where all the terms were positive. Juan s examples

More information

Detection of Motor Vehicles and Humans on Ocean Shoreline. Seif Abu Bakr

Detection of Motor Vehicles and Humans on Ocean Shoreline. Seif Abu Bakr Detection of Motor Vehicles and Humans on Ocean Shoreline Seif Abu Bakr Dec 14, 2009 Boston University Department of Electrical and Computer Engineering Technical report No.ECE-2009-05 BOSTON UNIVERSITY

More information

Naive Bayes & Introduction to Gaussians

Naive Bayes & Introduction to Gaussians Naive Bayes & Introduction to Gaussians Andreas C. Kapourani 2 March 217 1 Naive Bayes classifier In the previous lab we illustrated how to use Bayes Theorem for pattern classification, which in practice

More information

Lecture 28 The Main Sources of Error

Lecture 28 The Main Sources of Error Lecture 28 The Main Sources of Error Truncation Error Truncation error is defined as the error caused directly by an approximation method For instance, all numerical integration methods are approximations

More information

Algebra I. Book 2. Powered by...

Algebra I. Book 2. Powered by... Algebra I Book 2 Powered by... ALGEBRA I Units 4-7 by The Algebra I Development Team ALGEBRA I UNIT 4 POWERS AND POLYNOMIALS......... 1 4.0 Review................ 2 4.1 Properties of Exponents..........

More information

Numerical Implementation of Transformation Optics

Numerical Implementation of Transformation Optics ECE 5322 21 st Century Electromagnetics Instructor: Office: Phone: E Mail: Dr. Raymond C. Rumpf A 337 (915) 747 6958 rcrumpf@utep.edu Lecture #16b Numerical Implementation of Transformation Optics Lecture

More information

PHYS 114 Exam 1 Answer Key NAME:

PHYS 114 Exam 1 Answer Key NAME: PHYS 4 Exam Answer Key AME: Please answer all of the questions below. Each part of each question is worth points, except question 5, which is worth 0 points.. Explain what the following MatLAB commands

More information

UNIVERSITY OF NORTH CAROLINA CHARLOTTE 1995 HIGH SCHOOL MATHEMATICS CONTEST March 13, 1995 (C) 10 3 (D) = 1011 (10 1) 9

UNIVERSITY OF NORTH CAROLINA CHARLOTTE 1995 HIGH SCHOOL MATHEMATICS CONTEST March 13, 1995 (C) 10 3 (D) = 1011 (10 1) 9 UNIVERSITY OF NORTH CAROLINA CHARLOTTE 5 HIGH SCHOOL MATHEMATICS CONTEST March, 5. 0 2 0 = (A) (B) 0 (C) 0 (D) 0 (E) 0 (E) 0 2 0 = 0 (0 ) = 0 2. If z = x, what are all the values of y for which (x + y)

More information

What is Image Deblurring?

What is Image Deblurring? What is Image Deblurring? When we use a camera, we want the recorded image to be a faithful representation of the scene that we see but every image is more or less blurry, depending on the circumstances.

More information

Chapter 4. Displaying and Summarizing. Quantitative Data

Chapter 4. Displaying and Summarizing. Quantitative Data STAT 141 Introduction to Statistics Chapter 4 Displaying and Summarizing Quantitative Data Bin Zou (bzou@ualberta.ca) STAT 141 University of Alberta Winter 2015 1 / 31 4.1 Histograms 1 We divide the range

More information

Homework 5 Solutions

Homework 5 Solutions 18-290 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 2017 Homework 5 Solutions Part One 1. (18 points) For each of the following impulse responses, determine whether the corresponding LTI

More information

Image Processing. Waleed A. Yousef Faculty of Computers and Information, Helwan University. April 3, 2010

Image Processing. Waleed A. Yousef Faculty of Computers and Information, Helwan University. April 3, 2010 Image Processing Waleed A. Yousef Faculty of Computers and Information, Helwan University. April 3, 2010 Ch3. Image Enhancement in the Spatial Domain Note that T (m) = 0.5 E. The general law of contrast

More information

ECE 661: Homework 10 Fall 2014

ECE 661: Homework 10 Fall 2014 ECE 661: Homework 10 Fall 2014 This homework consists of the following two parts: (1) Face recognition with PCA and LDA for dimensionality reduction and the nearest-neighborhood rule for classification;

More information

Problem Set 8 - Solution

Problem Set 8 - Solution Problem Set 8 - Solution Jonasz Słomka Unless otherwise specified, you may use MATLAB to assist with computations. provide a print-out of the code used and its output with your assignment. Please 1. More

More information

Homework 5 Solutions

Homework 5 Solutions 18-290 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 2018 Homework 5 Solutions. Part One 1. (12 points) Calculate the following convolutions: (a) x[n] δ[n n 0 ] (b) 2 n u[n] u[n] (c) 2 n u[n]

More information

Homework 1 Solutions

Homework 1 Solutions 18-9 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 18 Homework 1 Solutions Part One 1. (8 points) Consider the DT signal given by the algorithm: x[] = 1 x[1] = x[n] = x[n 1] x[n ] (a) Plot

More information

COMP 551 Applied Machine Learning Lecture 20: Gaussian processes

COMP 551 Applied Machine Learning Lecture 20: Gaussian processes COMP 55 Applied Machine Learning Lecture 2: Gaussian processes Instructor: Ryan Lowe (ryan.lowe@cs.mcgill.ca) Slides mostly by: (herke.vanhoof@mcgill.ca) Class web page: www.cs.mcgill.ca/~hvanho2/comp55

More information

Modeling Classes of Shapes Suppose you have a class of shapes with a range of variations: System 2 Overview

Modeling Classes of Shapes Suppose you have a class of shapes with a range of variations: System 2 Overview 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 4 4 4 6 Modeling Classes of Shapes Suppose you have a class of shapes with a range of variations: System processes System Overview Previous Systems:

More information

1 What is the area model for multiplication?

1 What is the area model for multiplication? for multiplication represents a lovely way to view the distribution property the real number exhibit. This property is the link between addition and multiplication. 1 1 What is the area model for multiplication?

More information

Slide a window along the input arc sequence S. Least-squares estimate. σ 2. σ Estimate 1. Statistically test the difference between θ 1 and θ 2

Slide a window along the input arc sequence S. Least-squares estimate. σ 2. σ Estimate 1. Statistically test the difference between θ 1 and θ 2 Corner Detection 2D Image Features Corners are important two dimensional features. Two dimensional image features are interesting local structures. They include junctions of dierent types Slide 3 They

More information

Morphological Operations. GV12/3072 Image Processing.

Morphological Operations. GV12/3072 Image Processing. Morphological Operations 1 Outline Basic concepts: Erode and dilate Open and close. Granulometry Hit and miss transform Thinning and thickening Skeletonization and the medial axis transform Introduction

More information

Algebra II Polynomials: Operations and Functions

Algebra II Polynomials: Operations and Functions Slide 1 / 276 Slide 2 / 276 Algebra II Polynomials: Operations and Functions 2014-10-22 www.njctl.org Slide 3 / 276 Table of Contents click on the topic to go to that section Properties of Exponents Review

More information

CS 4495 Computer Vision Binary images and Morphology

CS 4495 Computer Vision Binary images and Morphology CS 4495 Computer Vision Binary images and Aaron Bobick School of Interactive Computing Administrivia PS6 should be working on it! Due Sunday Nov 24 th. Some issues with reading frames. Resolved? Exam:

More information

Test 4 also includes review problems from earlier sections so study test reviews 1, 2, and 3 also.

Test 4 also includes review problems from earlier sections so study test reviews 1, 2, and 3 also. MATD 0370 ELEMENTARY ALGEBRA REVIEW FOR TEST 4 (1.1-10.1, not including 8.2) Test 4 also includes review problems from earlier sections so study test reviews 1, 2, and 3 also. 1. Factor completely: a 2

More information

Interpolation and Polynomial Approximation I

Interpolation and Polynomial Approximation I Interpolation and Polynomial Approximation I If f (n) (x), n are available, Taylor polynomial is an approximation: f (x) = f (x 0 )+f (x 0 )(x x 0 )+ 1 2! f (x 0 )(x x 0 ) 2 + Example: e x = 1 + x 1! +

More information

Bayesian Classifiers and Probability Estimation. Vassilis Athitsos CSE 4308/5360: Artificial Intelligence I University of Texas at Arlington

Bayesian Classifiers and Probability Estimation. Vassilis Athitsos CSE 4308/5360: Artificial Intelligence I University of Texas at Arlington Bayesian Classifiers and Probability Estimation Vassilis Athitsos CSE 4308/5360: Artificial Intelligence I University of Texas at Arlington 1 Data Space Suppose that we have a classification problem The

More information

Computer Vision, Laboratory session 2

Computer Vision, Laboratory session 2 Centre for Mathematical Sciences, February 2011 Computer Vision, Laboratory session 2 In the first laboratory you downloaded datorsee.zip from the homepage: http://www.maths.lth.se/matematiklth/vision/datorsee

More information

Digital Image Processing COSC 6380/4393

Digital Image Processing COSC 6380/4393 Digital Image Processing COSC 6380/4393 Lecture 7 Sept 11 th, 2018 Pranav Mantini Slides from Dr. Shishir K Shah and Frank (Qingzhong) Liu Today Review Binary Image Processing Opening and Closing Skeletonization

More information

Chapter 1: Introduction

Chapter 1: Introduction Chapter 1: Introduction Definition: A differential equation is an equation involving the derivative of a function. If the function depends on a single variable, then only ordinary derivatives appear and

More information

Multimedia Databases. Previous Lecture. 4.1 Multiresolution Analysis. 4 Shape-based Features. 4.1 Multiresolution Analysis

Multimedia Databases. Previous Lecture. 4.1 Multiresolution Analysis. 4 Shape-based Features. 4.1 Multiresolution Analysis Previous Lecture Multimedia Databases Texture-Based Image Retrieval Low Level Features Tamura Measure, Random Field Model High-Level Features Fourier-Transform, Wavelets Wolf-Tilo Balke Silviu Homoceanu

More information

Multimedia Databases. Wolf-Tilo Balke Philipp Wille Institut für Informationssysteme Technische Universität Braunschweig

Multimedia Databases. Wolf-Tilo Balke Philipp Wille Institut für Informationssysteme Technische Universität Braunschweig Multimedia Databases Wolf-Tilo Balke Philipp Wille Institut für Informationssysteme Technische Universität Braunschweig http://www.ifis.cs.tu-bs.de 4 Previous Lecture Texture-Based Image Retrieval Low

More information

Binary Image Analysis

Binary Image Analysis Binary Image Analysis Binary image analysis consists of a set of image analysis operations that are used to produce or process binary images, usually images of 0 s and 1 s. 0 represents the background

More information

18.085, PROBLEM SET 1 SOLUTIONS

18.085, PROBLEM SET 1 SOLUTIONS 18.085, PROBLEM SET 1 SOLUTIONS Question 1. (20 pts.) Using odd values of n, the error is on the order of machine precision, about 10 16, for smaller values of n. We expect this because we are doing finite

More information

Communication Engineering Prof. Surendra Prasad Department of Electrical Engineering Indian Institute of Technology, Delhi

Communication Engineering Prof. Surendra Prasad Department of Electrical Engineering Indian Institute of Technology, Delhi Communication Engineering Prof. Surendra Prasad Department of Electrical Engineering Indian Institute of Technology, Delhi Lecture - 41 Pulse Code Modulation (PCM) So, if you remember we have been talking

More information

Multimedia Databases. 4 Shape-based Features. 4.1 Multiresolution Analysis. 4.1 Multiresolution Analysis. 4.1 Multiresolution Analysis

Multimedia Databases. 4 Shape-based Features. 4.1 Multiresolution Analysis. 4.1 Multiresolution Analysis. 4.1 Multiresolution Analysis 4 Shape-based Features Multimedia Databases Wolf-Tilo Balke Silviu Homoceanu Institut für Informationssysteme Technische Universität Braunschweig http://www.ifis.cs.tu-bs.de 4 Multiresolution Analysis

More information

CITS 4402 Computer Vision

CITS 4402 Computer Vision CITS 4402 Computer Vision Prof Ajmal Mian Adj/A/Prof Mehdi Ravanbakhsh, CEO at Mapizy (www.mapizy.com) and InFarm (www.infarm.io) Lecture 04 Greyscale Image Analysis Lecture 03 Summary Images as 2-D signals

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

CITS 4402 Computer Vision

CITS 4402 Computer Vision CITS 4402 Computer Vision A/Prof Ajmal Mian Adj/A/Prof Mehdi Ravanbakhsh Lecture 06 Object Recognition Objectives To understand the concept of image based object recognition To learn how to match images

More information

Algorithm User Guide:

Algorithm User Guide: Algorithm User Guide: Nuclear Quantification Use the Aperio algorithms to adjust (tune) the parameters until the quantitative results are sufficiently accurate for the purpose for which you intend to use

More information

GRE Quantitative Reasoning Practice Questions

GRE Quantitative Reasoning Practice Questions GRE Quantitative Reasoning Practice Questions y O x 7. The figure above shows the graph of the function f in the xy-plane. What is the value of f (f( ))? A B C 0 D E Explanation Note that to find f (f(

More information

Outline. Math Numerical Analysis. Intermediate Value Theorem. Lecture Notes Zeros and Roots. Joseph M. Mahaffy,

Outline. Math Numerical Analysis. Intermediate Value Theorem. Lecture Notes Zeros and Roots. Joseph M. Mahaffy, Outline Math 541 - Numerical Analysis Lecture Notes Zeros and Roots Joseph M. Mahaffy, jmahaffy@mail.sdsu.edu Department of Mathematics and Statistics Dynamical Systems Group Computational Sciences Research

More information

Computer Vision Group Prof. Daniel Cremers. 10a. Markov Chain Monte Carlo

Computer Vision Group Prof. Daniel Cremers. 10a. Markov Chain Monte Carlo Group Prof. Daniel Cremers 10a. Markov Chain Monte Carlo Markov Chain Monte Carlo In high-dimensional spaces, rejection sampling and importance sampling are very inefficient An alternative is Markov Chain

More information

STAT2201 Assignment 3 Semester 1, 2017 Due 13/4/2017

STAT2201 Assignment 3 Semester 1, 2017 Due 13/4/2017 Class Example 1. Single Sample Descriptive Statistics (a) Summary Statistics and Box-Plots You are working in factory producing hand held bicycle pumps and obtain a sample of 174 bicycle pump weights in

More information

Math Numerical Analysis

Math Numerical Analysis Math 541 - Numerical Analysis Lecture Notes Zeros and Roots Joseph M. Mahaffy, jmahaffy@mail.sdsu.edu Department of Mathematics and Statistics Dynamical Systems Group Computational Sciences Research Center

More information

[POLS 8500] Review of Linear Algebra, Probability and Information Theory

[POLS 8500] Review of Linear Algebra, Probability and Information Theory [POLS 8500] Review of Linear Algebra, Probability and Information Theory Professor Jason Anastasopoulos ljanastas@uga.edu January 12, 2017 For today... Basic linear algebra. Basic probability. Programming

More information

ECE Digital Image Processing and Introduction to Computer Vision

ECE Digital Image Processing and Introduction to Computer Vision ECE592-064 Digital Image Processing and Introduction to Computer Vision Depart. of ECE, NC State University Instructor: Tianfu (Matt) Wu Spring 2017 Outline Recap, image degradation / restoration Template

More information

15th Bay Area Mathematical Olympiad. BAMO Exam. February 26, Solutions to BAMO-8 and BAMO-12 Problems

15th Bay Area Mathematical Olympiad. BAMO Exam. February 26, Solutions to BAMO-8 and BAMO-12 Problems 15th Bay Area Mathematical Olympiad BAMO Exam February 26, 2013 Solutions to BAMO-8 and BAMO-12 Problems 1 How many different sets of three points in this equilateral triangular grid are the vertices of

More information

Lecture 7 Random Signal Analysis

Lecture 7 Random Signal Analysis Lecture 7 Random Signal Analysis 7. Introduction to Probability 7. Amplitude Distributions 7.3 Uniform, Gaussian, and Other Distributions 7.4 Power and Power Density Spectra 7.5 Properties of the Power

More information

Boosting: Algorithms and Applications

Boosting: Algorithms and Applications Boosting: Algorithms and Applications Lecture 11, ENGN 4522/6520, Statistical Pattern Recognition and Its Applications in Computer Vision ANU 2 nd Semester, 2008 Chunhua Shen, NICTA/RSISE Boosting Definition

More information

Department of Electrical Engineering, Polytechnic University, Brooklyn Fall 05 EL DIGITAL IMAGE PROCESSING (I) Final Exam 1/5/06, 1PM-4PM

Department of Electrical Engineering, Polytechnic University, Brooklyn Fall 05 EL DIGITAL IMAGE PROCESSING (I) Final Exam 1/5/06, 1PM-4PM Department of Electrical Engineering, Polytechnic University, Brooklyn Fall 05 EL512 --- DIGITAL IMAGE PROCESSING (I) Y. Wang Final Exam 1/5/06, 1PM-4PM Your Name: ID Number: Closed book. One sheet of

More information

Support Vector Machines. CSE 4309 Machine Learning Vassilis Athitsos Computer Science and Engineering Department University of Texas at Arlington

Support Vector Machines. CSE 4309 Machine Learning Vassilis Athitsos Computer Science and Engineering Department University of Texas at Arlington Support Vector Machines CSE 4309 Machine Learning Vassilis Athitsos Computer Science and Engineering Department University of Texas at Arlington 1 A Linearly Separable Problem Consider the binary classification

More information

Chapter 2. Polynomial and Rational Functions. 2.3 Polynomial Functions and Their Graphs. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Chapter 2. Polynomial and Rational Functions. 2.3 Polynomial Functions and Their Graphs. Copyright 2014, 2010, 2007 Pearson Education, Inc. Chapter Polynomial and Rational Functions.3 Polynomial Functions and Their Graphs Copyright 014, 010, 007 Pearson Education, Inc. 1 Objectives: Identify polynomial functions. Recognize characteristics

More information

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10)

ELEC Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10) ELEC 2200-002 Digital Logic Circuits Fall 2014 Sequential Circuits (Chapter 6) Finite State Machines (Ch. 7-10) Vishwani D. Agrawal James J. Danaher Professor Department of Electrical and Computer Engineering

More information

Right-truncated data. STAT474/STAT574 February 7, / 44

Right-truncated data. STAT474/STAT574 February 7, / 44 Right-truncated data For this data, only individuals for whom the event has occurred by a given date are included in the study. Right truncation can occur in infectious disease studies. Let T i denote

More information

Corner. Corners are the intersections of two edges of sufficiently different orientations.

Corner. Corners are the intersections of two edges of sufficiently different orientations. 2D Image Features Two dimensional image features are interesting local structures. They include junctions of different types like Y, T, X, and L. Much of the work on 2D features focuses on junction L,

More information

Representing regions in 2 ways:

Representing regions in 2 ways: Representing regions in 2 ways: Based on their external characteristics (its boundary): Shape characteristics Based on their internal characteristics (its region): Both Regional properties: color, texture,

More information

18.085: Summer 2016 Due: 3 August 2016 (in class) Problem Set 8

18.085: Summer 2016 Due: 3 August 2016 (in class) Problem Set 8 Problem Set 8 Unless otherwise specified, you may use MATLAB to assist with computations. provide a print-out of the code used and its output with your assignment. Please 1. More on relation between Fourier

More information

Singular Value Decompsition

Singular Value Decompsition Singular Value Decompsition Massoud Malek One of the most useful results from linear algebra, is a matrix decomposition known as the singular value decomposition It has many useful applications in almost

More information

Note: An algebraic expression is made of one or more terms. The terms in an algebraic expression are connected with either addition or subtraction.

Note: An algebraic expression is made of one or more terms. The terms in an algebraic expression are connected with either addition or subtraction. .4 Combining Like Terms Term A term is a single number or variable, or it can be a product of a number (called its coefficient) and one or more variables. Examples of terms:, x, a, xy, 4 a bc, 5, xyz coefficient

More information

Ritangle - an A Level Maths Competition 2016

Ritangle - an A Level Maths Competition 2016 Ritangle - an A Level Maths Competition 2016 Questions and Answers - 12-12-16 A. The Taster Questions Answer: this sequence cycles. The first eight terms are, r, i, t, a, n, g, l, e, 1 while the ninth

More information

Deformation and Viewpoint Invariant Color Histograms

Deformation and Viewpoint Invariant Color Histograms 1 Deformation and Viewpoint Invariant Histograms Justin Domke and Yiannis Aloimonos Computer Vision Laboratory, Department of Computer Science University of Maryland College Park, MD 274, USA domke@cs.umd.edu,

More information

Introduction to Machine Learning Prof. Sudeshna Sarkar Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Introduction to Machine Learning Prof. Sudeshna Sarkar Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Introduction to Machine Learning Prof. Sudeshna Sarkar Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Module 2 Lecture 05 Linear Regression Good morning, welcome

More information

Chapter y. 8. n cd (x y) 14. (2a b) 15. (a) 3(x 2y) = 3x 3(2y) = 3x 6y. 16. (a)

Chapter y. 8. n cd (x y) 14. (2a b) 15. (a) 3(x 2y) = 3x 3(2y) = 3x 6y. 16. (a) Chapter 6 Chapter 6 opener A. B. C. D. 6 E. 5 F. 8 G. H. I. J.. 7. 8 5. 6 6. 7. y 8. n 9. w z. 5cd.. xy z 5r s t. (x y). (a b) 5. (a) (x y) = x (y) = x 6y x 6y = x (y) = (x y) 6. (a) a (5 a+ b) = a (5

More information

To Find the Product of Monomials. ax m bx n abx m n. Let s look at an example in which we multiply two monomials. (3x 2 y)(2x 3 y 5 )

To Find the Product of Monomials. ax m bx n abx m n. Let s look at an example in which we multiply two monomials. (3x 2 y)(2x 3 y 5 ) 5.4 E x a m p l e 1 362SECTION 5.4 OBJECTIVES 1. Find the product of a monomial and a polynomial 2. Find the product of two polynomials 3. Square a polynomial 4. Find the product of two binomials that

More information

Polynomials. Lesson 6

Polynomials. Lesson 6 Polynomials Lesson 6 MFMP Foundations of Mathematics Unit Lesson 6 Lesson Six Concepts Overall Expectations Simplify numerical and polynomial expressions in one variable, and solve simple first-degree

More information

The Design Procedure. Output Equation Determination - Derive output equations from the state table

The Design Procedure. Output Equation Determination - Derive output equations from the state table The Design Procedure Specification Formulation - Obtain a state diagram or state table State Assignment - Assign binary codes to the states Flip-Flop Input Equation Determination - Select flipflop types

More information

Today s class. Constrained optimization Linear programming. Prof. Jinbo Bi CSE, UConn. Numerical Methods, Fall 2011 Lecture 12

Today s class. Constrained optimization Linear programming. Prof. Jinbo Bi CSE, UConn. Numerical Methods, Fall 2011 Lecture 12 Today s class Constrained optimization Linear programming 1 Midterm Exam 1 Count: 26 Average: 73.2 Median: 72.5 Maximum: 100.0 Minimum: 45.0 Standard Deviation: 17.13 Numerical Methods Fall 2011 2 Optimization

More information

Introduction to Measurement Physics 114 Eyres

Introduction to Measurement Physics 114 Eyres 1 Introduction to Measurement Physics 114 Eyres 6/5/2016 Module 1: Measurement 1 2 Significant Figures Count all non-zero digits Count zeros between non-zero digits Count zeros after the decimal if also

More information

Lab 2: Static Response, Cantilevered Beam

Lab 2: Static Response, Cantilevered Beam Contents 1 Lab 2: Static Response, Cantilevered Beam 3 1.1 Objectives.......................................... 3 1.2 Scalars, Vectors and Matrices (Allen Downey)...................... 3 1.2.1 Attribution.....................................

More information

Lecture 04 Image Filtering

Lecture 04 Image Filtering Institute of Informatics Institute of Neuroinformatics Lecture 04 Image Filtering Davide Scaramuzza 1 Lab Exercise 2 - Today afternoon Room ETH HG E 1.1 from 13:15 to 15:00 Work description: your first

More information

Numerical Analysis. Carmen Arévalo Lund University Arévalo FMN011

Numerical Analysis. Carmen Arévalo Lund University Arévalo FMN011 Numerical Analysis Carmen Arévalo Lund University carmen@maths.lth.se Discrete cosine transform C = 2 n 1 2 1 2 1 2 cos π 2n cos 3π 2n cos (2n 1)π 2n cos 6π 2n cos 2(2n 1)π 2n cos 2π 2n... cos (n 1)π 2n

More information

Intensity Analysis of Spatial Point Patterns Geog 210C Introduction to Spatial Data Analysis

Intensity Analysis of Spatial Point Patterns Geog 210C Introduction to Spatial Data Analysis Intensity Analysis of Spatial Point Patterns Geog 210C Introduction to Spatial Data Analysis Chris Funk Lecture 4 Spatial Point Patterns Definition Set of point locations with recorded events" within study

More information

Algebraic Expressions

Algebraic Expressions ALGEBRAIC EXPRESSIONS 229 Algebraic Expressions Chapter 12 12.1 INTRODUCTION We have already come across simple algebraic expressions like x + 3, y 5, 4x + 5, 10y 5 and so on. In Class VI, we have seen

More information

Similar Shapes and Gnomons

Similar Shapes and Gnomons Similar Shapes and Gnomons May 12, 2013 1. Similar Shapes For now, we will say two shapes are similar if one shape is a magnified version of another. 1. In the picture below, the square on the left is

More information

Introduction to Machine Learning CMU-10701

Introduction to Machine Learning CMU-10701 Introduction to Machine Learning CMU-10701 23. Decision Trees Barnabás Póczos Contents Decision Trees: Definition + Motivation Algorithm for Learning Decision Trees Entropy, Mutual Information, Information

More information

Summary of Derivative Tests

Summary of Derivative Tests Summary of Derivative Tests Note that for all the tests given below it is assumed that the function f is continuous. Critical Numbers Definition. A critical number of a function f is a number c in the

More information

1 Normal Distribution.

1 Normal Distribution. Normal Distribution.. Introduction A Bernoulli trial is simple random experiment that ends in success or failure. A Bernoulli trial can be used to make a new random experiment by repeating the Bernoulli

More information

= 9 = x + 8 = = -5x 19. For today: 2.5 (Review) and. 4.4a (also review) Objectives:

= 9 = x + 8 = = -5x 19. For today: 2.5 (Review) and. 4.4a (also review) Objectives: Math 65 / Notes & Practice #1 / 20 points / Due. / Name: Home Work Practice: Simplify the following expressions by reducing the fractions: 16 = 4 = 8xy =? = 9 40 32 38x 64 16 Solve the following equations

More information

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Part I: Basics MATLAB Environment Getting Help Variables Vectors, Matrices, and

More information

YEAR 9 ENTRANCE AND SCHOLARSHIP EXAMINATION Mathematics

YEAR 9 ENTRANCE AND SCHOLARSHIP EXAMINATION Mathematics YEAR 9 ENTRANCE AND SCHOLARSHIP EXAMINATION Mathematics Specimen Paper D Time allowed for this paper: 1 hour 30 mins Instructions Attempt all the questions. Calculators may be used. Show all your working

More information

Detectors part II Descriptors

Detectors part II Descriptors EECS 442 Computer vision Detectors part II Descriptors Blob detectors Invariance Descriptors Some slides of this lectures are courtesy of prof F. Li, prof S. Lazebnik, and various other lecturers Goal:

More information

Computational Statistics with Application to Bioinformatics

Computational Statistics with Application to Bioinformatics Computational Statistics with Application to Bioinformatics Prof. William H. Press Spring Term, 2008 The University of Texas at Austin Unit 6: Understanding Distributions Known Only Empirically The University

More information

Detecting Dark Matter Halos Sam Beder, Brie Bunge, Adriana Diakite December 14, 2012

Detecting Dark Matter Halos Sam Beder, Brie Bunge, Adriana Diakite December 14, 2012 Detecting Dark Matter Halos Sam Beder, Brie Bunge, Adriana Diakite December 14, 2012 Introduction Dark matter s gravitational pull affects the positions of galaxies in the universe. If galaxies were circular,

More information

Order of convergence. MA3232 Numerical Analysis Week 3 Jack Carl Kiefer ( ) Question: How fast does x n

Order of convergence. MA3232 Numerical Analysis Week 3 Jack Carl Kiefer ( ) Question: How fast does x n Week 3 Jack Carl Kiefer (94-98) Jack Kiefer was an American statistician. Much of his research was on the optimal design of eperiments. However, he also made significant contributions to other areas of

More information

Lecture 7: Edge Detection

Lecture 7: Edge Detection #1 Lecture 7: Edge Detection Saad J Bedros sbedros@umn.edu Review From Last Lecture Definition of an Edge First Order Derivative Approximation as Edge Detector #2 This Lecture Examples of Edge Detection

More information

6.867 Machine Learning

6.867 Machine Learning 6.867 Machine Learning Problem Set 2 Due date: Wednesday October 6 Please address all questions and comments about this problem set to 6867-staff@csail.mit.edu. You will need to use MATLAB for some of

More information

DSP Applications for Wireless Communications: Linear Equalisation of MIMO Channels

DSP Applications for Wireless Communications: Linear Equalisation of MIMO Channels DSP Applications for Wireless Communications: Dr. Waleed Al-Hanafy waleed alhanafy@yahoo.com Faculty of Electronic Engineering, Menoufia Univ., Egypt Digital Signal Processing (ECE407) Lecture no. 5 August

More information

ECE Lecture #10 Overview

ECE Lecture #10 Overview ECE 450 - Lecture #0 Overview Introduction to Random Vectors CDF, PDF Mean Vector, Covariance Matrix Jointly Gaussian RV s: vector form of pdf Introduction to Random (or Stochastic) Processes Definitions

More information

Tu: 9/3/13 Math 471, Fall 2013, Section 001 Lecture 1

Tu: 9/3/13 Math 471, Fall 2013, Section 001 Lecture 1 Tu: 9/3/13 Math 71, Fall 2013, Section 001 Lecture 1 1 Course intro Notes : Take attendance. Instructor introduction. Handout : Course description. Note the exam days (and don t be absent). Bookmark the

More information

8 The SVD Applied to Signal and Image Deblurring

8 The SVD Applied to Signal and Image Deblurring 8 The SVD Applied to Signal and Image Deblurring We will discuss the restoration of one-dimensional signals and two-dimensional gray-scale images that have been contaminated by blur and noise. After an

More information

MAC 1105 Lecture Outlines for Ms. Blackwelder s lecture classes

MAC 1105 Lecture Outlines for Ms. Blackwelder s lecture classes MAC 1105 Lecture Outlines for Ms. Blackwelder s lecture classes These notes are prepared using software that is designed for typing mathematics; it produces a pdf output. Alternative format is not available.

More information

Companion. Jeffrey E. Jones

Companion. Jeffrey E. Jones MATLAB7 Companion 1O11OO1O1O1OOOO1O1OO1111O1O1OO 1O1O1OO1OO1O11OOO1O111O1O1O1O1 O11O1O1O11O1O1O1O1OO1O11O1O1O1 O1O1O1111O11O1O1OO1O1O1O1OOOOO O1111O1O1O1O1O1O1OO1OO1OO1OOO1 O1O11111O1O1O1O1O Jeffrey E.

More information

CSCI 315: Artificial Intelligence through Deep Learning

CSCI 315: Artificial Intelligence through Deep Learning CSCI 35: Artificial Intelligence through Deep Learning W&L Fall Term 27 Prof. Levy Convolutional Networks http://wernerstudio.typepad.com/.a/6ad83549adb53ef53629ccf97c-5wi Convolution: Convolution is

More information

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP In this laboratory session we will learn how to. Use MATLAB solvers for solving scalar IVP 2. Use MATLAB solvers for solving higher order ODEs and

More information

ORF 523 Final Exam, Spring 2016

ORF 523 Final Exam, Spring 2016 Name: Princeton University ORF 523 Final Exam, Spring 2016 Thursday, May 5, 9am, to Tuesday, May 10, 11am Instructor: A.A. Ahmadi AI: G. Hall 1. Please write out and sign the following pledge on top of

More information