Metashape offers the defocus masking feature that can help with improving blurred texture in particular areas of the object. When capturing a scene with depth variability it is common that not all parts of the scene have the same level of sharpness on one image: some areas will be inevitably out of focus. It is suggested that the blurred areas on the images should be excluded from the processing to improve texture quality. The tool described in the current tutorial allows excluding such areas prior to the texture blending procedure by applying the masks automatically to out-of-focus areas. 

This function is available in Agisoft Metashape Professional version only, because the algorithm relies on the model's dimensions on a real-world scale. In our example we have created a scale bar between two points (defined by the markers) setting the length for the sword - element that can be measured directly on the real object: 

Refer to the following articles in order to check, how to scale model: Scale bar and Coded targets and Scale bars

Contents of this article:

It is also important that the camera calibration parameters (focal length and pixel size) in the Camera Сalibration dialog window are specified. If the values were not automatically loaded from EXIF, then you can specify them manually. Select Tools > Camera Calibration and specify the appropriate values:

To generate a mask for defocus areas

1. Select Generate Masks command from the Model submenu from Tools menu (Tools > Model > Generate Masks...). At this point, you should already have a mesh model generated in the active chunk.

2. In Generate Masks dialog select suitable parameters:

  • enable "Mask defocus areas" option. 
  • define Blur threshold parameter. 

You can choose Blur Threshold parameter value experimentally, but in most cases, we recommend using the 2 or 3. The Blur threshold parameter defines the allowed blur radius on a photo in pixels:

3.  Click OK button when done. The progress dialog box will appear displaying the current processing status. To cancel processing click Cancel button. 


In the examples below the images on the left-hand side are original photos, and automatic masks with defocus masking feature were applied to the images on the right-hand side. The illustration demonstrates that the set Blur threshold (it is equal to 3 in our dataset) worked well to mask out the out-of-focus areas on the images (such as griffin's tail), while other parts of the model are not masked. Additionally, the tool automatically masks out the background that is not present in the actual model. The parts of the image covered by the mask appear darker on the preview. 

It is important to note that automatic masking uses the reconstructed mesh model, therefore the more detailed model will provide better results.

The tool can be applied to all cameras in the project or only to one or several images specified by the user:

After masks for defocus areas are generated you may proceed to the texture generation via Workflow > Build Texture... command.