# Working with Calibrated Images

VisionPro Deep Learning tools operate on pixel values and return results that are in pixel values. VisionPro tools operate on pre-defined or arbitrary coordinate spaces and return results in the context of the image's selected coordinate space. Therefore, when fixturing a calibrated image with PatMax, it is necessary to both ensure that the PatMax tool's results are in terms of pixels, and that the Deep Learning tool's results are in terms of the calibrated coordinate space.

## Using a PMAlign Tool to Fixture Calibrated Images for a Red Analyze Tool

The Pose produced by the PMAlign tool must be in terms of pixels to be correctly consumed by a Red Analyze tool. The PMAlign tool returns Poses that map points in Pattern Space to points in the Selected Space. When Pixel space is selected (or when Root space is selected and Root space = Pixel space), the Pose is already in terms of pixels.

There are cases where the Pose is not in terms of pixels, namely:

- The input image was subsampled by a VisionPro tool:
  - Selected space: Root ("@")
  - Root space != Pixel space
- The input image was calibrated:
  - Selected space: Calibrated space

Thankfully, the same procedure discussed in the standard case will handle images whose selected space is a calibrated space:

Tip:

###### API Example

    ICogTransform2D fromSelectedToPixelTransform = cogImage.GetTransform("#", ".");

    CogTransform2DLinear fromPatternToPixelLinearTransform = fromSelectedToPixelTransform.ComposeBase(<Pose>).LinearTransform(0, 0);

The transform "fromPatternToPixelLinearTransform" can then be passed to AddView to fixture the default View, even if the image is calibrated.

Without taking these precautions, the PMAlign tool will produce a Pose that is valid only in the calibrated space, leading to Views that are dramatically out of position in the Red Analyze tool. After the PMAlign tool Pose is transformed into Pixel space, however, the procedure for using the image and its Pose with the Red Analyze tool does not change.

## Working with Deep Learning Markings in a Calibrated Space

Deep Learning Markings present results in pixel coordinates – specifically, pixels relative to the origin of the View in which the results are found.

Consider a Red Analyze tool that returns a Marking with a single View and a single (square) defect:

- RedMarking
  - RedView
    - Region
      - (0, 0)
      - (1, 0)
      - (1, 1)
      - (0, 1)

The area of this Region is therefore one pixel, regardless of whether the image was calibrated or not. Using this wrapper, it is possible to convert a Marking into a new implementation of IMarking that contains calibrated results. The conversion process requires the marking, as well as the calibration transform (as a CogTransform2DLinear).

Suppose one pixel length is calibrated to five inches in the example above. The calibrated version is as follows:

- CalibratedRedMarking
  - CalibratedRedView
    - CalibratedRegion
      - (0, 0)
      - (5, 0)
      - (5, 5)
      - (0, 5)

Now, the Region.Area property would return 25, representing in2 in the calibrated space instead of pixels. This allows the same interface to be used for both calibrated results and un-calibrated results.

Note:

- The calibration transform can be retrieved from the calibrated image via ICogImage.GetTransform("#", "<CalibrationSpaceName>").

  This returns the transform from calibrated space to Pixel space.

- The calibrated implementations of the different Deep Learning markings are available in the ViDi2.VisionPro.Calibration namespace.

## Summary

When using PatMax and Deep Learning on a calibrated image, the PatMax tool must return Poses in terms of pixels. To interpret Deep Learning results in a calibrated space, a CalibratedMarking must be created from a (pixel) Marking and a calibration transform.