Delphi binary image Impurity Removal

Source: Internet
Author: User

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;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.