Flexible Masks

ROIs vs flexible masks

ROIs and masks restrict processing to part of an image:

  • Using Regions of Interest accelerates processing by reducing the number of pixels. eVision supports hierarchically nested rectangular ROIs.

  • Flexible Masks are recommended to process disconnected ROIs or non-rectangular shapes. They are supported by some functions of EasyObject and EasyImage.

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.

../../../_images/flexiblemaskssourceimage.webp

Source image

../../../_images/flexiblemasksassociatedmask.webp

Associated mask

../../../_images/flexiblemasksprocessingmaskedimage.webp

Processed masked image

A flexible mask can be generated by any application that outputs BW8 images by some functions of EasyObject and EasyImage.

Flexible masks in EasyImage

Code Snippets

../../../_images/easyobjectflexmaskssource.webp

Source image

../../../_images/easyobjectflexmasks1.webp

Mask variable

Simple steps to use flexible masks in EasyImage

  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.

../../../_images/easyobjectflexmasks2.webp

Resulting image

EasyImage functions that support flexible masks

Flexible masks in EasyObject

A flexible mask can be generated by any application that outputs BW8 images or uses the 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 EImageEncoder::Encode .NET Python 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.

EasyObject functions that create flexible masks

../../../_images/easyobjectflexmaskssource.webp

Source image

ECodedImage2.RenderMask: from a layer of an encoded 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 .NET Python.

../../../_images/easyobjectflexmasks1.webp

BW8 resulting image that can be used as a flexible mask

ECodedElement.RenderMask: from a blob or hole

  1. Select the coded elements of interest.

  2. Create a loop extracting a mask from selected coded elements of the coded image using ECodedElement::RenderMask .NET Python.

  3. Optionally, compute the feature value over each of these selected coded elements.

../../../_images/easyobjectflexmasks2.webp

BW8 resulting image that can be used as a flexible mask

EObjectSelection.RenderMask: from a selection of blobs

EObjectSelection::RenderMask .NET Python can, for example, discard small objects resulting from noise.

../../../_images/easyobjectflexmasks3.webp

BW8 resulting image that can be used as a flexible mask

Example: Restrict the areas encoded by EasyObject

../../../_images/easyobjectinputmasksource.webp

Find four circles

../../../_images/easyobjectinputmaskmask.webp

Flexible mask can isolate the central chip

  1. Declare a new ECodedImage2 .NET Python object.

  2. Setup variables: first declare source image and flexible mask, then load them.

  3. Declare an EImageEncoder .NET Python object and, if applicable, select the appropriate segmenter. Setup the segmenter and choose the appropriate layer(s) to encode.

  4. 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 (EGrayscaleSingleThresholdSegmenter .NET Python):

../../../_images/easyobjectinputmaskresult.webp
  1. Select all objects of the coded image.

  2. Select objects of interest by filtering out objects that are too small.

  3. Display the blob feature by iterating over the selected objects to display the chosen feature.