mojiiz
mojiiz

Reputation: 274

Why? specific pixel processing should be process (h, w) not (w, h) or (x, y)

Some sample code about image processing using OpenCV give somethings like this:

for(i=0;i<height;i++)
{
      for(j=0;j<width;j++)
      {
          if(pointPolygonTest(Point(i,j),myPolygon))
          {
                 // do some processing
          }
      }
}

In the iteration, why we need to start from height and width? and also why the Point is store (height, width) so that is -> (y,x) ?

Upvotes: 1

Views: 112

Answers (2)

sgarizvi
sgarizvi

Reputation: 16816

Actually here, the row/column convention is used to iterate over the whole image.

height = Number of Rows

width = Number of Columns

The image is being accessed row wise.The outer loop is iterating over rows of the image and the inner loop is iterating on columns. So basically i is the current row and j is the current column of the image.

The inner loop processes a complete row of the image.

Upvotes: 1

masoud
masoud

Reputation: 56539

Ranges between [0..Height] and [0..Width] are maximum boundaries of your working area.

This code is testing which pixels of whole image are inside the polygon myPolygon.

The word "whole" means you should check all pixels of your image so you should iterate from 0 to height for Y, and iterate from 0 to width for X.

Upvotes: 2

Related Questions