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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:56:24+00:00 2026-06-08T12:56:24+00:00

I need to find a particular pixel of an image. Let’s say 89 21

  • 0

I need to find a particular pixel of an image. Let’s say “89 21 24”.

I’m using two nested cycles to walk the image:

for( $y=$inity; $y<$h; $y++) {
 for( $x=$initx; $x<$w; $x++) {

   $pixel = getpixelat($img,$x,$y);
   if ($pixel == "892124" and getpixelat($img,$x+1,$y) == "1212224") {
       $px = $x; $py = $y;
       break 2;
   }
}

I’d like to have a faster algorithm by increasing $y and $x not one by one, instead for example 4 by 4. (Sixteen times faster?)
Of course I need to know exactly the pixels that build 4×4 square.

I would do it like:

    if ($pixel == "" and nextpixel...) {
        $px = $x - 1; $py = $y -...;
    }
   //etc.

Is there a smarter way to achieve that?

EDIT:

Here’s the getpixelat function:

function getpixelat($img,$x,$y) {
$rgb = imagecolorat($img,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
return $r.$g.$b;
}
  • 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-08T12:56:27+00:00Added an answer on June 8, 2026 at 12:56 pm

    If you know that the color you are looking for always appears in patches of at least 2×2, or 3×3, or any fixed size, then yes, you can speed up the lookup by incrementing $x and $y by more than one at each iteration.

    For instance, if you know that your patches are always of size at least KxL, you can do the following:

    for( $y=$inity; $y<$h; $y += L) {
        for( $x=$initx; $x<$w; $x += K) {
            $pixel = getpixelat($img,$x,$y);
    
            if ($pixel == "892124" and getpixelat($img,$x+1,$y) == "1212224") {
                $px = $x; $py = $y;
                break 2;
            }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I need to find a particular entry in a journal using a CL
How can we find a particular stored procedure. I need to find a stored
I need to find an element that has a particular title. The only problem
I need to find out which table (name) a particular constraint belongs to. Does
Using a ruby file (or any rake facility) I need to find out if
I need to find all records for a particular resource and display them in
I need to find all SPs, which are used in particular page. Problem, that
I need to find attribute values in an ASPX file using regular expressions. That
I need to find all the groups a particular user is a member of.
I need to find the largest value from one particular column in a mysql

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.