Вы находитесь на странице: 1из 64

BAZE DE DATE I CUNOTINE

: ______________ , .
()

: ______________ , ..
()
: _______________
()

-2014


...............................................................................................................................3
...................................................................................................................................4
1. ..................................8
1.1 ...................................................................8
1.2 ..........................................................................................................11
1.3 ...................................................................14
1.4 - ...........19
2. ..............................................................................................22
2.1 ......................................................................................................................22
2.2 ........................................................................................24
2.3 , . .. .29
3. ........35
3.1 , ...............................35
3.2 ......35
3.3 ......................................................................................36
4. .............................................................................................56
..........................................................................................................................60
...............................................................62


64 , 25 , 15
.

,

.
,
.
, ,
.
, ,
.
.
,
.
, .

.
.
,
.
: , ,
, , ,


,
.
- - , , ,
,


:
, .
, , , ( ).

,
.
,
,
( ).
, ,
.
-
, .
,
.
.
.


.
, , .
.
, , ,
. ,
.
4

-
. ,
, ,
, , ,
.
, ,
, , ,
,
.
- . , ,
, ,
. , ,
, , ,
, ,
. .

,
, ,
.
, .
.
.

.
, ,
. ,
.
,
,

, .
.
,
, ,
..
. ,
, .
,
.
-
.


.

, , ,
, .
,
, , .., .
.

() -
, , ,
. (
)
, .
( , - ..)
.
( , ,
, ).

( ),
6

, ,

,
,
.
- , -
, -

, ,
.
,
(

), (
, ). , ,
,
.

-

.
, ,
.

. , ,
, ,
.

. ,
.

1.

. , ,
, .
: , , , .

.
.

,
.

, ,
. ,
. , ,
, , , , , .
,
:

1.1

f(m1 , m2), 0 # m1 # M1 - 1, 0 # m2 # # M2 - 1.
-
,
8

, - g(n1 , n2), 0 # n1 # N1 - 1, 0 # n2 # N2 - 1.
(),
,
.
,

() .
.
,

,
.
.

, , ,
.
[fmin , fmax]
( ).
"" .

g = af + b.
a, b ,
.
[gmin , gmax], ,
gmin = afmin = b,
gmax = afmax = b.
:

, ,
.

( , )
().
, ,
, .
(,
) ().

,

f0 - "" .

f0 .
( : , ,
. .).
-.
: f0 "". ,
, , , , -,
, -, ,
.
"", .
f0 ,
.

.1.1
10

, , , ,
,
.

. ,
, .
.

.
. "" ,
,
. , , "",
.

, ""
.
, "",
"" : ,
.
,
( ) ,

.

1.2
,

, - . ,
, .

.
11

1.2 ,
, , .

.1.2
,
.
,
, , .
.
, ,
,
, :
,
.

.1.3
, "-" ,
, , "" ,
.

.

.

-,

12

.1.4
f , ,
.
e,
f.
e () g.
.
,
. -
. .
-
() - .

.
f(x)

.1.5
f(x,y) x y

f(x,y)/x

f(x,y)/y

.
1.6,
, , - ). ,
13

, x, f(x, y)/ x
(. 1.6), , y, - f(x, y)/ y (. 1.6).
,
.
, ( )
.

, (. 1.6) ,
, .

.1.6
,
"" 2 x 2 ( ):

1.3
, "",
.
. .
.
.1.7( ).
. 1.7 .

.1.7

14

, , .

.
.1.8. ,
, .
, :

.1.8

, 1 x 1.

" ".
M1 x M2 .
,
m n. ,
(n1 # 0, n2 # 0,
n1 > M1 , n2 > M2) (, )
.


.

(,

.
,
,
, .
,
.
, -
15


().
,
, ..
,
,
, .
. ,
,
.

,
. ,
.

() ,
. 1.9

.1.9
y(n1 ,n2)
,
x(n1 ,n2) .
() x(n1 ,n2).
:

16

(n1,n2) , = x (n1,n2) - x (n1,n2),


n1 = 0 1 ,..., M1 1, n2 = 0 1 ,, M2 1,
() ,
:

(e2 -> min)



- .
, ,
() ,
.

( )
.
.
,

.
,
. ,
.
.
:

17

A1=

A2=

,A3=

,
. ( A1
, A3 - ).
.
,
.
3 x 3 ,
(5 x 5, 7 x 7,)


.
W, .
, .
x1,x2, ..., xL L ,
(L - 1)/2 , , (L 1)/2 , . ,
,
. , med(20, 10, 3, 7, 7) = 7.
W :
x (n1,n2) , = med y(n1,n2) = med[y( n1 + k1,n2 + k2): (k1,k2) , W]
,
.
, ,
18

().
,
.
. .1.10

.

.1.10
, , , 3 x 3
, ,
.
, ,
.
3 x 3 :
,
.

1.4 -


-
,
.
-.
19

,

, ,
,
, ,
.

. -
-
,
, , , , , ..
,

.

- :
;

, ;

(, , ..);

,
;

.1.11
.
20


.
.

- .
-1 .
:

-;

-;

-;

-.

-;

-;

-;

-;

-.

-;

, ;


-;

-;

-;

-.

21

.1.12

22

2.

2.1
- , ,
(, , ),
( .), ,
, ().
- .
.
, ,
,
. , , ,
.

.2.1
- .
, (,
). .
, - .
23

(.2.2)
.
.
.

.2.2

. : .
, , ,
, .
, ,
:
- ,
- ,
- ,
- .

24

.2.3

. 2.3
,
. ""
. "" ,
[0; 255].

( ) (.2.3).
(.2.3).
, ,
, , .
.
.
,
, . 2.4

25

.2.4

2.2

:

.2.5

( );

26

.2.6

.2.7
,
, , .

, ,
.
, , ,
. .
, .
,
.

.
27

, (
).

.
, ,
,
. ,
.

.2.8

, ,
. .
2.1

.
, ,
28

. ,
.

.2.9

, .
,
. ,
.
, ,
. , ,
, .
:
1. ,
,
. .
2. ,
.
.
29

3. ,
, (, , ).
.

, .
,
. .
,

.

.2.10
,
: , .
- ,
,
.

30

2.3 , .

.

:

- ;

;

.
.
A = {aij| i=, j=} ,
, aij - (). aij

{0,1,,N-1}

N ,
N ( ). aij
xyk

{(xy1, xy2 , xy3 )},

{0,1,,N-1} ,

31

N3 , ,
(x1ij , x2ij ,x3ij ) .

.
, .
() , ()
.

:
, , . .
,
.

, :

() ;


.
, .
,
, . (
)

.
:
- :
B(x,y)=

32

- :
B(x,y)=

,
.

, , ,
, . ,

.
, ,
- ,
. .
,
.
, , ,
.
, ,
, ,
, , , .

.
, -
, .

, ,

.
, .
33

.
.

.2.11

.
.
, ,
.

.2.12

.2.13

()
: , ,
34

.
.
:


.
, ,
.
.
,
(), , .

35

3.

3.1 ,
3
:
1. ()
2.
3.

.

().
, ,
/ .

, ,
.

, , ,
.

3.2

FOREL,
,
.
,
, .
, ..
. .
:
36

3.3
,
, , . ,
.
:
this.button1 = new System.Windows.Forms.Button(); //
// button1
//
this.button1.Location = new System.Drawing.Point(6, 19);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "O";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);

1.
2.
3.
4.
5.
6. .
7. .
, , ,
, .
37

:
this.pictureBox1 = new System.Windows.Forms.PictureBox();
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.NoMove2D;
this.pictureBox1.Location = new System.Drawing.Point(12, 72);
this.pictureBox1.MaximumSize = new System.Drawing.Size(480, 480);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(480, 480);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
this.pictureBox1.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
this.pictureBox1.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);

1.
2. ( )
3.
4.
5.
6.
7. , PictureBox.
8.
9. ,
10. 11. 12. ,
/ /
:
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(501, 72);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(485, 480);
this.textBox1.TabIndex = 8;

1.
2.
38

3.
4.
5.
,
, .
// groupBox1
//
this.groupBox1.Controls.Add(this.get_radius);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.delete_image);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(277, 54);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "";

1. 2. 3.
4.
5.
6.
7.
8. ,
9.
, /
:
// trackBar1
//
this.trackBar1.Location = new System.Drawing.Point(12, 558);
this.trackBar1.Maximum = 50;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(480, 45);
this.trackBar1.TabIndex = 14;
this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);

1.
2.
3.
4.
5.
39

6. ,
:
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(998, 610);
this.Controls.Add(this.trackBar1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Text = " ";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

1. , . SizeF

2.
3.
4. 11. // ..
12.
13. , ,
, .

14.
15.
16. 17. 18.
19.
20. .
:
40

public Form1()
{
InitializeComponent();
}

:
private void button1_Click( object sender , EventArgs e )
{
//
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// ,
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe;
*.jfif; *.png";
openFileDialog1.FilterIndex = 2;
//
if ( openFileDialog1.ShowDialog() == DialogResult.OK )
{
try
{
//
Bitmap tempimg = ( Bitmap )Bitmap.FromFile( openFileDialog1.FileName );
//
get_radius.Enabled = true;
delete_image.Enabled = true;
// 480x480
img = new Bitmap( 480 , 480 );
Graphics gp = Graphics.FromImage( img );
gp.DrawImage( tempimg , 0 , 0 , 480 , 480 );
finalImg = new Bitmap( img );
// ,
pictureBox1.Image = img;
// ()
radius = 100;
choosingRadius = true;
drawMainImage();
}
catch ( Exception ex )
{
//
MessageBox.Show( "Error: Could not read file from disk. Original error: " + ex.Message );
}
}
}

:
int ellipseX = 0; // x
int ellipseY = 0; // Y
int ellipseSize = 100; //

41

int borderSize = 5;
bool choosingRadius = false;
int imageX; // x
int imageY; // y
Bitmap zoomImage;
double imageZoom = 1; // , 1 1
SolidBrush br = new SolidBrush( Color.FromArgb( 65 , 0 , 0 , 0 ) );
Pen pn = new Pen( Brushes.Gray , 5 );
bool dragEllipse = false; //
bool resizeEllipse = false; //
bool isMouseDown = false; // , true
int mouseDownX = 0; //x
int mouseDownY = 0; //y

:
private void button2_Click( object sender , EventArgs e )
{
textBox1.Text += "\r\n \t-------------------------------------------------------\r\n...\r\n";
textBox1.Refresh();
textBox1.Text += " ...\r\n";
textBox1.Refresh();
// (clearBackground() - > MyImage)
pictureBox1.Image = myimg.clearBackground();
pictureBox1.Refresh();
//
int count = 0;
//
double precent = myimg.filled_area();
textBox1.Text += " ...\r\n";
textBox1.Refresh();
//
finalImg = myimg.Clustering( radius , ref count , pictureBox1);
//
pictureBox1.Image = finalImg;
textBox1.Text += "...\r\n\r\n";
textBox1.Refresh();
textBox1.Text += " " + count + " \r\n";
textBox1.Text += " " + string.Format("{0:0.00}",precent)
+ "%\r\n";
double area = radius * radius * Math.PI;

42

textBox1.Text += " " + string.Format( "{0:0.00}" , area ) + " \r\n";


//
button3.Enabled = true;
drawMainImage();
}

- ,
, , :
private void button3_Click( object sender , EventArgs e )
{
//
textBox1.Text = ""; //
pictureBox1.Image = img; //
zoomImage = new Bitmap( img );
finalImg = new Bitmap( img );
pictureBox1.Refresh();
if ( isCutting )
{
// ,
isCutting = false;
cut_part = new Rectangle( 0 , 0 , 50 , 50 );
myimg.cutPart = new Rectangle( 0 , 0 , 480 , 480 );
pictureBox1.Image = img;
pictureBox1.Refresh();
}
else if ( !get_radius.Enabled )
{
//
//
choosingRadius = true;
get_radius.Enabled = true;
button2.Enabled = false;
fill_area.Enabled = false;
object_size.Enabled = false;
object_count.Enabled = false;
cut_image.Enabled = false;
button3.Enabled = false;
radius = 100;
myimg = new MyImage( img );
drawMainImage();
}
}

( ,
.. ):
private void delete_image_Click( object sender , EventArgs e )

43

{
isCutting = false;
cut_part = new Rectangle( 0 , 0 , 480 , 480 );
//
button2.Enabled = false;
button3.Enabled = false;
fill_area.Enabled = false;
delete_image.Enabled = false;
object_size.Enabled = false;
object_count.Enabled = false;
cut_image.Enabled = false;
get_radius.Enabled = false;
//
img = new Bitmap( 480 , 480 );
finalImg = new Bitmap( 480 , 480 );
zoomImage = new Bitmap( 480 , 480 );
pictureBox1.Image = img;
//
textBox1.Text = "";
}

- ,
, ,
Clustering, :
private void object_count_Click( object sender , EventArgs e )
{
// (clearBackground() - > MyImage)
pictureBox1.Image = myimg.clearBackground();
pictureBox1.Refresh();
//
int count = 0;
//
double precent = myimg.filled_area();
textBox1.Text += "\r\n \t-------------------------------------------------------\r\n
...\r\n";
textBox1.Refresh();
//
finalImg = myimg.Clustering( radius , ref count , pictureBox1 );
textBox1.Text += " " + count + " \r\n";
drawMainImage();
}

- filled_area
2 :
private void fill_area_Click( object sender , EventArgs e )

44

{
//
double fl = myimg.filled_area();
textBox1.Text += "\r\n \t-------------------------------------------------------\r\n
" + string.Format( "{0:0.00}" , fl ) + "%\r\n";
}

0.1
1, X*, . = 1 +
0.1*- :
private void trackBar1_ValueChanged( object sender , EventArgs e )
{
//
imageZoom = 1 + 0.1 * trackBar1.Value;
drawMainImage();
}

, ,
:
private void drawMainImage()
{
//
zoomImage = new Bitmap( finalImg );
Graphics gp = Graphics.FromImage( zoomImage );
// pictureBox1
imageX = imageX > 0 ? 0 : imageX;
imageY = imageY > 0 ? 0 : imageY;
// pictureBox1,

imageX = imageX < -( int )( imageZoom * 480 ) + 480 ? -( int )( imageZoom * 480 ) + 480 :
imageX;
imageY = imageY < -( int )( imageZoom * 480 ) + 480 ? -( int )( imageZoom * 480 ) + 480 :
imageY;
//
gp.DrawImage( zoomImage , imageX , imageY , ( int )( 480 * imageZoom ) , ( int )( 480 *
imageZoom ) );
//
if ( isCutting )
{
//
// pictureBox1
cut_part.X = cut_part.X < 0 ? 0 : cut_part.X;
cut_part.Y = cut_part.Y < 0 ? 0 : cut_part.Y;

45

//
if ( moveCutPart )
{
cut_part.X = cut_part.X + cut_part.Width > 480 ? 480 - cut_part.Width : cut_part.X;
cut_part.Y = cut_part.Y + cut_part.Height > 480 ? 480 - cut_part.Height : cut_part.Y;
}
//
if ( resizeCutPart )
{
cut_part.Width = cut_part.X + cut_part.Width > 480 ? 480 - cut_part.X : cut_part.Width;
cut_part.Height = cut_part.Y + cut_part.Height > 480 ? 480 - cut_part.Y : cut_part.Height;
}
//
gp.DrawRectangle( pn , cut_part );
myimg.cutPart = new Rectangle( ( int )( cut_part.X / imageZoom ) , ( int )( cut_part.Y /
imageZoom ) , ( int )( cut_part.Width / imageZoom ) , ( int )( cut_part.Height / imageZoom ) );
}
//
if ( choosingRadius )
{
//
gp.DrawRectangle( pn , ellipseX , ellipseY , ellipseSize , ellipseSize );
//
gp.FillEllipse( br , ellipseX , ellipseY , ellipseSize , ellipseSize );
}
//
pictureBox1.Image = zoomImage;
//
pictureBox1.Refresh();
}

:
private void pictureBox1_MouseDown( object sender , MouseEventArgs e )
{
isMouseDown = true;
//
// ,
mouseDownX = e.X - imageX;
mouseDownY = e.Y - imageY;
//
if ( isCutting )
{
if ( e.X > cut_part.X && e.Y > cut_part.Y && e.X < cut_part.X + cut_part.Width && e.Y <
cut_part.Y + cut_part.Height )
{
if ( e.X >= cut_part.X + cut_part.Width - borderSize || e.Y >= cut_part.Y + cut_part.Height borderSize )//
{
//
resizeCutPart = true; //
mouseDownX = e.X - cut_part.Width;

46

mouseDownY = e.Y - cut_part.Height;


}
Else //
{
//
moveCutPart = true;//
mouseDownX = e.X - cut_part.X;
mouseDownY = e.Y - cut_part.Y;
}
}
}
// , ..
if ( choosingRadius )
{
if ( e.X > ellipseX && e.Y > ellipseY && e.X < ellipseX + ellipseSize && e.Y < ellipseY +
ellipseSize )
{//
if ( e.X >= ellipseX + ellipseSize - borderSize || e.Y >= ellipseY + ellipseSize - borderSize )
{
//
resizeEllipse = true;
mouseDownX = e.X - ellipseSize;
mouseDownY = e.Y - ellipseSize;
}
else//
{
//
dragEllipse = true;
mouseDownX = e.X - ellipseX;
mouseDownY = e.Y - ellipseY;
}
}
}
}

- (,
..) False:
private void pictureBox1_MouseUp( object sender , MouseEventArgs e )
{
//
isMouseDown = false;
moveCutPart = false;
resizeCutPart = false;
dragEllipse = false;
resizeEllipse = false;
}

:
private void pictureBox1_MouseMove( object sender , MouseEventArgs e )
{

47

//
//
if (isCutting && e.X > cut_part.X && e.X < cut_part.X + cut_part.Width && e.Y > cut_part.Y
&& e.Y < cut_part.Y + cut_part.Height )
{
if ( e.X >= cut_part.X + cut_part.Width - borderSize || e.Y >= cut_part.Y + cut_part.Height borderSize )
{
pictureBox1.Cursor = Cursors.SizeNWSE;
}
else
{
pictureBox1.Cursor = Cursors.NoMove2D;
}
}
else if ( choosingRadius && e.X > ellipseX && e.Y > ellipseY && e.X < ellipseX + ellipseSize
&& e.Y < ellipseY + ellipseSize )
{
if ( e.X >= ellipseX + ellipseSize - borderSize || e.Y >= ellipseY + ellipseSize - borderSize )
{
pictureBox1.Cursor = Cursors.SizeNWSE;
}
else
{
pictureBox1.Cursor = Cursors.NoMove2D;
}
}
else
{
pictureBox1.Cursor = Cursors.NoMove2D;
}
//
if ( isMouseDown )
{
if ( moveCutPart )
{
//
cut_part.X = e.X - mouseDownX;
cut_part.Y = e.Y - mouseDownY;
}
else if( resizeCutPart )
{
//
cut_part.Width = e.X - mouseDownX;
cut_part.Height = e.Y - mouseDownY;
}
else if ( dragEllipse )
{
//
ellipseX = e.X - mouseDownX;

48

ellipseY = e.Y - mouseDownY;


}
else if ( resizeEllipse )
{
//
ellipseSize = (e.X - mouseDownX + e.Y - mouseDownY) / 2;
}
else
{
//
imageX = e.X - mouseDownX;
imageY = e.Y - mouseDownY;
}
drawMainImage();
}
}

:
private void object_size_Click( object sender , EventArgs e )
{
// Pi*R2
double area = radius * radius * Math.PI;
textBox1.Text += "\r\n\t-------------------------------------------------------\r\n " +
string.Format( "{0:0.00}" , area ) + " \r\n";
}

, Pi*R2
.
:
private void cut_image_Click( object sender , EventArgs e )
{
//
isCutting = true;
finalImg = new Bitmap( img );
myimg.cutPart = new Rectangle( (int)(cut_part.X / imageZoom) , (int)(cut_part.Y / imageZoom) ,
(int)(cut_part.Width / imageZoom) , (int)(cut_part.Height / imageZoom) );
drawMainImage();
}

isCutting True, .. ,
.
drawMainImage();, .

49

):
private void get_radius_Click( object sender , EventArgs e )
{
//
getRadius();
}
void getRadius()
{
//
finalImg = new Bitmap( img );
zoomImage = new Bitmap( img );
choosingRadius = false;
get_radius.Enabled = false;
button2.Enabled = true;
fill_area.Enabled = true;
object_size.Enabled = true;
object_count.Enabled = true;
cut_image.Enabled = true;
button3.Enabled = true;
radius = (int)(ellipseSize / imageZoom) / 2;
myimg = new MyImage( img );
drawMainImage();
}

.
drawMainImage();, .
,

.
, :
private void makeMatric()
{
for ( int i = 0; i < img.Width; i++ )
{
for ( int j = 0; j < img.Height; j++ )
{
//
MyStruct tempStruct = new MyStruct();
tempStruct.R = img.GetPixel( i , j ).R;
tempStruct.G = img.GetPixel( i , j ).G;
tempStruct.B = img.GetPixel( i , j ).B;
imgmat[ i , j ] = tempStruct;
}
}
}

50

.
,
( ) , :
1. ( (0,0) ( ),
(i,j))
2. :
a.
b.
c.
3. : ++
4. 20 650,
0.
5. . 4 , 1
6. 1-5, .
, ,
,
, .
public Bitmap clearBackground()
{
//
Bitmap retImg = new Bitmap( img );
for ( int i = cutPart.X; i < cutPart.X + cutPart.Width; i++ )
{
for ( int j = cutPart.Y; j < cutPart.Y + cutPart.Height; j++ )
{
int R = imgmat[ i , j ].R;
int G = imgmat[ i , j ].G;
int B = imgmat[ i , j ].B;
int diff1 = Math.Abs( R - G );
int diff2 = Math.Abs( R - B );
int diff3 = Math.Abs( G - B );
// ,

if ( ( diff1 < 20 && diff2 < 20 && diff3 < 20 ) || R + G + B > 650 )
{
objectMatrix[ i , j ] = 0;
retImg.SetPixel( i , j , Color.FromArgb( 0 , 0 , 0 ) );
}
else
{
objectMatrix[ i , j ] = 1;
}

51

}
}
return retImg;
}

, :
0 0 0 1 0
0 0 1 1 1
0 1 1 1 1
0 0 1 1 1
0 0 0 1 0
, 0 , 1 .
,
: 1 / :
public double filled_area()
{
clearBackground();
int allPrec = 0;
int countPrecent = 1;
for ( int i = cutPart.X; i < cutPart.X + cutPart.Width; i++ )
{
for ( int j = cutPart.Y; j < cutPart.Y + cutPart.Height; j++ )
{
if ( objectMatrix[ i , j ] == 1 )
{
//
countPrecent++;
}
//
allPrec++;
}
}
//
double precent = ( double )( ( double )countPrecent / ( double )allPrec ) * 100;
return precent > 100 ? 100 : precent;
}

.
, , ,
. Pi*R2
:
52

private void object_size_Click( object sender , EventArgs e )


{
// Pi*R2
double area = radius * radius * Math.PI;
textBox1.Text += "\r\n\t-------------------------------------------------------\r\n " +
string.Format( "{0:0.00}" , area ) + " \r\n";
}


:
1.
2. , , R
3. , ,
,
.
4. 2-3,
5.

,
6. 1-5,
1.
//
if ( objectMatrix[ i , j ] == 1 )
{
//
Point center = new Point( i ,j );
//
Point lastCenter = new Point( -1 , -1 );
//
List<Point> pointers = new List<Point>();
//
pointers.Add( center );

2.
while ( true )
{
// , , R

for ( int x = center.X - radius; x <= center.X + radius* 2; x++ )


{
for ( int y = center.Y - radius; y <= center.Y + radius * 2; y++ )
{

53

if ( x >= cutPart.X && y >= cutPart.Y && x < cutPart.X+cutPart.Width && y <
cutPart.Y+cutPart.Height)
{
if ( getDistance( new Point( x , y ) , center ) <= radius )
{
if ( objectMatrix[ x , y ] == 1 )
{

3.
//
pointers.Add( new Point( x , y ) );
//
retImg.SetPixel( x , y , Color.FromArgb( 76 , 102 , 164 ) );

// ,
if ( pointers.Count > 0 )
{
lastCenter = center;
center = getCenter( pointers );
}

4. , ,

5. ,
0, .. :
//
// R
,
if ( lastCenter == center )
{
foreach ( Point point in pointers )
{
objectMatrix[ point.X , point.Y ] = 0;
}
objectsCount++;
i = cutPart.X;
j = cutPart.Y;
pb.Refresh();
break;
// ,
}

6. , .

54

,
, .
, , ,
:
// ,
if ( pointers.Count < radius*radius/2 && pointers.Count > 0 )
{
foreach ( Point point in pointers )
{
objectMatrix[ point.X , point.Y ] = 0;
}
i = 0;
j = 0;
break;
}

,
:
//
for ( int i = cutPart.X; i < cutPart.X + cutPart.Width - 1; i++ )
{
for ( int j = cutPart.Y; j < cutPart.Y+cutPart.Height - 1; j++ )
{
if ( tempMatrix[ i , j ] != tempMatrix[ i + 1 , j ] || tempMatrix[ i , j ] != tempMatrix[ i , j +
1])
{
retImg.SetPixel( i , j , Color.FromArgb( 200 , 100 , 0 ) );
retImg.SetPixel( i+1 , j , Color.FromArgb( 200 , 100 , 0 ) );
retImg.SetPixel( i , j+1 , Color.FromArgb( 200 , 100 , 0 ) );
}
}
}


() :
count = objectsCount;
pb.Refresh();
return retImg;

, , R
getDistance,
, R.:
private int getDistance( Point pt1 , Point pt2 )
{
// 2
return (int)Math.Sqrt( Math.Pow( pt1.X - pt2.X , 2 ) + Math.Pow( pt1.Y - pt2.Y , 2 ) );

55

}
if ( getDistance( new Point( x , y ) , center ) <= radius )

getCenter:
private Point getCenter( List<Point> pt )
{
//
Point retPnt = new Point();
int sumx = 0 , countx = 0 , sumy = 0 , county = 0;
foreach ( Point point in pt )
{
sumx += point.X;
countx++;
sumy += point.Y;
county++;
}
retPnt = new Point( sumx / countx , sumy / county );
return retPnt;
}

56

4.
,
, :

57

,
,
():

,
.

:

58

,
.

:

,
:

59

,
:

,
:

60



. .
.

.
,
,
.
,
,
. ,
, , 20 :

,
- . , .

.

,
,
.
:

,
.

61

,
.
,
.

62


1.

.., ..

. .: , 2005. 155.
2.

.. Visual # .2008 496.

3.

.., .. Java #

.2005-512.
4.

M.I1.

/ .. , .., .. // - ,
2004,-3,-. 23-27
5.

.. . /

.., .., .. . .: ,
2006. -132.
6.

..

/ .., .., ..
. // 2005611778
21.07.2005.
7.

, .. . 2.


8.

, .. / ..

.-, 2003 - 784 .


9.

., . Visual C# 2010. .2011.-955.

10.

.., ..,

: . . - : , 2008. 192 .
11.

, .. / .. .-.:

, 1979.-274 .
12.

: 2- . . .; .

. . - .: , 1991. - . 2 - 406 .
13.

. http://www.diamorph.ru/
14.

"-". http:// www.vrach-aspirant.ru /

15.

. http://www.ld.ru/

63


, ,
, ,
. ,
.
,

64

Оценить