Skip to content
STAGING SERVER
DEVELOPMENT SERVER

Grid Creator vTool#

The Grid Creator vTool creates a grid overlay that divides an image into individual cells. By dividing an image into cells, subsequent vTools can evaluate the contents of the individual cells instead of the image as a whole.

The Grid Creator vTool accepts an image via the Image input pin and outputs information about the grid via its output pins.

To design the grid, you have to specify the number of rows and columns and the height and width of the individual cells. You can also configure whether you want the grid to cover the whole image or just a part of it. By default, the grid starts at the top left pixel of the image. By specifying an offset, you can place the grid where your region of interest begins. You can also specify gaps between the cells, effectively reducing the size of the cells, if you're only interested in specific parts of the image.

Download the pylon Software Suite to use the Grid Creator vTool.

Grid Creator vTool

Prerequisites#

  • If you're configuring the grid size manually, the size of the images has to remain constant in your application. If image sizes vary, the grid may not fit anymore.
  • Before you can configure the Grid Creator vTool, you have to connect its Image input pin to the Image output pin of another vTool.

Use Cases#

There are different scenarios when using the Grid Creator depending on whether you want the grid to cover the whole image or a part of the image.

The scenarios require different approaches when configuring the vTool.

In both cases, it may be useful to configure gaps between neighboring cells in order to reduce the relevant area even further. See Configuring Gaps Between Cells for details.

Grid Covering the Whole Image#

This is the straightforward case. You take the source image, count the rows and columns, and enable the Auto Size Grid option. This is a sample input image:

Grid Creator vTool Input Image With Grid Covering the Whole Image - AI Generated

There are 5 columns and 5 rows. The necessary settings look like this:

Parameter Settings for When the Grid Covers the Whole Image

Open a pin data view and select the Image pin of the image source vTool and the GridCreator Rectangles pin. If you run the recipe now, you will see that the image has been divided into 25 cells:

Pin Data View Grid Creator

If the Regions output pin is enabled (default setting), a colored overlay shows the grid more clearly:

Pin Data View Grid Creator With Regions Output Pin Enabled

Grid Covering Part of the Image#

This use case requires a few more steps. The sample image shows 30 AA batteries placed in a box. The spacing between them is irregular, and they don't fill the entire image.

Grid Creator vTool Input Image With Grid Covering Part of the Image - AI Generated

You start again by counting the columns and rows: 5 columns and 6 rows. If you enter these values and enable the Auto Size Grid option, the result would look like this (with Regions output pin enabled):

Pin Data View Grid Creator - Partial Grid - Offset Not Considered

As you can see, a grid with 30 cells has been placed over the image. Because the margin hasn't been considered, however, not every cell contains exactly one battery. Especially in column 4, the result would be ambiguous as there are parts of two batteries visible in a cell.

To improve the grid layout, disable the Auto Size Grid option. Instead, you have to manually specify cell width and height, i.e., the width and height of the batteries, as well as vertical and horizontal offsets, i.e., where you want the grid to start. By default, the grid's origin is in the top left corner (0,0).

By pointing your mouse at a pixel, you can view the pixel's coordinates in the status bar of the image window.

Grid Creator - Determining Grid Layout

Using the pixel coordinates, you can determine the necessary properties of your grid and specify the corresponding parameter values.

Parameter Settings for When the Grid Covers Part of the Image

You can fine-tune width, height, and offsets while the recipe is running until you are satisfied. The end result could look like this:

Grid Creator - Result Image

You can see that each of the 30 batteries is covered by a cell of the grid.

Configuring Gaps Between Cells#

Gap X and Gap Y define the horizontal and vertical gaps between neighboring cells, in pixels. The default value is 0, which means that the cells are directly adjacent. The gap is inserted between cells only.

The other settings depend on whether the grid covers the whole image or only part of it.

Grid Covering the Whole Image#

Leave the Auto Size Grid option enabled and specify Gap X and Gap Y.

The vTool calculates the cell size from the image size and the gaps. Gap X reduces the cell width and Gap Y reduces the cell height. The grid origin stays at the top-left pixel. With Auto Size Grid enabled, Cell Width, Cell Height, Offset X, and Offset Y stay unavailable.

The calculated cell size is a whole number of pixels. If the image size doesn't divide evenly, the remaining pixels stay outside the grid. If the gaps take up the whole image, the recipe reports an error and no cells are created.

Grid Covering Part of the Image#

Disable the Auto Size Grid option. Cell Width and Cell Height stay at the values you enter, and Gap X and Gap Y add space between those cells.

The sample image shows 12 boxes with labels printed on them. Part of each label is a QR code that you want to read (highlighted yellow in the following image). The QR codes are the same size, the spacing between them is regular, and they fill only part of the image.

Grid Creator vTool Input Image With Gaps Between Cells - AI Generated

Count the columns and rows: 4 columns and 3 rows. By pointing your mouse at a pixel, you can view that pixel's coordinates in the status bar of the image window. Use those coordinates to set the following parameters:

  • Cell Width and Cell Height: Width and height of one QR code
  • Offset X and Offset Y: Distance from the top-left pixel of the image to the first QR code. Until you change the offsets, the grid origin is that top-left pixel (0,0).
  • Gap X and Gap Y: Space between two neighboring QR codes

If you leave Gap X and Gap Y at 0, the cells are directly adjacent. A cell then contains part of one label and part of the neighboring label.

Set Gap X and Gap Y to the space between the QR codes so that the cells don't touch. Cell Width and Cell Height remain the width and height of a single QR code, and each cell covers only the QR code.

The offset, the cells, and the gaps between the cells have to fit inside the image. If they extend past the image, the recipe reports an error and no cells are created.

You can fine-tune the width, height, offsets, and gaps while the recipe is running.

Grid Creator with Gaps Between Cells - Result Image

You can see that each of the 12 QR codes is covered by a cell of the grid.

Configuring the vTool#

To configure the Grid Creator vTool, double-click it in the Workbench. A dialog opens showing all the available settings. Alternatively, you can find the same settings in the Features - All pane.

Grid Creator vTool Settings

Connect the Image input pin of the Grid Creator vTool to the Image output pin of an image source (e.g., a Camera vTool or Image Loading vTool). Then, choose the procedure that matches your use case:

Configuring a Grid Covering the Whole Image#

  1. Enable the Auto Size Grid parameter.
  2. In the Number of Columns and Number of Rows input fields, specify how many cells you need across and down the image.
  3. If the cells should not touch each other, specify Gap X and Gap Y. The vTool calculates the cell width and height automatically and shrinks the cells to accommodate the gaps.

Configuring a Grid Covering Part of the Image#

  1. Disable the Auto Size Grid parameter. The Cell Width, Cell Height, Offset X, and Offset Y parameters become available.
  2. In the Number of Columns and Number of Rows input fields, specify the number of cells across and down the grid.
  3. In the Cell Width and Cell Height input fields, enter the width and height of an individual cell in pixels.
  4. In the Offset X and Offset Y input fields, specify the distance (in pixels) from the top-left pixel of the image (0,0) to where the first cell should start.
  5. If the cells should not touch each other, specify the distance between neighboring cells in the Gap X and Gap Y input fields.

Ensure that the total grid extent (offsets + cells + gaps) does not exceed the width and height of the image. Otherwise, the vTool reports an error when running the recipe.

Tip

If the Regions output pin is enabled (default setting), an overlay is displayed over the input image showing the individual cells. This allows you to immediately see the effects of your configuration in the pin data view while the recipe is running:

  1. Make sure the Regions Output Pin parameter is enabled.
  2. Open a pin data view and select the Image pin of the image source vTool and the Regions pin of the Grid Creator.
  3. Start the recipe.

If you hover over a pixel in the image, the status bar of the pin data view shows the coordinates of that pixel (X/Y). You can use these coordinates to determine the offsets, cell dimensions, and gaps.

Inputs#

Image#

Accepts images directly from a Camera vTool or any other vTool that outputs images.

  • Data type: Image
  • Image format: All formats are accepted. The Grid Creator only reads the width and height of an image, not the pixel format.

Outputs#

Rectangles#

Returns a rectangle for each cell of the grid.

  • Data type: RectangleF Array

Regions#

Returns one region per cell of the grid and visualizes the regions in the image.

  • Data type: Region Array

Typical Predecessors#

Typical Successors#