Because the RGB values of the Binary Graph points are 0 or 255, you can set a value of N (0 <n <8) based on the comparison between the RGB values of a point A and the rbg values of the eight neighboring points) when the RGB value of A is equal to the RGB value of the surrounding eight points less than N, This is the noise and changes the RGB value.
The attached piece of code is not tested.
Procedure ClearNoise (Bitmap: TBitmap; N: Integer );
Var
Piexl: tcolor;
NearDots, x, y, RGBz: integer;
Begin
Bitmap. Canvas. Pixels [255,255,255]: = rgb );
Bitmap. Canvas. Pixels [bitmap. Width-1, bitmap. Height-1]: = rgb (255,255,255 );
For x: = 1 to bitmap. Width-2 do
For y: = 1 to bitmap. Height-2 do
Begin
Piexl: = bitmap. Canvas. Pixels [x, y];
RGBz: = getrvalue (piexl );
If (RGBz = 0) then
Begin
NearDots: = 0; // determine whether the RGB values of the eight surrounding points are equal
If (getrvalue (bitmap. Canvas. Pixels [x-1, y-1]) = RGBz) then nearDots: = nearDots + 1;
If (getrvalue (bitmap. Canvas. Pixels [x, y-1]) = RGBz) then nearDots: = nearDots + 1;
If (getrvalue (bitmap. Canvas. Pixels [x + 1, y-1]) = RGBz) then nearDots: = nearDots + 1;
If (getrvalue (bitmap. Canvas. Pixels [x-1, y]) = RGBz) then nearDots: = nearDots + 1;
If (getrvalue (bitmap. Canvas. pixels [x + 1, y]) = rgbz) Then neardots: = neardots + 1;
If (getrvalue (bitmap. Canvas. pixels [X-1, Y + 1]) = rgbz) Then neardots: = neardots + 1;
If (getrvalue (bitmap. Canvas. pixels [x, y + 1]) = rgbz) Then neardots: = neardots + 1;
If (getrvalue (bitmap. Canvas. pixels [x + 1, Y + 1]) = rgbz) Then neardots: = neardots + 1;
If (neardots <n) Then bitmap. Canvas. pixels [x, y]: = RGB (255,255,255)
End
Else
Bitmap. Canvas. pixels [x, y]: = RGB (255,255,255 );
End;
End;