This task performs a type of image change detection known as spectral angle difference. It determines the spectral similarity between the Time 1 image spectra and the Time 2 image spectra for every pixel. Each pixel spectrum is represented by a vector in space whose dimensionality is equal to the number of bands. The task calculates the angle between the two vectors. The smaller the angle, the more similar the two spectra.

Before running this task, ensure that the two input images have the same number of bands and the same spatial dimensions. Use the BANDS property to the SubsetRaster task to define spectral subsets, if needed. Also use the ImageIntersection task to ensure that the two images have the same dimensions, projection, and pixel size.

Example


This example performs a SAM image difference change detection on two co-registered Sentinel-2 multispectral images. The images are before and after a flood event along the Mala River in Peru in 2017. They have the same number of bands, columns, and rows; no preprocessing is necessary.

The source files are available from our ENVI Tutorials web page. Click the Change Detection link to download the .zip file to your machine, then unzip the files. Update the file references in the example with the correct locations.

; Start the application
e = ENVI()
 
; Open input files
File1 = 'MalaRiver_2017-02-20.dat'
Raster1 = e.OpenRaster(File1)
 
File2 = 'MalaRiver_2017-03-12.dat'
Raster2 = e.OpenRaster(File2)
 
; Get the task from the catalog of ENVITasks
Task = ENVITask('SAMImageDifference')
 
; Define task inputs
Task.INPUT_RASTER1 = Raster1
Task.INPUT_RASTER2 = Raster2
 
; Run the task
Task.Execute
 
; Get the collection of data objects currently 
; available in the Data Manager
DataColl = e.Data
 
; Add the output to the data manager
DataColl.Add, Task.OUTPUT_RASTER
 
; Display the result
View = e.GetView()
Layer = View.CreateLayer(Task.OUTPUT_RASTER)

See More Examples below.

Syntax


Result = ENVITask('SAMImageDifference')

Input properties (Set, Get): INPUT_RASTER1, INPUT_RASTER2, OUTPUT_RASTER_URI

Output properties (Get only): OUTPUT_RASTER

Properties marked as "Set" are those that you can set to specific values. You can also retrieve their current values any time. Properties marked as "Get" are those whose values you can retrieve but not set.

Methods


This task inherits the following methods from ENVITask:

AddParameter

Execute

Parameter

ParameterNames

RemoveParameter

Properties


This task inherits the following properties from ENVITask:

COMMUTE_ON_DOWNSAMPLE

COMMUTE_ON_SUBSET

DESCRIPTION

DISPLAY_NAME

NAME

REVISION

TAGS

This task also contains the following properties:

INPUT_RASTER1 (required)

Specify a multiband raster representing the earliest time.

INPUT_RASTER2 (required)

Specify a multiband raster representing the latest time.

OUTPUT_RASTER

This is a reference to the output raster of filetype ENVI.

OUTPUT_RASTER_URI (optional)

Specify a string with the fully qualified filename and path of the associated OUTPUT_RASTER. If you do not specify this property, the associated OUTPUT_RASTER will not be created. To force the creation of a temporary file set the property to an exclamation symbol (!).

More Examples


This example performs a SAM image difference change detection between a Landsat TM image from 1985 and a Landsat 8 image from 2020. It shows the effects of urban sprawl in Las Vegas, Nevada over a 35-year period. Because the number of bands is different between the two images, the example uses the SubsetRaster task to create a spectral subset of the Landsat 8 image. The example also uses the ImageIntersection task to ensure that the two images cover the same geographic extent and that they have the same spatial dimensions.

The source files are available from our ENVI Tutorials web page. Click the Landsat Case Studies link to download the .zip file to your machine, then unzip the files. Update the file references in the example with the correct locations.

; Start the application
e = ENVI()
 
; Open a Landsat TM image
File1 = 'LasVegasMay1985.dat'
Raster1 = e.OpenRaster(File1)
 
; Open a Landsat 8 image
File2 = 'LasVegasMay2020.dat'
Raster2 = e.OpenRaster(File2)
 
; Create a spectral subset of the Landsat 8 image that
; omits the coastal aerosol band, so that the bands match
; those of the Landsat TM image (Raster1)
Time2SubsetTask = ENVITask('SubsetRaster')
Time2SubsetTask.INPUT_RASTER = Raster2
Time2SubsetTask.BANDS = [1,2,3,4,5,6]
Time2SubsetTask.Execute
 
; Run the image intersection task so that the spatial dimensions
; are the same between the two rasters
ImageIntersectionTask = ENVITask('ImageIntersection')
ImageIntersectionTask.INPUT_RASTER1 = Raster1
ImageIntersectionTask.INPUT_RASTER2 = Time2SubsetTask.OUTPUT_RASTER
ImageIntersectionTask.Execute
 
; Run the SAM image difference task
Task = ENVITask('SAMImageDifference')
Task.INPUT_RASTER1 = ImageIntersectionTask.OUTPUT_RASTER1
Task.INPUT_RASTER2 = ImageIntersectionTask.OUTPUT_RASTER2
Task.OUTPUT_RASTER_URI = e.GetTemporaryFilename()
Task.Execute
 
; Get the collection of data objects currently
; available in the Data Manager
DataColl = e.Data
 
; Add the output to the data manager
DataColl.Add, Task.OUTPUT_RASTER
 
; Display the result
View = e.GetView()
Layer = View.CreateLayer(Task.OUTPUT_RASTER)
View.Zoom, 0.4

Version History


ENVI 5.5

Introduced

API Version


4.2

See Also


ENVITask, ImageBandDifference Task, SubsetRaster Task, ImageIntersection Task