Preprocess
This module is intended for image preprocessing.
It is commonly used to scale down images to reduce processing times/memory usage, cropping pictures to avoid defect detection outside ROIs (Regions of Interest), and other examples mentioned below.
The following modifications are available in this module:
Cut
Cut lets you crop the image manually from all four sides by adjusting the sliders on the right side of the image or by drawing a rectangle around the area you want to crop out and then pressing the Crop button whicg is located under the slider.
The slidebars on the right side of the image let you choose from which side of the image and how many pixels to cut.
If you use the Crop button, the slidebars will adjust automatically.
This is useful when the area on which the detection is required is only on a portion of the image. Cutting the image can shorten training and detection times and prevents detection outside of ROI.
The same cut will apply to all images, so make sure that the are for detection is in the same portion of the image among all the images.
Scale
Scale lets you adjust the resolution of the image.
The value slider specifies the factor by which the image size is adjusted. For example, if you change the value to 0.5 just like on the second image, each side of the image will be halved.
This can be useful when the defects on the image are alrge and clearly visible and thus the resolution of the image doesn’t need to be so high. Reducing the resolution can shorten inference and training times.
Rotation
You can rotate all images anti-clockwise by a specified angle.
Background normalization
Background normalization serves for unifying colors. It evaluates each pixel and based on how many surrounding pixels are of a similar colour it shifts that pixel closer to gray. The value specifies the size of the are in which it takes the surrounding pixels into consideration, meaning the lower the value, the more gray/shifted will the resulting image be.
Blur
This function blurs the picture and reduces noise. Blur blurres the image by averaging the value of a pixel depending on the values of the surrounding pixels. The value specifies the area in which the surrounding pixels are use to calculate the new pixel value. For example, with value set to 100, it would calculate a value of a pixel based on it’s surrounding pixels in a 100 by 100 rectange around that pixel.
Canny Edge Detector
Canny edge detector focuses only on the edges of the objects. You can set the Threshold value to highlight the edges, the higher the Threshold value, the larger the edge must be for it to be shown on the processed image. Details in the OpenCV documentation.
Remove background
Remove background function can help you with focusing only on the main object. Offers two types of background removal (histogram and canny), and each can be useful for different kinds of images. The Canny background removal uses either canny edge detector, dilation, and erosion or OpenCV histogram.
Canny Edge Histogram
When removing background using the Canny Edge detector, you can set the blur size (it blurs the image based on the data of pixels in an NxN rectangle, you set the N in the “Blur” field). Threshold is for setting the size of the edges that will be kept. The rest are settings for Dilataion and Erosion.
Histogram removes background based on the frequency of colors of pixels. The pixel values with frequency between Extreme 1 and Extreme 2 will be kept.
The Background Color table can be used to choose which color to set the removed part of the image to.
Unifier
Unifies the position and angle of objects or just puts the angle of the object into Context (if this option is ticked). Remove background that needs to be used before Unifier and have the same background color selected.
Contrast equalisation
Equalises the contrast using the CLAHE algorithm, which works with a histogram of a pixel and its surroundings (depending on the kernel size). The clip limit determines the value at which the histogram is clipped. Details in the OpenCV documentation for CLAHE and histogram equalisation.
Dilation
Can be used to expand light shapes found in the input image. Details in the OpenCV documentation for dilate and morphological transformations.
Erosion
Can be used to reduce light shapes found in the input image. Details in the OpenCV documentation for erode and morphological transformations.
Polar transform
Finds the biggest circle in the image (found circle can be seen in the left image showing the Stage 1 layer of polar transform), then transforms it using polar coordinates. Minimal distance between circles can be used to adjust how many circles will be found by defining a minimum distance that needs to be between their centers. The inverse ratio of the accumulator/image resolution is used to adjust accumulator resolution (the lower the ratio, the higher the accumulator resolution). Details in the OpenCV documentation for Hough circles and polar warp.
Color space transform
Converts the image into a different color space (HLS, HSV, YUV, LAB, or GRAY). Details in the OpenCV documentation.
Adjust gamma
This function lets you adjust the gamma value.
Camera calibration
This function can be used to remove some camera-related distortions of the image.
It uses a calibration pattern, which needs to be photographed by the camera that we are going to use for inspection and at the position where the inspected objects will be. This pattern can be downloaded from the OpenCV website and then printed out to place at the inspection site. When we make a photo of this pattern with our camera, we select it as the template image, and then all images will be transformed in the same way.
The Calibration subfunction removes the “fisheye” effect (straight lines of the pattern look curved outwards to the edges of the image), and the result of the transformation on our sample image looks like this:
The Perspective transform performs a transformation of the image in a way that the pattern will end up looking as if it's placed perpendicular to the camera (correction for situations where the inspection plane is somehow tilted in relation to the camera).
Kernel size
Some transformations use a parameter called Kernel size, which determines the size of the matrix of surrounding pixels, which are taken into consideration when computing the transformation in a given pixel.
Iterations
This parameter controls how many times a given transformation is performed. This is used e.g. for the Erosion or Dilation functions, which are local transformations whose output changes when they’re applied to the image multiple times subsequently.
Active
Using the Active checkbox, the whole module can be enabled or disabled. You can also enable/disable each function individually. When a new module or individual function is created, it is automatically set as active.
Order of functions, changing layers
Individual functions are applied one after another from the top. You can change the order of the functions so that they suit your needs best, just drag and drop them to the right place. If you want to see how the image looks after applying individual active modifications (and its stages in some cases), you can change layers using the button at the top, which is set to Show all layers by default.