• 沒有找到結果。

Computer Vision Homework 8

N/A
N/A
Protected

Academic year: 2022

Share "Computer Vision Homework 8"

Copied!
20
0
0

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

全文

(1)

Computer Vision

Homework 8

Noise Cleaning

December 8, 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.

13. Conducts binary image thinning operation.

14. Adding Gaussian noise and salt & pepper to the image.

15. Dynamic assignment of filtering kernel.

16. Conducts box filter and mean filter.

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.

Conclusions of this Work

These results have been evaluated visually and also by SNR ratio.

1. The box filter works better than the median filter on Gaussian noise.

2. The median filter works better that box filter on salt & pepper noise.

(3)

Code Fragment for Adding Gaussian noise

This functions adds Gaussian noise to the image.

void __fastcall IMAGE::GaussianNoise( int amplitude ) { int a, b;

randomize();

MainForm->ProgressBar1->Show();

MainForm->ProgressBar1->Max = sizey;

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

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

data[b][a] += ( char )( RandG( 0.0, 1.0 ) * amplitude );

MainForm->ProgressBar1->Hide();

}

Code Fragment for Adding Salt & Pepper Noise

This functions adds salt & pepper noise to the image. The noise rate is the combined percentage of salt noise and pepper noise.

void __fastcall IMAGE::SaltPepperNoise( int salt, int pepper ) { int a, b;

int val;

randomize();

MainForm->ProgressBar1->Show();

MainForm->ProgressBar1->Max = sizey;

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

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

{

val = random( 100 );

if( val < salt ) data[b][a] = 255;

if( val >= pepper ) data[b][a] = 0;

}

MainForm->ProgressBar1->Hide();

}

Code Fragment for Filter Preprocessing

This function locks the orientation of the filter and determines the filter size.

void __fastcall IMAGE::GetBoxFilterMaskBoundary( BOXFILTER *m ) { int a, b;

m->max_x = 0;

(4)

m->max_y = 0;

m->min_x = 45;

m->min_y = 45;

for( b = 1; b < 46; b++ ) for( a = 1; a < 46; a++ )

m->data[b-1][a-1] = atoi( Form7->StringGrid1->Cells[b][a].c_str() );

for( b = 0; b < 45; b++ ) for( a = 0; a < 45; a++ ) if( m->data[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;

return;

}

Code Fragment for Box Filtering

This function performs box filtering on the image.

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

int avg;

int value;

IMAGE *temp = new IMAGE;

GetBoxFilterMaskBoundary( m );

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

MainForm->ProgressBar1->Show();

MainForm->ProgressBar1->Max = sizey;

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

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

{

avg = 0;

value = 0;

for( d = m->min_y+22; d <= m->max_y+22; d++ ) for( c = m->min_x+22; c <= m->max_x+22; c++ ) {

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

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

avg += m->data[d][c];

if( m->data[d][c] )

value += ( data[b+d-22][a+c-22] * m->data[d][c] );

}

temp->data[b][a] = ( char )( value / avg );

(5)

}

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 Median Filtering

This function performs median filtering on the image.

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

int avg;

int value;

int sort[45*45];

IMAGE *temp = new IMAGE;

GetBoxFilterMaskBoundary( m );

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

MainForm->ProgressBar1->Show();

MainForm->ProgressBar1->Max = sizey;

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

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

{

value = 0;

for( d = m->min_y+22; d <= m->max_y+22; d++ ) for( c = m->min_x+22; c <= m->max_x+22; c++ ) {

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

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

if( m->data[d][c] )

sort[value++] = data[b+d-22][a+c-22];

}

for( c = 0; c < value - 1; c++ ) for( d = c + 1; d < value; d++ ) if( sort[c] > sort[d] ) {

avg = sort[c];

sort[c] = sort[d];

sort[d] = avg;

}

temp->data[b][a] = ( char ) sort[( value - 1) / 2];

}

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;

}

(6)

Original Image: Lena

This is the original image of Lena with histogram.

Salt & Pepper Noise Added to Image

Sample image for demonstrating how the filtering mask is assigned.

(7)

Salt & Pepper Noise Added to Image

Salt rate = 5%, pepper rate = 5%, SNR = -2.085.

Salt & Pepper Noise Added to Image

Salt rate = 10%, pepper rate = 10%, SNR = -3.472.

(8)

Gaussian Noise Added to Image

Amplitude = 10, SNR = -0.172.

Gaussian Noise Added to Image

Amplitude = 30, SNR = -1.286.

(9)

Box Filter on Salt & Pepper Image

Box filter size = 3x3, salt rate = 5%, pepper rate = 5%, SNR = 0.598.

Box Filter on Salt & Pepper Image

Box filter size = 3x3, salt rate = 10%, pepper rate = 10%, SNR = 1.036.

(10)

Box Filter on Gaussian Image

Box filter size = 3x3, amplitude = 10, SNR = 0.038.

Box Filter on Gaussian Image

Box filter size = 3x3, amplitude = 30, SNR = -1.286.

(11)

Box Filter on Salt & Pepper Image

Box filter size = 5x5, salt rate = 5%, pepper rate = 5%, SNR = 1.053.

Box Filter on Salt & Pepper Image

Box filter size = 5x5, salt rate = 10%, pepper rate = 10%, SNR = 1.870.

(12)

Box Filter on Gaussian Image

Box filter size = 5x5, amplitude = 10, SNR = 0.333.

Box Filter on Gaussian Image

Box filter size = 5x5, amplitude = 30, SNR = 1.343.

(13)

Median Filter on Salt & Pepper Image

Median filter size = 3x3, salt rate = 5%, pepper rate = 5%, SNR = 0.045.

Median Filter on Salt & Pepper Image

Median filter size = 3x3, salt rate = 10%, pepper rate = 10%, SNR = 0.002.

(14)

Median Filter on Gaussian Image

Median filter size = 3x3, amplitude = 10, SNR = 0.064.

Median Filter on Gaussian Image

Median filter size = 3x3, amplitude = 30, SNR = 0.213.

(15)

Median Filter on Salt & Pepper Image

Median filter size = 5x5, salt rate = 5%, pepper rate = 5%, SNR = 0.102.

Median Filter on Salt & Pepper Image

Median filter size = 5x5, salt rate = 10%, pepper rate = 10%, SNR = 0.104.

(16)

Median Filter on Gaussian Image

Median filter size = 5x5, amplitude = 10, SNR = 0.165.

Median Filter on Gaussian Image

Median filter size = 5x5, amplitude = 30, SNR = 0.513.

(17)

Opening and Closing on Salt & Pepper Image

Salt rate 5%, Pepper rate 5%, octagon kernel opening - closing, SNR = -0.684.

Opening and Closing on Salt & Pepper Image

Salt rate 10%, pepper rate 10%, octagon kernel opening - closing, SNR = -2.813.

(18)

Opening and Closing on Gaussian Image

Amplitude 10, octagon kernel opening - closing, SNR = 0.170.

Opening and Closing on Gaussian Image

Amplitude 30, octagon kernel opening - closing, SNR = 0.957.

(19)

Closing and Opening on Salt & Pepper Image

Salt rate 5%, Pepper rate 5%, octagon kernel closing - opening, SNR = -0.187.

Closing and Opening on Salt & Pepper Image

Salt rate 10%, pepper rate 10%, octagon kernel closing - opening, SNR = -2.897.

(20)

Closing and Opening on Gaussian Image

Amplitude 10, octagon kernel closing - opening, SNR = 0.268.

Closing and Opening on Gaussian Image

Amplitude 30, octagon kernel closing - opening, SNR = 1.069.

參考文獻

相關文件

4.1.2 Overfitting and underfitting 4.1.3 Robust data fitting... 4.1.0 Scattered

• Since successive samples are correlated, the Markov chain may have to be run for a considerable time in order to generate samples that are effectively independent samples from p(x).

• Can be applied to all the latent variable models including factor analysis, probabilistic PCA, mixture of factor analyzers, mixture of probabilistic PCA, mixture of Gaussians, etc..

• 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

Tsung-Min Hwang, Wei-Cheng Wang and Weichung Wang, Numerical schemes for three dimensional irregular shape quantum dots over curvilinear coordinate systems, accepted for publication

● develop teachers’ ability to identify opportunities for students to connect their learning in English lessons (e.g. reading strategies and knowledge of topics) to their experiences

• Emergent Z_k 1-form &amp; 2-form symmetry. BF theory