Masks are used in Metashape to specify the areas on the photos which can otherwise be confusing to the program or lead to incorrect reconstruction results. Workflow can be used in Professional and Standard versions. The article describes the following workflows:


Generate and edit masks manually 


Recommended masking all irrelevant elements on the source photos (background, accidental foreground, etc.). Masks in Metashape are represented by contours bounding certain image regions. Modification of the current mask is performed in Photo View through adding or subtracting selections.


In Metashape, the area that will not be taken into account during processing is masked. That is, if you want the background not to be used around the object, then you need to mask the background, and not create a mask for the object.



1. To switch to the Photo View double-click on the corresponding photo in the Workspace or Photo pane. 




2. To create a selection using one of the supported Selection tools (available from the Toolbar or Photo menu). In the project, we selected an object using the Intelligent Scissors:



When using Intelligent Scissors, it is possible to automatically create vertices along the border of an object, for this you need to hold down the Ctrls key and guide along the border of the object, to add them, you need to click with the left mouse button. To complete the selection of an object, press ESC. 

When using a Magic Wand, use Ctrl and Shift respectively to add and remove areas. To reset mask selection on the current photo press Esc key.

To undo a previously drawn vertex at the moment of drawing, use Ctrl+Z. 



3. The selection wouldn't be incorporated in the current mask until it is merged with the mask using Add selection, Subtract selection, Invert selection buttons from the Toolbar:


To display the mask in Model view click Show mask on the Toolbar:



If some part of the model was accidentally masked, then to remove the mask from this area, you also need to use the selection tools to create an area around the desired element and click Subtract selection button on the Toolbar:



The mask display color can be changed in the Metashape Preferences dialog window. Select Tools > Preferences... and open Appearance tab > Photo View:


To see which image masks are created, you can also click on the Show mask in the Photo pane:




Masked areas could be ignored at Align Photos processing stage (set Apply masks to option in Align Photos dialog) and are always ignored at Build Model and Build Texture stages.


Generate masks (automatically)


There are several ways to create masks automatically in Metashape: from the mesh model, from background images and automatic (AI method).  


Select Tools > Generate Mask. In the dialog box, select one of the required methods:



As a result, masks will be created automatically depending on the method you choose.


To generate mask based on reconstructed 3D model 


In the Generate Masks dialog select Method - From Model and select the necessary parameters to create a mask:



For this method, it is important that the project should have a built mesh model.


The following parameters can be specified: 


Operation - specifies how the new masks should be combined with the existing ones if masks already exist in the project:

  • Replacement - new mask will be loaded and stored instead of the original one. 
  • Union - two masks will be united and stored. 
  • Intersection - the intersection of the two masks will be stored as a new mask for the photo. 
  • Difference - only the difference between two masks will be stored as a new mask for the photo.

Mask defocus areas - enabled applying masks to the areas that are out of focus based on the depth information of each point. 

Blur threshold - parameter defines the allowed blur radius on a photo in pixels. In most cases, we recommend using the 2 or 3 pixels. 

Depth threshold - parameter sets the distance from the camera beyond which the image area will be masked. Available only for the scaled model. 

Apply to - specifies whether masks should be created:

  • All images - generate masks for all images in active chunk. 
  • Selected images - generate mask for the currently selected images (if any). 
  • Entire workspace - generate masks for all chunks in the project. 
  • Current photo - generate mask for the currently opened photo (if any) 


To generate mask from background images 


 In the Generate Masks dialog select Method - From Background Images and select the necessary  parameters to create a mask:



The following parameters can be specified:
Operation - specifies how the new masks should be combined with the existing ones if masks already exist in
the project.

  • Replacement - new mask will be loaded and stored instead of the original one.
  • Union - two masks will be united and stored.
  • Intersection - the intersection of the two masks will be stored as a new mask for the image.
  • Difference - only the difference between two masks will be stored as a new mask for the photo.

Filename template - specifies the file name template used to generate mask file names. This template can contain special

tokens, that will be substituted by corresponding data for each photo being processed. The following tokens are supported:

  • {filename} - file name of the source photo without extension.
  • {fileext} - extension of the source photo.
  • {camera} - camera label.
  • {frame} - frame number.

Tolerance - specifies the tolerance threshold used for background differencing. Tolerance value should be set according to the color separation between foreground and background pixels. For larger separation higher tolerance values can be used.

Apply to - specifies whether masks should be created.

  • All images - generate masks for all images in active chunk.
  • Selected images - generate mask for the currently selected images (if any).
  • Entire workspace - generate masks for all chunks in the project.
  • Current photo - generate mask for the currently opened photo (if any).


To generate mask automatic (AI) 



 In the Generate Masks dialog select Method - Automatic (AI) and select the necessary parameters to create a mask.


AI can be used to generate masks for the background. When using the tool for the first time, it is important that you have an Internet connection to download the AI model.


Export masks


The created mask can be also saved for external editing or storage.


1. Select Export Masks... command from the File menu (File > Export > Export Masks...).


2. In the Export Mask dialog select suitable parameters. Click OK button when done.



File type - specifies the type of generated files:

  • Single channel mask image - generates single channel black and white mask images
  • Image with alpha channel - generates color images from source photos combined with mask data in alpha channel


Filename template - specifies the file name template used to generate mask file names. This template can contain special tokens, that will be substituted by corresponding data for each photo being processed. The following tokens are supported:

  • {filename} - file name of the source photo without extension;
  • {fileext} - extension of the source photo;
  • {camera} - camera label;
  • {frame} - frame number;
  • {filenum} - sequential number of the mask being exported.


3. Browse to the folder where the masks should be saved and select it.


4. The progress dialog box will appear displaying the current processing status. To cancel processing click Cancel button. 


When importing/exporting mask for the current photo only, Metashape will prompt for the actual image instead of image folder. Mask file names parameter will not be used in this case. 


Import masks


Masks can be loaded from external sources, as well as generated automatically from background images if such data is available. Metashape supports loading masks from the following sources:

  • from alpha channel of the source photos;
  • from file (separate images).


1. Select Import Masks... command from the File menu (File > Import Masks...).


2. In the Import Mask dialog select suitable parameters. Click OK button when done.



Parameters in the Import Masks dialog window: 

Method - specifies the source of the mask data (From Alpha or From File):

  • From Alpha - load masks from alpha channel of the source photos. 
  • From File - load masks from separate images.

Operation - specifies the action to be done in case a second mask is imported for the photo.

  •  Replacement - new mask will be loaded and stored instead of the original one. 
  • Union - two masks will be united and stored. 
  • Intersection - the intersection of the two masks will be stored as a new mask for the photo. 
  • Difference - only the difference between two masks will be stored as a new mask for the photo. 

Filename template (not used in From alpha mode) - specifies the file name template used to generate mask file names. This template can contain special tokens, that will be substituted by corresponding data for each photo being processed. The following tokens are supported: 

  • {filename} - file name of the source photo without extension. 
  • {fileext} - extension of the source photo. 
  • {camera} - camera label. 
  • {frame} - frame number. 
  • {filenum} - sequential number of the mask being imported

For example, {filename}_mask.png template can be used if masks are available in PNG format and have a _mask suffix. 

Apply to - specifies whether masks should be imported for the currently opened photo, active chunk or entire Workspace

  • All cameras - load masks for active chunk. 
  • Entire workspace - load masks for all chunks in the project. 
  • Selected cameras - load mask for the currently checked cameras (if any). 
  • Current photo - load mask for the currently opened photo (if any).