• 沒有找到結果。

Computer Vision Homework 5

N/A
N/A
Protected

Academic year: 2022

Share "Computer Vision Homework 5"

Copied!
8
0
0

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

全文

(1)

Computer Vision

Homework 5

Gray Morphology

November 17, 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.

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.

Code Fragment for Dilation

This method conducts the basic gray dilation morphological operation.

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++ )

(3)

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();

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 Erosion

This method conducts the basic erosion morphological operation.

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

IMAGE *temp = new IMAGE;

int tmp;

int min;

GetGrayMorphMaskBoundary( m );

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( min = 255, d = m->min_y+22; d <= m->max_y+22; d++ ) for( c = m->min_x+22; c <= m->max_x+22; c++ )

{

(4)

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

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

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

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

if( min > tmp ) min = tmp;

} }

if( min < 0 ) min = 0;

else if( min > 255 ) min = 255;

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

}

MainForm->ProgressBar1->Hide();

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

delete temp;

return;

}

Code Fragment for Locking Morph Kernel

This method will find out the size of the kernel for morphing. This can reduce computational time, since 45 by 45 kernel may not be used most of the time.

void __fastcall IMAGE::GetGrayMorphMaskBoundary( GMORPHOLOGY *m ) { int a, b;

m->max_x = 0;

m->max_y = 0;

m->min_x = 45;

m->min_y = 45;

for( b = 0; b < 45; b++ ) for( a = 0; a < 45; a++ ) if( m->selected[b][a] ) {

if( a < m->min_x ) m->min_x = a;

else if( a > m->max_x ) m->max_x = a;

if( b < m->min_y ) m->min_y = b;

else if( b > m->max_y ) m->max_y = b;

}

m->min_x -= 22;

m->max_x -= 22;

m->min_y -= 22;

m->max_y -= 22;

(5)

return;

}

Code Fragment for Opening

The opening operation can be done by first applying the erosion operation and then followed by dilation operation.

void __fastcall TMainForm::Opening2Click(TObject *Sender) { TMDIChild *MDI;

MDI = ( TMDIChild * )MainForm->ActiveMDIChild;

MDI->image->GrayErosion( &gray_ero );

MDI->image->GrayDilation( &gray_dil );

MDI->ShowImage();

}

Code Fragment for Closing

The closing operation can be done by first applying the dilation operation and then followed by erosion operation.

void __fastcall TMainForm::Closing2Click(TObject *Sender) { TMDIChild *MDI;

MDI = ( TMDIChild * )MainForm->ActiveMDIChild;

MDI->image->GrayDilation( &gray_dil );

MDI->image->GrayErosion( &gray_ero );

MDI->ShowImage();

}

(6)

Original Image: Lena

This is the original image of Lena with histogram.

Dilation/Erosion Kernel ( Octagon )

This shape can be obtained by first pressing the “Octagon” button, and then

select the “Erosion” radio button. Finally, press the “Copy Dilation Kernel” button

beside the radio button set.

(7)

Dilation of Lena ( with Octagon Kernel )

After assigning the kernel, select “Dilation” from the “Gray Morphology” menu.

Erosion of Lena ( with Octagon Kernel )

Erosion is done the same way as how dilation was selected.

(8)

Opening of Lena ( with Octagon Kernel )

Closing of Lena ( with Octagon Kernel )

參考文獻

相關文件

In computer science, the treap and the randomized binary search tree are two closely related forms of binary search tree data structures that maintain a dynamic set of ordered keys

• Richard Szeliski, Image Alignment and Stitching: A Tutorial, Foundations and Trends in Computer Graphics and Computer Vision, 2(1):1-104, December 2006. Szeliski

• Richard Szeliski, Image Alignment and Stitching: A Tutorial, Foundations and Trends in Computer Graphics and Computer Vision, 2(1):1-104, December 2006. Szeliski

Finally, we train cascade classifier with adaptive boosting [3] and Local Binary Pattern (LBP) [5], and detect pin defect to reduce false alarm rate and miss detection rate and

Calculate Yokoi connectivity number and conducts image thinning.. Display binary image in ASCII ‘*’ symbols or in Yokoi connectivity

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

• Steady state: light is assumed to have reached equilibrium so its radiance distribution isn’t equilibrium, so its radiance distribution isn t changing over time.. •

(1) Show the truth table of a function that outputs a 1 whenever the 4-bit input is divisible by 4, where the input is treated as a 4-bit unsigned binary integer.. (2) Derive