Image Stitching
Basics
In certain situations, a camera field of view is insufficient to capture the entire subject. To address this limitation, the camera is repositioned (frequently in a grid pattern) to acquire multiple, overlapping images. These images are then combined using a process known as image stitching, resulting in a final image that appears to have been captured in a single shot.
● | Here is an example used below: |
● | Use the class EImageStitcher to perform the stitching: |
□ | Use your already loaded and properly calibrated patches as inputs in an arbitrary order. |
□ | The patches do not need to be aligned (they can be arbitrarily rotated). |
□ | All input images must have the same resolution. |
List<EImageC24> patchs = new List<EImageC24>(); // should be already loaded
EImageStitcher stitcher = new EImageStitcher();
EImageC24 output = new EImageC24(); // no need to be sized beforehand
stitcher.Stitch(patchs.ToArray(), output);
You can also use this code with images EImageBW8.
Reference image
● | If your set of patches contains images with significantly different rotations, you can specify a reference image. |
Example of a subset of arbitrarily rotated images:
● | By default, the result image may appear unaligned as the EImageStitcher has no reference. |
● | To avoid this, specify the given patch to be used as the reference image. |
□ | The reference image is stitched onto the final image with no rotation, scale or skew. |
With the car picture set, the reference image is set as 1. In our example, that is:
● | The corresponding code is: |
List<EImageC24> patchs = new List<EImageC24>(); // should be already loaded
EImageStitcher stitcher = new EImageStitcher();
EImageC24 output = new EImageC24(); // no need to be sized beforehand
stitcher.StitchWithReferenceImage(patchs.ToArray(), output, 1); // the last argument specifies the reference image index
Parameters
Due to the strict constraints applied during the stitching process (to ensure the validity of the possible measurements applied afterward), the class EImageStitcher can fail to stitch certain sets of patches.
MaxFeatures and MaxPointMatch
The default values of the parameters MaxPointMatch and MaxFeatures work with most contexts:
□ | Adjust MaxFeatures when the input images are noisy or blurry. |
□ | Adjust MaxPointMatch if the input images are similar to one another or if they're are noisy or blurry. Decreasing MaxPointMatch value may improve the speed of the stitching. |
Use one of the samples or the new Open eVision Studio to determine the correct values for your project.
Image resolution
The parameters MaxPointMatch and MaxFeatures can heavily impact the time required by the stitching operation.
However, the most influential factor is the resolution of the input images as the stitching operation time does not increase linearly with the image resolution but rather exponentially.
□ | If possible, use input patches with a low resolution (for example, preprocessed with the EasyImage.Resize). |
FeatureScalingEnabled
The parameter FeatureScalingEnabled can help you achieve a better performance without sacrificing resolution:
□ | Use FeatureScalingEnabled to scale down the input image and speed up the finding of its feature Geometrical property of a coded element. points. |
□ | This does not affect the resolution of the output image as only the underlying computation is performed at a lower resolution. |
□ | This parameter may influence the overall precision of the stitching. |
Grid parameters
In most industrial cases, the position of the camera when the image is captured is approximately known. It's especially true when multiple cameras are positioned in a grid (or when a single camera is repositioned in a grid).
If the patches are submitted to the stitching method row by row, the stitching method can leverage that information and produce better and faster results.
Specifying a grid increases the constraints applied when computing the affine matrix. The stitching method assumes that there are about no differences in the rotation and the scaling between patches.
List<EImageC24> patchs = new List<EImageC24> {
image_0, image_1,
image_2, image_3, // images are ordered row by row
};
EImageStitcher stitcher = new EImageStitcher();
EImageC24 output = new EImageC24(); // no need to be sized beforehand
stitcher.Stitch(patchs.ToArray(), output, 2, 2); // as the grid is 2x2, colCount is 2 and rowCount is 2
Debugging
To better guide the debugging process, use the following methods to generate visualizations after a stitching operation (successful or not):
● | Use DrawPoints to draw, for a given image, the set of feature points used to stitch it. |
● | Use DrawTransformation to draw, for each stitched image, a transformed quadrangle (a quadrangle multiplied by the affine matrix used to stitch the image). |
Multithreading
The stitching method can greatly benefits from multithreading.
If your use-case allows it, enable it using :
Easy.MaxNumberOfProcessingThreads = int numberOfThreads;