Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:51+00:00 2026-06-11T12:32:51+00:00

Scope : Hi everyone, i am trying to convert this captcha to a black

  • 0

Scope:

Hi everyone, i am trying to convert this captcha to a “black and white” (binarized) image, where the characters are white and the whole rest (background,lines,random pictures) are black.

The link to the captcha can be found here. Refreshing will give you another captcha.

Reason:

I know most of people think it is wrong to mess with captchas so here i am defending myself. This will be used for knowledge / self challenge only. No other use is planned for these images.

Problem:

After studying these images for a while, i figured out that a good aproach would be to replace the colors : “White and Yellow” to “Color.Black”, and every other color should be replaced to “Color.White.”

After this, i would just “Invert” the colors, leading me to the output i want.

Code Sample:

In this code, i am trying to replace the color “Black” of every image for a SkyBlue Pixel.

        WebRequests wr = new WebRequests(); // My class to handle WebRequests
        Bitmap bmp;
        string url = "http://www.fazenda.rj.gov.br/projetoCPS/codigoImagem";

        bmp = wr.GetBitmap (url);

        for (int i = 1; i < bmp.Height ; i++)
        {
            for (int j = 1 ; j < bmp.Width ; j++)
            {
                if (bmp.GetPixel(j,i).Equals(Color.Black))
                {
                    bmp.SetPixel(j,i, Color.SkyBlue);
                }
            }
        }

This code do not work at all, i’m not sure why, but no pixel is getting replaced in this example.

Question:

How can i make this work ? What am i missing here ?

Also, the ideal scenario for me would be to “reduce” the color pallete of this image to “basic” colors, that would make my job here much easier.

I already tried the AForge Framework, which i am using to reduce colors, but it is not working at all, the result is not the one i expected.

What can i do here in order to binarize this image correctly ?

Thanks in advance,

Marcello Lins.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:32:52+00:00Added an answer on June 11, 2026 at 12:32 pm

    The reason why your algorithm does not work is that you are looking for an exact match. But the black in the image isn’t really black due to JPEG compression artifacts; in three CAPTCHAS I’ve loaded there was not even a single black (0, 0, 0) pixel. The closest value was (0, 0, 4) which looks black, but isn’t.

    An approximate approach would be:

    • Remove all grays (channels differing from each other less than 5%) having a channel average below 220 with gray. This kills the thin lightgray lines as well as much of the ringing (JPEG) artifacts against a gray background.
    • Replace all pixels where the red, green, or blue channel is more than 25% above both the other two channels with gray. This takes care of reds, greens and blues as well as most of their ringing artifacts.
    • Run a simple despeckle to remove all nongray pixels surrounded by five grays and by no other pixel of the same colour within 20%.

    At the end of this process, the background is all gray, all nongray pixels left are characters.

    Some useful functions:

    // Very basic (and CIE-incorrect) check
    public static int isGray(Color c)
    {
        if (Math.Abs(c.R - c.G) > 5 * 2.55) return 0; // Not gray. R and G too different
        if (Math.Abs(c.R - c.B) > 5 * 2.55) return 0;
        if (Math.Abs(c.G - c.B) > 5 * 2.55) return 0;
        return 1;
    }
    
    // the blind man's test for shading :-)
    public static int isShadeOfRed(Color c)
    {
        if (4*c.R < 5*c.G) return 0; // Red not strong enough in respect to green
        if (4*c.R < 5*c.B) return 0; // Red not strong enough in respect to blue
        return 1; // Red is stronger enough than green and blue to be called "shade of red"
    }
    
    // (shades of green and blue left as an exercise)
    
    // Very basic (and CIE-incorrect) check
    public static int areSameColor(Color a, Color b)
    {
        if (Math.Abs(a.R - b.R) > 5 * 2.55) return 0;
        if (Math.Abs(a.G - b.G) > 5 * 2.55) return 0; 
        if (Math.Abs(a.B - b.B) > 5 * 2.55) return 0;
        return 1; // "more or less" the same color
    }
    
    // This is more or less pseudo code...
    public static int isNoise(int x, int y)
    {
        if ((x < 1) || (y < 1)) return 0; // or maybe "return 1"
        if ((x+1 >= bmp.Width)||(y+1 >= bmp.Height)) return 0;
        pix = bmp.GetPixel(x,y);
        for (i = -1; i <= 1; i++)
            for (j = -1; j <= 1; j++)
            {
                if ((i == 0) && (j == 0)) continue;
                test = bmp.GetPixel(x+i, y+j);
                if (isGray(test)) grays++;
                if (isSameColor(pix, test)) same++;
            }
        // Pixel surrounded by grays, and has no neighbours of the same colour
        // (who knows, maybe we could skip gray calculation and check altogether?)
        // is noise.
        if ((grays == 5) && (same == 0))
           return 1;
        return 0;
    }
    
    // NOTE: do not immediately set to gray pixels found to be noise, for their neighbours
    // will be calculated using the new gray pixel. Damage to image might result.
    // Use a copy of bmp instead.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The scope of this is that we have three main projects. Some of the
I have this scope: scope :user_id, :as => user do resources :boards, :controller =>
scope issue in PHP classes: Why does this work? class index extends Application {
I am trying to see if this can be done in classic ASP: Dim
Thanks everyone for the feedback Hi All, I'm am trying to create a stored
This is my first post on stackoverflow, hello everyone! My first venture into jQuery
For reasons beyond the scope of this post, I would like to verify in
Just about everyone has ran into this specific issue: function addLinks () { for
I'm sure this is simple, but I'm tripping up over a scope issue in
Global scope allows you to use a variable in a function that was defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.