Flexible Masks
ROIs vs flexible masks
ROIs and masks restrict processing to part of an image:
□ | ROI Main Properties apply to all Open eVision functions. Using Regions of Interest accelerates processing by reducing the number of pixels. Open eVision supports hierarchically nested rectangular ROIs. |
□ | Flexible Masks are recommended to process disconnected ROIs or non-rectangular shapes. They are supported by some EasyObject and EasyImage library functions. |
Flexible Masks
A flexible mask is a BW8 image with the same height and width as the source image. It contains shapes of areas that must be processed and ignored areas (that will not be considered during processing):
□ | All pixels of the flexible mask having a value of 0 define the ignored areas. |
□ | All pixels of the flexible mask having any other value than 0 define the areas to be processed. |
|
|
|
Source image |
Associated mask |
Processed masked image |
A flexible mask can be generated by any application that outputs BW8 images and by some EasyObject and EasyImage functions.
1. | Call the functions from EasyImage that take an input mask as an argument. For instance, one can evaluate the average value of the pixels in the white layer and after in the black layer. |
2. | Display the results. |
Resulting image
● | EImageEncoder::.Encode has a flexible mask argument for BW1, BW8, BW16, and C24 source images. |
● | AutoThreshold. |
● | Histogram (function HistogramThreshold has no overload with mask argument). |
● | RmsNoise, SignalNoiseRatio. |
● | Overlay (no overload with mask argument for BW8 source images). |
● | ProjectOnAColumn, ProjectOnARow (Vector projection). |
● | ImageToLineSegment, ImageToPath (Vector profile). |
Flexible Masks in EasyObject
A flexible mask can be generated by any application that outputs BW8 images or uses the Open eVision image processing functions.
EasyObject can use flexible masks to restrict blob analysis to complex or disconnected shaped regions of the image.
If an object of interest has the same gray level as other regions of the image, you can define "keep" and "ignore" areas using flexible masks and Encode functions.
A flexible mask is a BW8 image with the same height and width as the source image.
□ | A pixel value of 0 in the flexible mask masks the corresponding source image pixel so it doesn't appear in the encoded image. |
□ | Any other pixel value in the flexible mask causes the pixel to be encoded. |
Source image
1. | To encode and extract a flexible mask, first construct a coded image from the source image. |
2. | Choose a segmentation method (for the image above the default method GrayscaleSingleThreshold is suitable). |
3. | Select the layer(s) of the coded image that should be encoded (i.e. white and black layers using minimum residue thresholding). |
4. | Make the mask image the desired size using mask.SetSize(sourceImage.GetWidth(), sourceImage.GetHeight()). |
5. | Exploit the flexible mask as an argument to ECodedImage2::.RenderMask. |
BW8 resulting image that can be used as a flexible mask
6. | Select the coded elements of interest. |
7. | Create a loop extracting a mask from selected coded elements of the coded image using ECodedElement::.RenderMask. |
8. | Optionally, compute the feature value over each of these selected coded elements. |
BW8 resulting image that can be used as a flexible mask
EObjectSelection::.RenderMask can, for example, discard small objects resulting from noise.
BW8 resulting image that can be used as a flexible mask
Find four circles (left) Flexible mask can isolate the central chip (right)
9. | Declare a new ECodedImage2 object. |
10. | Setup variables: first declare source image and flexible mask, then load them. |
11. | Declare an EImageEncoder object and, if applicable, select the appropriate segmenter. Setup the segmenter and choose the appropriate layer(s) to encode. |
12. | Encode the source image. Encoding a layer with just the area in the flexible mask is then pretty straightforward. We see that the circles are correctly segmented in the black layer with the grayscale single threshold segmenter: |
13. | Select all objects of the coded image. |
14. | Select objects of interest by filtering out objects that are too small. |
15. | Display the blob feature by iterating over the selected objects to display the chosen feature. |