Create Binary Mask (Image Analyst)

Available with Image Analyst license.

Summary

Converts an input raster dataset to a binary raster. Pixels are labeled as either mask or background based on user-defined values.

Usage

  • This tool classifies an input raster as background or mask based on parameter values and outputs a binary mask raster in which a value of 1 indicates mask pixels and a value of 0 indicates background pixels.

    Note:

    Create the initial background of the input raster by first using a threshold function such as Remap, Binary Thresholding, Zonal Remap, Mask, math operators (<, <, >, >), and others.

  • When the output binary mask raster is applied to a raster, the pixels that overlap the background pixels of the binary mask raster will be turned into NoData.

  • Using this tool, you can eliminate small regions, shrink or expand regions, fill small background regions, and smooth boundaries.

  • The Flood Fill from Image Boundary parameter allows you to specify whether pixels within the mask boundary will be classified as background.

  • Use the Flood Fill from Image Boundary parameter if you want to create a mask of an island that maintains the water pixels on the island as mask values. The tool performs flood fill on the water pixels and ends when it reaches the land pixels. The output mask boundaries will remain intact.

    Flood Fill from Image Boundary parameter results
    The Flood Fill from Image Boundary parameter is checked (first image) and unchecked (second image).

  • The units for the Expand Mask and Expand Background parameter values are pixels. Values can be negative, which results in shrinking the mask and background.

  • To remove small groups of background pixels, use a negative value for the Expand Mask parameter, and a positive value for the Expand Background parameter.

Parameters

LabelExplanationData Type
Input Raster

The input raster dataset. If the input is multiband, the first band will be used by default.

Mosaic Layer; Raster Layer; Image Service; String; Raster Dataset; Mosaic Dataset
Output Mask Raster

The output binary raster dataset. Supported formats are TIFF, CRF, and PNG.

Raster Dataset
Background Value
(Optional)

The background value for the output raster. The default value is 0.

Double
Flood Fill from Image Boundary
(Optional)

Specifies how background pixel values will be determined.

  • Checked—Background pixel values will be determined by the flood fill operation, which fills the connected pixels from the image boundary to the mask boundary. Pixels inside the mask will not be converted to background regardless of their value.
  • Unchecked—Background pixel values will be determined by the specified background value. This is the default.

Boolean
Expand Background
(Optional)

The number of pixels that will be used to expand or shrink the background. Negative values will shrink the background.

Long
Expand Mask
(Optional)

The number of pixels that will be used to expand or shrink the mask. Negative values will shrink the mask.

Long
Minimum Mask Region Size
(Optional)

The number of connected pixels that will be used to define a mask region. Mask regions that are smaller than this size will be classified as background.

Long
Set Background as NoData
(Optional)

Specifies whether the background value will be set to NoData.

  • Checked—The background value will be set to NoData.
  • Unchecked—The background value will not be set to NoData. This is the default.

Boolean

CreateBinaryMask(in_raster, out_raster, {background_value}, {flood_fill}, {expand_background}, {expand_mask}, {min_region_size}, {background_nodata})
NameExplanationData Type
in_raster

The input raster dataset. If the input is multiband, the first band will be used by default.

Mosaic Layer; Raster Layer; Image Service; String; Raster Dataset; Mosaic Dataset
out_raster

The output binary raster dataset. Supported formats are TIFF, CRF, and PNG.

Raster Dataset
background_value
(Optional)

The background value for the output raster. The default value is 0.

Double
flood_fill
(Optional)

Specifies how background pixel values will be determined.

  • FLOOD_FILLBackground pixel values will be determined by the flood fill operation, which fills the connected pixels from the image boundary to the mask boundary. Pixels inside the mask will not be converted to background regardless of their value.
  • NO_FLOOD_FILLBackground pixel values will be determined by the specified background value. This is the default.
Boolean
expand_background
(Optional)

The number of pixels that will be used to expand or shrink the background. Negative values will shrink the background.

Long
expand_mask
(Optional)

The number of pixels that will be used to expand or shrink the mask. Negative values will shrink the mask.

Long
min_region_size
(Optional)

The number of connected pixels that will be used to define a mask region. Mask regions that are smaller than this size will be classified as background.

Long
background_nodata
(Optional)

Specifies whether the background value will be set to NoData.

  • BACKGROUND_NODATAThe background value will be set to NoData.
  • BACKGROUND_DATAThe background value will not be set to NoData. This is the default.
Boolean

Code sample

CreateBinaryMask (Python window)

This example creates a binary raster in which all pixels within the mask boundary are filled.

#Import system modules and check out extension
import arcpy 
from arcpy.ia import *
arcpy.CheckOutExtension("ImageAnalyst") 

#Execute
output = arcpy.ia.CreateBinaryMask(r'C:\data\in_raster.crf”, 0, True, 0, 0, 100, 'BACKGROUND_DATA'') 

#Save output
output.save('c:\data\out_mask.tif')
CreateBinaryMask (stand-alone script)

This example creates a binary raster in which all pixels within the mask boundary are filled.

# Import system modules and check out ArcGIS Image Analyst extension license
import arcpy 
from arcpy.ia import *
arcpy.CheckOutExtension("ImageAnalyst") 

#Set local variables
in_raster = r'C:\data\input_raster.crf'         
background_value=0        
flood_fill=True     
expand_background=0        
expand_mask=0     
min_region_size=100       
background_nodata=False     
   
#Execute
out_raster = arcpy.ia.CreateBinaryMask(in_raster, background_value, flood_fill, 
				expand_background, expand_mask, min_region_size, 
				background_nodata)

#Save the output
out_raster.save(r'C:\Data\FloodMap\WaterMask.crf')

Related topics