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

  • Home
  • SEARCH
  • 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 5964701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:28:52+00:00 2026-05-22T19:28:52+00:00

i am currently developing an application that has to process scanned forms. One of

  • 0

i am currently developing an application that has to process scanned forms. One of the tasks of my application is to determine which kind of form is scanned. There are 3 possible types of forms with a unique background color to identify each kind. The 3 colors that are possible are red/pink, green and blue. The problem i am having is, that my attempts fail to distinguish between the green and blue forms.
Here are links to the green and blue sample files:

http://dl.dropbox.com/u/686228/Image0037.JPG

http://dl.dropbox.com/u/686228/Image0038.JPG

I am using C# .net Application and ImageMagick for some tasks i need to perform.

Currently i am getting color reduced histogram of my scanned form and try to determine which colors are in the form. But my app can’t rely distinguish the green and blue ones.

Any advise or maybe a smarter approach would be gladly appreciated.

Thanks,

Erik

  • 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-05-22T19:28:53+00:00Added an answer on May 22, 2026 at 7:28 pm

    I found this rather interesting and dug into it a little deeper.

    The code to get the average color of a bitmap found at How to calculate the average rgb color values of a bitmap had problems like some invalid casts and red/blue channels swapped. Here is a fixed version:

    private System.Drawing.Color CalculateAverageColor(Bitmap bm)
    {
        int width = bm.Width;
        int height = bm.Height;
        int red = 0;
        int green = 0;
        int blue = 0;
        int minDiversion = 15; // drop pixels that do not differ by at least minDiversion between color values (white, gray or black)
        int dropped = 0; // keep track of dropped pixels
        long[] totals = new long[] { 0, 0, 0 };
        int bppModifier = bm.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb ? 3 : 4; // cutting corners, will fail on anything else but 32 and 24 bit images
    
        BitmapData srcData = bm.LockBits(new System.Drawing.Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, bm.PixelFormat);
        int stride = srcData.Stride;
        IntPtr Scan0 = srcData.Scan0;
    
        unsafe
        {
            byte* p = (byte*)(void*)Scan0;
    
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int idx = (y * stride) + x * bppModifier;
                    red = p[idx + 2];
                    green = p[idx + 1];
                    blue = p[idx];
                    if (Math.Abs(red - green) > minDiversion || Math.Abs(red - blue) > minDiversion || Math.Abs(green - blue) > minDiversion)
                    {
                        totals[2] += red;
                        totals[1] += green;
                        totals[0] += blue;
                    }
                    else
                    {
                        dropped++;
                    }
                }
            }
        }
    
        int count = width * height - dropped;
        int avgR = (int)(totals[2] / count);
        int avgG = (int)(totals[1] / count);
        int avgB = (int)(totals[0] / count);
    
        return System.Drawing.Color.FromArgb(avgR, avgG, avgB);
    }
    

    Running this function on your input images, however, returned some indistinguishable grayish color for both of them, as already anticipated by Will A in the comments, which is why i’m dropping any colors from the calculation that do not have a difference of at least 15 between R, G and B.

    The interesting thing is that the supposedly blue prescription scan averages equal values for G and B (R: 214, G: 237, B: 237). However the green prescription scan resulted in a big difference (18) between the values for G and B (R: 202, G: 232, B: 214) so that might be what you should be looking into. Ex:

    if (color.G - color.B > 15) { form.Type = FormTypes.GreenForm }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am developing a windows form application in c# that has several forms.
I'm currently developing a web application that has one feature while allows input from
I am developing an application that currently has a View Controller (call it ViewControllerX).
The application my team is currently developing has a DLL that is used to
I'm currently developing an application which needs a lot of system and process information,
I'm currently in the process of developing an app which has some very demanding
Background: We are developing a web application that includes charts. Currently one can left-click
I am currently developing a C# Windows Form Application that I intend to let
I am currently developing an iPad application that has a Pause button. The entire
I am currently developing an application which has a maps feature. My map is

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.