CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011
    Posts
    3

    Loop through all pixels to find one different by at least 5

    It never gets flagged..... I have a link to the two images.
    Code:
            bool flag = true;
            Color firstPixel;
            Color secondPixel;
    
            int BadPixels = 0;
           
                for (int i = 0; i < firstImage.Width; i++)
                {
                    for (int j = 0; j < firstImage.Height; j++)
                    {
                        firstPixel = firstImage.GetPixel(i, j);
                        secondPixel = secondImage.GetPixel(i, j);
                        if (firstPixel != secondPixel)
                        {
                            int PixelRed = Convert.ToInt16(firstPixel.R.ToString());
                            int PixelGreen = Convert.ToInt16(firstPixel.G.ToString());
                            int PixelBlue = Convert.ToInt16(firstPixel.B.ToString());
                            int PixelRed2 = Convert.ToInt16(secondPixel.R.ToString());
                            int PixelGreen2 = Convert.ToInt16(secondPixel.G.ToString());
                            int PixelBlue2 = Convert.ToInt16(secondPixel.B.ToString());
                            int MaxRed = PixelRed + 5;
                            int LowRed = PixelRed - 5;
                            int MaxGreen = PixelGreen + 5;
                            int LowGreen = PixelGreen - 5;
                            int MaxBlue = PixelBlue + 5;
                            int LowBLue = PixelBlue - 5;
                            if (FirstOne == 2)
                            {
                                textBox1.Text = "Red1: " + PixelRed + " Red2: " + PixelRed2 + " Blue1: " + PixelBlue + " Blue2: " + PixelBlue2 + " PixelGreen: " + PixelGreen + " PixelGreen2: " + PixelGreen2 + "\r\n";
                                textBox1.Text += "MaxR:" + MaxRed + " LowR:" + LowRed + " MaxBlue:" + MaxBlue + " LowB:" + LowBLue + " MaxG:" + MaxGreen + " LowG:" + LowGreen;
                            }
                            FirstOne++;
                            if (PixelRed2 <= LowRed && PixelRed2 >= MaxRed)
                            {
    
                                if (PixelBlue2 <= LowBLue && PixelBlue2 >= MaxBlue)
                                {
    
                                    if (PixelGreen2 <= LowGreen && PixelGreen2 >= MaxGreen)
                                    {
                                        BadPixels++;
                                        textBox1.Text = "Red1: " + PixelRed + " Red2: " + PixelRed2 + " Blue1: " + PixelBlue + " Blue2: " + PixelBlue2 + " PixelGreen: " + PixelGreen + " PixelGreen2: " + PixelGreen2 + "\r\n";
                                        textBox1.Text += "MaxR:" + MaxRed + " LowR:" + LowRed + " MaxBlue:" + MaxBlue + " LowB:" + LowBLue + " MaxG:" + MaxGreen + " LowG:" + LowGreen;
                                        flag = false;
                                        break;
    
                                    }
    
    
    
    
    
                                }
    
    
    
    
    
    
    
    
    
                            }
    
    
    
                        }
                    }
                }
    
                if (flag == false)
                {
                    return false;
                }
                else
                {
                    return true;
                }
    *The picture
    http://www.mymobster.org/Theif7.bmp
    *The picture I compare the first one to
    http://www.mymobster.org/TheifA.bmp
    P.S. I have turned off all auto-correcting settings on the webcam.

  2. #2
    Join Date
    Oct 2011
    Posts
    3

    Re: Loop through all pixels to find one different by at least 5

    I just realized my problem lol. The pixel can not be greater and less than it at the same time!

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Loop through all pixels to find one different by at least 5

    Yes. However, you can do bitmap access with better performance using unsafe code, see this discussion (link).
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured