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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:03:04+00:00 2026-05-13T18:03:04+00:00

What does this expression’s algorithm mean? p = ((p<<1)&0666) | ((q<<3)&0110) | (Image->scanLine(y+1)[x+1] !=

  • 0

What does this expression’s algorithm mean?

p = ((p<<1)&0666) | ((q<<3)&0110) | (Image->scanLine(y+1)[x+1] != 0);

Algorithm “Binary Image Thinning Using Neigborhood Maps” in a book “Graphics Gems IV”:

    static int  masks[] = {0200, 0002, 0040, 0010};

 uchar delete_[512] = 
 {
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,1,0,0,1,1,  0,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,1,1,1,0,1,1,  0,0,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  1,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,1,1,0,0,1,1, 
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  1,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,1,1,1,0,1,1,  1,1,1,1,1,1,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,0,0,0,0,0,0,  1,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,1,1,1,0,1,1,  1,1,1,1,1,1,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,1,1,1,0,1,1,  0,0,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,  0,0,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,0,0,0,0,0,0,  1,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,1,1,1,0,1,1,  1,1,1,1,1,1,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,0,0,0,0,0,0,  1,1,1,1,0,0,1,1,
  0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,
  1,0,1,1,1,0,1,1,  1,1,1,1,1,1,1,1
 };

  int xsize, ysize; 
  int x, y; 
 int i;  
 int count = 1; 
 int p, q;  
 uchar *qb;
 int m;


 xsize = Image->width();
 ysize = Image->height();
 qb = (uchar*) malloc (xsize*sizeof(uchar));
 qb[xsize-1] = 0;

    while(count) 
 { 
  count = 0;
  for (i = 0; i < 4; ++i) 
  {
   m = masks[i];
   p = Image->scanLine(0)[0] != 0;

   for (x = 0; x < xsize-1; ++x)
    qb[x] = p = ((p<<1)&0006) | (Image->scanLine(0)[x+1] != 0);

   // Scan image for pixel deletion candidates.
   for (y = 0; y < ysize-1; ++y) 
   {
    q = qb[0];
    p = ((q<<3)&0110) | (Image->scanLine(y+1)[0] != 0);

    for (x = 0; x < xsize-1; ++x) 
    { 
     q = qb[x];
     p = ((p<<1)&0666) | ((q<<3)&0110) | (Image->scanLine(y+1)[x+1] != 0);
     qb[x] = p;
     if  ((p&m)==0 && delete_[p])
     {
      count++;
      Image->scanLine(y)[x] = 0; 
     } 
    }
  • 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-13T18:03:05+00:00Added an answer on May 13, 2026 at 6:03 pm

    (See commented source code)

    The variables m, p, q, and elements of the qb array are 9-bit numbers that represent the 3×3-pixel “neighborhood” of a pixel.

    Suppose your image looks like this (each letter represents a pixel, which is either ‘on’ or ‘off’ (1 or 0, black or white):

        ---x---
        0123456
    | 0 abcdefg
    | 1 hijklmn
    y 2 opqrstu
    | 3 vwxyz{|
    

    The pixel at (x,y) location (2,1) is j. The neighborhood of that pixel is

    bcd
    ijk  // 3x3 grid centered on j
    pqr
    

    Since each pixel has a binary value, the neighborhood can be represented in 9 bits. The neighborhood above can be written out linearly, expressed in binary as bcd_ijk_pqr. The grouping of 3 pixels in a row makes octal a good choice, since each octal digit represents three bits.

    Once you have a neighborhood expressed as a 9-bit value, you can do bit-manipulation on it. An operation such as ((p << 1) & 0666) takes a neighborhood, shifts all bits to the left one position, and clears the rightmost column of bits. For example, the shift changes bcd_ijk_pqr to cdi_jkp_qr@ (where @ represents a ‘null’ bit, by default 0). Then the mask changes it to cd@_jk@_qr@. Expressed in 3×3 grid form:

    cd@
    jk@
    qr@
    

    Essentially, the whole grid has been shifted to the left.

    Similarly, an operation such as ((q << 3) & 0110) shifts all bits three positions (moves rows up) and clears the first two columns of bits. So bcd_ijk_pqr becomes ijk_pqr_@@@ and then after the masking, becomes @@k_@@r_@@@.

    The gist of the algorithm is to evaluate the neighborhood of each pixel to determine whether to turn that pixel off (delete it). This line does the evaluation:

    if  ((p&m)==0 && delete_[p])
    

    Everything that precedes that line is done to set up the neighborhood in p. The code is written so that each pixel value is read exactly once per pass.

    The qb array stores the neighborhood for each pixel in the previous scanline. Note that the elements of qb are only 8-bits wide. This means the upper-left pixel of the neighborhood is omitted. That is not a problem, since any time qb is used, it gets shifted up a row.

    So to answer your question about what this line does:

    p = ((p<<1)&0666) | ((q<<3)&0110) | (Image->scanLine(y+1)[x+1] != 0);
    

    It creates the neighborhood of a pixel by merging the following:

    • the neighborhood of the previous pixel on the same line, shifted to the left
    • the right column of the neighborhood of the pixel one row higher, shifted up
    • the (x+1,y+1) pixel of the image, put into the “southwest” corner

    For example, the neighborhood about j is calculated as:

    p = bc@_ij@_pq@ | @@d_@@k_@@@ | r
    
        bc@ | @@d | @@@   bcd
    p = ij@ | @@k | @@@ = ijk
        pq@ | @@@ | @@r   pqr
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 295k
  • Answers 295k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In short, yes. May 13, 2026 at 6:58 pm
  • Editorial Team
    Editorial Team added an answer It's the same to define a type of varchar2(10) or… May 13, 2026 at 6:58 pm
  • Editorial Team
    Editorial Team added an answer you can create type dynamically using new features in C#… May 13, 2026 at 6:58 pm

Related Questions

What does this expression in Perl programming do? $variable =~ /^\s*$/;
I am confused as to what boost::bind does when we bind to member variables.
What does this error mean? Generic.h:25: error: 'Generic' is not a template type Here's
I'm just to figure out what does this method do, I know there must
I have this regex I built and tested in regex buddy. _ [ 0-9]{10}+

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.