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 6049729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:34+00:00 2026-05-23T07:36:34+00:00

So i’m trying to make a program that can find how many pixels of

  • 0

So i’m trying to make a program that can find how many pixels of a specific colour it has in it. The images are pictures taken with camera and after that some areas on them has been marked on photoshop, and i need to find the exact number of this pixels. But i have few problems.
I’m using getPixel(x,y) but and i’m comparing to the Color.FromArgb(red, green, blue) that i want but… my first problem is that for colors differ a little for example i want to find out the color
RGB 116,110,40 but when you draw with this color on photoshop some pixels get a little diferent color like RGB 115,108,38 (and others similar) and i want to include this as well. So i finally came up with this code(but it seems that id does now work right):

public Form1()
    {
        InitializeComponent();
    }

    Bitmap image1;
    int count=0;
    int red, green, blue;
    int redt, greent, bluet;
    double reshenie;

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            red = int.Parse(textBox1.Text);
            green = int.Parse(textBox2.Text);
            blue = int.Parse(textBox3.Text);

                           // Retrieve the image.
            image1 = new Bitmap(@"C:\bg-img.jpg", true);
             double widht, height, pixel ;
            int x, y;
            MessageBox.Show(pixel.ToString());

            // Loop through the images pixels            
            for (x = 0; x < image1.Width; x++)
            {
                for (y = 0; y < image1.Height; y++)
                {
                    Color pixelColor = image1.GetPixel(x, y);
                    redt = pixelColor.R;
                    greent = pixelColor.G;
                    bluet = pixelColor.B;


                    if ((red+10>=redt) && (red-10>=redt))//i used +-10 in attempt to resolve the problem that i have writed about the close colours
                    {

                        if ((green + 10 >= greent) && (green - 10 >= greent))
                        {
                            if ((blue + 10 >= bluet) && (blue - 10 >= bluet))
                            {
                                count += 1;

                            }
                        }
                    }
                }
            }

            pictureBox1.Image = image1;

            MessageBox.Show("Imashe " + count.ToString());
            count = 0;

        }
        catch (ArgumentException)
        {
            MessageBox.Show("There was an error." +
                "Check the path to the image file.");

        }

    }

The problem is that i dont get the result that i expect. For example when i have to get like 1000 pixels i get more or less and i cant find where is my mistake. So if someone can give me idea what i’m doing wrong. Thanks for all the help in advance.

  • 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-23T07:36:34+00:00Added an answer on May 23, 2026 at 7:36 am

    From your code:

    if ((green + 10 >= greent) && (green - 10 >= greent))
    

    If (a - 10 >= b), then for sure (a + 10 >= b). See if you can understand why.

    I think you may have meant

    if ((green - 10 <= greent) && (greent <= green + 10))
    

    Ordering the condition like that helps with readability, because greent has to be between green - 10 and green + 10, and is also physically located between those expressions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.