• 沒有找到結果。

Computer Vision Homework 6

N/A
N/A
Protected

Academic year: 2022

Share "Computer Vision Homework 6"

Copied!
10
0
0

加載中.... (立即查看全文)

全文

(1)

Computer Vision

Homework 6

Yokoi Connectivity Number

November 23, 1998

R87526001

許為元 William W. Hsu

(2)

Programming tool:

This program was developed with Borland C++ Builder 3.0 on Windows 98.

This program has the following functions:

1. Dynamic histogram display and multi-image display.

2. Dynamic information (pixel, histogram) update status bar.

3. Binarizing an image.

4. Conducting histogram equalization.

5. Inverting an image.

6. Dynamic binary morphological operation kernel assignment.

7. Conducting binary morphological operations: dilation, erosion, opening, closing and hit-and-miss.

8. Dynamic gray morphological operation kernel assignment with color depth showing its associated value.

9. Conducting gray morphological operations: dilation, erosion, opening and closing.

10. Down sampling the image into smaller sizes.

11. Calculate Yokoi connectivity number.

12. Display binary image in ASCII ‘*’ symbols or in Yokoi connectivity numbers.

The format of the data files used in this program ( *.raw format ) is as follows:

1. The first 4 bytes specify the image height.

2. The second 4 bytes specify the image width.

3. The following 512*512 bytes specifies the image data in gray level.

(3)

2

Code Fragment for Down Sampling

This method can shrink the image to 1/2, 1/4, 1/8, 1/16, and 1/32 of the original size. The algorithm used is averaging algorithm, i.e., when shrinking a 512 by 512 image into a 64 by 64 image, which is 1/8 of the original size, we take 8 by 8 blocks and use the average value of these 64 blocks for the pixel value of the down sampled image.

void __fastcall IMAGE::GrayDilation( GMORPHOLOGY *m ) { int a, b, c ,d;

IMAGE *temp = new IMAGE;

int tmp;

int max;

GMORPHOLOGY *x = new GMORPHOLOGY;

for( b = 0; b < 45; b++ ) for( a = 0; a < 45; a++ ) {

x->mask[b][a] = m->mask[a][b];

x->selected[b][a] = m->selected[a][b];

x->color[b][a] = m->color[a][b];

}

GetGrayMorphMaskBoundary( x );

for( a = 0; a < sizex; a++ ) for( b = 0; b < sizey; b++ ) temp->data[a][b] = 0;

MainForm->ProgressBar1->Show();

for( MainForm->ProgressBar1->Position = b = 0; b < sizey;

b++, MainForm->ProgressBar1->Position = b ) for( a = 0; a < sizex; a++ )

{

for( max = 0, d = x->min_y+22; d <= x->max_y+22; d++ ) for( c = x->min_x+22; c <= x->max_x+22; c++ ) {

if( b+d-22 >= sizey || b+d-22 < 0 ||

a+c-22 >= sizex || a+c-22 < 0 ) continue;

if( x->selected[d][c] ) {

tmp = data[b+d-22][a+c-22] + x->mask[d][c];

if( max < tmp ) max = tmp;

} }

if( max < 0 ) max = 0;

else if( max > 255 ) max = 255;

temp->data[b][a] = ( char ) max;

}

MainForm->ProgressBar1->Hide();

(4)

for( b = 0; b < sizey; b++ ) for( a = 0; a < sizex; a++ ) data[b][a] = temp->data[b][a];

delete temp;

delete x;

return;

}

Code Fragment for Calculating the Yokoi Connectivity Number

This method will calculate the Yokoi connectivity number of the binary image in 4–connected-neighbor mode.

void __fastcall IMAGE::Yokoi( void ) { int a, b, c;

char x[4];

int q;

int r;

const int val[4][3] = { { 1, 6, 2 },

{ 2, 7, 3 }, { 3, 8, 4 }, { 4, 5, 1 } };

for( b = 0; b < sizey; b++ ) for( a = 0; a < sizex; a++ ) {

if( !data[b][a] ) {

yokoi[b][a] = ' ';

continue;

}

for( c = 0; c < 4; c++ )

x[c] = function_h( a, b, val[c] );

q = 0;

r = 0;

for( c = 0; c < 4; c++ ) {

if( x[c] == 'q' ) q++;

else if( x[c] == 'r' ) r++;

}

if( r == 4 )

yokoi[b][a] = '5';

else

yokoi[b][a] = ( char )( '0' + q );

}

is_yokoi = true;

}

(5)

4

Code Fragment for H-Function

This is the h-function for finding the Yokoi connectivity number.

char __fastcall IMAGE::function_h( int x, int y, const int *val ) { int u, v;

const int neighbor[8][2] = {

{ 1, 0 }, { 0, -1 }, { -1, 0 }, { 0, 1 }, { 1, 1 }, { 1, -1 }, { -1, -1 }, { -1, 1 } };

int b[4], c;

b[0] = data[y][x];

for( c = 0; c < 3; c++ ) {

u = x + neighbor[val[c]-1][0];

v = y + neighbor[val[c]-1][1];

if( u < 0 || v < 0 || u >= sizex || v >= sizey ) b[c+1] = 0;

else

b[c+1] = data[v][u];

}

if( b[0] == b[1] ) {

if( ( b[0] == b[2] ) && ( b[0] == b[3] ) ) return 'r';

else

return 'q';

} else

return 's';

}

(6)

Original Image: Lena

This is the original image of Lena with histogram.

Down Sampled Image: Lena 64x64

This picture can be obtained by selecting the ‘Downsample’ option in the ‘Tools’

menu.

(7)

6

Binary Image of Lena 64x64

ASCII Plot Window of Lena 64x64

This tool can be enabled by selecting ‘Ascii Plot’ in the ‘Tools’ menu.

(8)

Yokoi Plot of Lena 64x64

(9)

8

Full ASCII Plot of Lena 64x64

******** ******************* ************ *

******* ***************** *************

******** ************ **** ************ *

******* ****** ** ************* *

******* * * ** *************

******* ** **** **************

******* ********** ***************

*** *** ** *********** ***************

** *** * ************* **************

* *** ************* *** ********

* *** ************** *** ******* * *** *************** *** ****** **

*** ***************** *** **** ***

*** * **** ************* *** *** ****

*** * *** *************** *** *** ****

*** ** * ******************** **** *****

*** * ********************* ****** ******

*** * ***************************** ******

**** ** ****************************** *******

**** ** ******************************* *******

**** *** ** **************************** ********

**** *** * ****** ******************* * *********

***** *** ****** * ********** * *********

**** **** * ** ********* ** *********

**** *** ********* *** **********

**** ** ******** ** **********

**** ** ********* * **********

**** ** *********** * ***********

**** ** ************* * ***********

**** * ************* ************

**** * **** ********* ************

**** * ****** ***** ************

**** ** *** *** *************

**** * *** * *** *************

**** ** *** ** *** ***** * *************

**** ** ************* * **************

**** * ** ************* * **************

**** * ************* * **************

**** * ** ******** **** * ***************

**** * ************ * ***************

**** * ****** *** ***************

**** * * *********** ***************

**** ** *********** ****************

**** ** *** **** *****************

**** ** *** **** *****************

**** *** *** ** *****************

**** * ******* *****************

**** ****** ******** ********

**** * ***** * ***** ******

**** * ******** * *****

* **** ********** **** ****

** ***** * ************ ****** ***

** **** * ************* ****** *****

** **** ************** ****** ****

** **** ** ************** ***** *****

** **** *************** ***** *****

* **** **************************

* **** **************** ********

* **** ***************** ****

* **** ****************** ***

* **** ****************** **

** *** ****************** * ****** ********************

****** ********************

(10)

Full Yokoi Plot of Lena 64x64

11111121 1211111111111111121 111111111111 0 1555551 15555555555111551 1155555555511 15555521 111555511111 1111 155555555551 0 1555551 111212 11 1555555555511 0 1555551 2 1 11 1555555555551 1555551 12 1111 15555555555511 1511151 1111551111 155555555555511 111 151 11 15555555511 155555555555511 21 151 0 1155555555111 15111155555511 2 151 1555555555511 151 15555511 1 151 15555555555511 151 1155551 1 151 155555555555511 151 115511 12 151 11111555555555511 151 1511 111 151 1 1111 1555555555551 151 151 1151 151 2 121 115555555555511 151 151 1551 151 22 1 11555555555555511151 1151 11551 151 2 115555555555555555551 111551 115551 151 2 11555555555555555555511155551 155551 1511 21 115555555555555555555555555551 1155551 1551 11 2215555555555555555555555555511 1555551 1551 111 22 1555111155555555555555555112 11555551 1551 151 1 115511 2111111155555555111 1 115555551 12551 151 121111 1 1555555111 0 155555551 1551 1521 0 11 115555111 21 155555551 1551 111 111555511 122 1155555551 1551 11 15555551 21 1555555551 1551 11 115555551 2 1555555551 1551 11 11555555511 2 11555555551 1551 12 1115555555551 1 15555555551 1551 1 1511155555551 115555555551 1551 0 1151 111155511 155555555551 1551 1 111121 15111 155555555551 1551 22 111 151 1155555555551 1551 2 121 1 151 1555555555551 1551 12 121 11 121 15111 1 1555555555551 1551 21 1111151115551 2 11555555555551 1551 0 22 1555555555551 2 15555555555551 1551 2 1555555111551 2 15555555555551 1551 0 22 11555551 1551 2 115555555555551 1551 1 155551222151 1 155555555555551 1551 1 155551 111 155555555555551 1551 1 1 15555111111 155555555555551 1551 22 15111111551 1155555555555551 1551 12 111 1511 11555555555555551 1551 11 121 1211 15555555555555551 1551 131 111 11 15555555555555551 1551 1 1111111 15555551115555551 1551 115551 21115551 15555111 1551 0 15551 2 11111 155511 1551 0 11555111 2 15511 1 1551 1555555111 2111 1511 22 15521 0 115555555511 155111 151 21 1551 0 1155555555551 155551 11111 11 1551 15555555555511 155511 1551 11 1551 11 15555555555551 15551 11551 12 1551 155555555555511 15551 15511 2 1551 15555555555555222115111551 2 1551 1155555555555551 11115511 2 1551 15555555555555511 1151 2 1551 115555555555555551 111 2 1151 155555555555555551 21 21 151 155555555555555551 1 111151 11555555555555555511 111111 11111111111111111111

參考文獻

相關文件

We propose a digital image stabilization algorithm based on an image composition technique using four source images.. By using image processing techniques, we are able to reduce

A calibration algorithm is developed to match the depth information, IR image information, and RGB image information of the Kinect, to improve the image quality in

Conducting binary morphological operations: dilation, erosion, opening, closing and hit-and-miss.. Dynamic gray morphological operation kernel assignment with color depth showing

In this research we successfully develop a hierarchical pyramid elliptical Hough transform algorithm for searching ellipses in 512×512 resolution image.. The computing complexity

From a visual comparison, we observe that based on the same demosaicing algorithm, the demosaiced images, which use the zoomed mosaic images created by our proposed zooming algorithm

[r]

[10%] Suppose that f and g are multiplicative

So we check derivative of f and g, the small one would correspond to graph (b) and the other to (c)(i.e.. Moreover, f is