Remove noise, dots and image strokes

Asked

Viewed 942 times

6

I would like to know how I can process a captcha image to remove noise, strokes and dots. Here are examples of how you are and how I’d like you to stay.

Original Image:

Imagem Original - Captcha

Adjusted Image:

Imagem processada

  • I could post your code?

  • 1

    For noise removal I recommend applying a media filter to your image. Unfortunately I only learned how to do the algorithm using the colors and I owe you in Delphi.

  • Randrade, at the moment my code is only transforming the image into 1 Bit... the process of cleaning it, regarding this removal I have nothing done yet.

  • William Okano, do you have any examples of this effect? Can I try to apply

  • You already have an answer that shows you how to manipulate pixels in Delphi. So just apply a media filter to your image (as suggested by fellow @Williamokano). The basic idea is to iterate over the image pixels and calculate the average of the pixels "around" the pixel under analysis. The value obtained (the average of the pixels in the "window" of the input image) is the pixel value for the output image. This type of filter removes well the kind of noise you have, but can eliminate letter details (depending on window size).

  • More information here and here.

Show 1 more comment

1 answer

4


Follow procedure to perform Noise Removal, Stitches and some strokes!

Add 1 component TImage and 1 component TButton, in the TImage1 upload an image BMP (for pixel by pixel is the best format, so the procedure is all over that format)

procedure frmTeste.btnCorrigirClick(Sender: TObject);
var
  X, Y : Integer;
  vBmpTemp : TBitmap;
begin
  vBmpTemp := TBitmap.Create;
  vBmpTemp.Assign(Image.Picture.Bitmap);
  for X := 0 to Image.Width - 1 do
  begin
    for Y := 0 to Image.Height - 1 do
    begin
      if ((Image.Canvas.Pixels[X, Y] >=  $00000000)  and
          (Image.Canvas.Pixels[X, Y] <=  $00999999)) or
          (Image.Canvas.Pixels[X, Y]  =  $00FEFEFE)  or
          (Image.Canvas.Pixels[X, Y]  =  $00FAFAFA)  or
          (Image.Canvas.Pixels[X, Y]  =  clBlack)    then
      begin
        if ((Image.Canvas.Pixels[X - 1, Y] >=  $00000000)  and
            (Image.Canvas.Pixels[X + 1, Y] <=  $00999999)) then
        begin
          vBmpTemp.Canvas.Pixels[X, Y] := Image.Canvas.Pixels[X, Y];
        end;
      end;
    end;
  end;

  Image.Picture := nil;

  for X := 0 to vBmpTemp.Width - 1 do
  begin
    for Y := 0 to vBmpTemp.Height - 1 do
    begin
      if ((vBmpTemp.Canvas.Pixels[X, Y] >=  $00000000)  and
          (vBmpTemp.Canvas.Pixels[X, Y] <=  $00999999)) or
          (vBmpTemp.Canvas.Pixels[X, Y]  =  $00FEFEFE)  or
          (vBmpTemp.Canvas.Pixels[X, Y]  =  $00FAFAFA)  or
          (vBmpTemp.Canvas.Pixels[X, Y]  =  clBlack)    then
      begin
        if ((vBmpTemp.Canvas.Pixels[X - 1, Y] >=  $00000000)  and
            (vBmpTemp.Canvas.Pixels[X + 1, Y] <=  $00999999)) then
        begin
          Image.Canvas.Pixels[X, Y] := vBmpTemp.Canvas.Pixels[X, Y];
        end;
      end;
    end;
  end;
end;

What I did is very simple, I’m going through the image pixels to pixels, if I find a sequence of colors I pass it to the TImage.

Every click on the button cleans more and more the image! I await the feedback!

  • Good morning! Sorry for the delay in responding to this post, I was without access for all this time. Your procedure served me as I expected, now I will make some more adjustments to clear tbm the lines, remaining only the letters. Thank you very much friend!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.