Segment Mean Shift (Image Analyst)

Available with Image Analyst license.

Available with Spatial Analyst license.

Summary

Groups adjacent pixels that have similar spectral characteristics into segments.

Usage

  • The input can be any Esri-supported raster, with any valid bit depth.

  • The Band Index parameter is a list of three bands, separated by a space delimiter.

  • To achieve optimal results, use the Symbology tab in the dataset properties to interactively stretch your Input Raster so the features you want to classify are apparent. Then use these optimal settings in the Stretch raster function to enhance your imagery for optimum results, and specify the Output Pixel Type as 8 bit unsigned from the General tab.

    The output layer from the previously executed Stretch raster function can be the Input Raster for the Segment Mean Shift tool.

Parameters

LabelExplanationData Type
Input Raster

The raster dataset to segment. This can be a multispectral or grayscale image.

Mosaic Layer; Raster Layer
Spectral Detail
(Optional)

The level of importance given to the spectral differences of features in the imagery.

Valid values range from 1.0 to 20.0. A higher value is appropriate when there are features to classify separately that have similar spectral characteristics. Smaller values create spectrally smoother outputs. For example, with higher spectral detail in a forested scene, there will be greater discrimination between the tree species.

Double
Spatial Detail
(Optional)

The level of importance given to the proximity between features in the imagery.

Valid values range from 1.0 to 20. A higher value is appropriate for a scene in which the features of interest are small and clustered together. Smaller values create spatially smoother outputs. For example, in an urban scene, impervious surfaces can be classified using a smaller spatial detail, or buildings and roads can be classified as separate classes using a higher spatial detail.

Long
Minimum Segment Size In Pixels
(Optional)

The minimum size of a segment. Merge segments smaller than this size with their best fitting neighbor segment. This is related to the minimum mapping unit for your project.

Units are in pixels.

Long
Band Indexes
(Optional)

The bands that will be used to segment the imagery, separated by a space. If no band indexes are specified, they are determined by the following criteria:

  • If the raster has only 3 bands, those 3 bands are used
  • If the raster has more than 3 bands, the tool assigns the red, green, and blue bands according to the raster's properties.
  • If the red, green, and blue bands are not identified in the raster dataset's properties, bands 1, 2, and 3 are used.

The band order will not change the result.

Select bands that offer the most differentiation between the features of interest.

String
Maximum Segment Size In Pixels
(Optional)

The maximum size of a segment. Segments that are larger than the specified size will be divided. Use this parameter to prevent artifacts in the output raster resulting from large segments.

Units are in pixels.

The default value is -1, meaning there is no limit on the segment size.

Long

Return Value

LabelExplanationData Type
Output Raster Dataset

Specify a name and extension for the output dataset.

If the input was a multispectral image, the output will be an 8-bit RGB image. If the input was a grayscale image, the output will be an 8-bit grayscale image.

Raster

SegmentMeanShift(in_raster, {spectral_detail}, {spatial_detail}, {min_segment_size}, {band_indexes}, {max_segment_size})
NameExplanationData Type
in_raster

The raster dataset to segment. This can be a multispectral or grayscale image.

Mosaic Layer; Raster Layer
spectral_detail
(Optional)

The level of importance given to the spectral differences of features in the imagery.

Valid values range from 1.0 to 20.0. A higher value is appropriate when there are features to classify separately that have similar spectral characteristics. Smaller values create spectrally smoother outputs. For example, with higher spectral detail in a forested scene, there will be greater discrimination between the tree species.

Double
spatial_detail
(Optional)

The level of importance given to the proximity between features in the imagery.

Valid values range from 1.0 to 20. A higher value is appropriate for a scene in which the features of interest are small and clustered together. Smaller values create spatially smoother outputs. For example, in an urban scene, impervious surfaces can be classified using a smaller spatial detail, or buildings and roads can be classified as separate classes using a higher spatial detail.

Long
min_segment_size
(Optional)

The minimum size of a segment. Merge segments smaller than this size with their best fitting neighbor segment. This is related to the minimum mapping unit for your project.

Units are in pixels.

Long
band_indexes
(Optional)

The bands that will be used to segment the imagery, separated by a space. If no band indexes are specified, they are determined by the following criteria:

  • If the raster has only 3 bands, those 3 bands are used
  • If the raster has more than 3 bands, the tool assigns the red, green, and blue bands according to the raster's properties.
  • If the red, green, and blue bands are not identified in the raster dataset's properties, bands 1, 2, and 3 are used.

The band order will not change the result.

Select bands that offer the most differentiation between the features of interest.

String
max_segment_size
(Optional)

The maximum size of a segment. Segments that are larger than the specified size will be divided. Use this parameter to prevent artifacts in the output raster resulting from large segments.

Units are in pixels.

The default value is -1, meaning there is no limit on the segment size.

Long

Return Value

NameExplanationData Type
out_raster_dataset

Specify a name and extension for the output dataset.

If the input was a multispectral image, the output will be an 8-bit RGB image. If the input was a grayscale image, the output will be an 8-bit grayscale image.

Raster

Code sample

SegmentMeanShift example 1 (Python window)

This example creates an output with a minimum segment size of 20, using the near-infrared, red, and green inputs.

import arcpy
from arcpy.ia import *

# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")

seg_raster = SegmentMeanShift("c:/test/moncton.tif", "15", "10", 
                              "20", "4 3 2")

seg_raster.save("c:/test/moncton_seg.tif")
SegmentMeanShift example 2 (stand-alone script)

This example performs a SegmentMeanShift to create an output with a minimum segment size of 20, using the near-infrared, red, and green inputs.

# Import system modules
import arcpy
from arcpy.ia import *

"""
Usage: SegmentMeanShift(in_raster, {spectral_detail}, {spatial_detail}, 
                    {min_segment_size}, {band_indexes})
"""

# Set local variables
inRaster = "c:/test/moncton.tif"
spectral_detail = "14.5"
spatial_detail = "10"
min_segment_size = "20"
band_indexes = "4 3 2"

# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")

# Execute 
seg_raster = SegmentMeanShift(inRaster, spectral_detail, spatial_detail, 
                              min_segment_size, min_segment_size)

# Save the output 
seg_raster.save("c:/output/moncton_seg.tif")

Licensing information

  • Basic: Requires Image Analyst or Spatial Analyst
  • Standard: Requires Image Analyst or Spatial Analyst
  • Advanced: Requires Image Analyst or Spatial Analyst

Related topics