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 parameter 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 Sentinel link to download the .zip file to your machine, then unzip the files. The files you will use in this example are located in the S2A_MalaRiver folder of the download. Update the file references in the example with the correct locations.
e = ENVI()
File1 = 'MalaRiver_2017-02-20.dat'
Raster1 = e.OpenRaster(File1)
File2 = 'MalaRiver_2017-03-12.dat'
Raster2 = e.OpenRaster(File2)
Task = ENVITask('SAMImageDifference')
Task.INPUT_RASTER1 = Raster1
Task.INPUT_RASTER2 = Raster2
Task.Execute
DataColl = e.Data
DataColl.Add, Task.OUTPUT_RASTER
View = e.GetView()
Layer = View.CreateLayer(Task.OUTPUT_RASTER)
See More Examples below.
Syntax
Result = ENVITask('SAMImageDifference')
Input parameters (Set, Get): INPUT_RASTER1, INPUT_RASTER2, OUTPUT_RASTER_URI
Output parameters (Get only): OUTPUT_RASTER
Parameters marked as "Set" are those that you can set to specific values. You can also retrieve their current values any time. Parameters marked as "Get" are those whose values you can retrieve but not set.
Input Parameters
INPUT_RASTER1 (required)
Specify a multiband raster representing the earliest time.
INPUT_RASTER2 (required)
Specify a multiband raster representing the latest time.
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 parameter, the associated OUTPUT raster will not be created.
- If you do not specify this parameter, or set it to an exclamation symbol (!), ENVI creates a temporary file.
- If you set it to the hash symbol (#), ENVI creates a file in the temporary directory, but this file will not be deleted when ENVI closes.
Output Parameters
OUTPUT_RASTER
This is a reference to the output raster of filetype ENVI.
Methods
Execute
Parameter
ParameterNames
Properties
DESCRIPTION
DISPLAY_NAME
NAME
REVISION
TAGS
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. The files you will use in this example are located in the TimeSeries folder of the download. Update the file references in the example with the correct locations.
e = ENVI()
File1 = 'LasVegasMay1985.dat'
Raster1 = e.OpenRaster(File1)
File2 = 'LasVegasMay2020.dat'
Raster2 = e.OpenRaster(File2)
Time2SubsetTask = ENVITask('SubsetRaster')
Time2SubsetTask.INPUT_RASTER = Raster2
Time2SubsetTask.BANDS = [1,2,3,4,5,6]
Time2SubsetTask.Execute
ImageIntersectionTask = ENVITask('ImageIntersection')
ImageIntersectionTask.INPUT_RASTER1 = Raster1
ImageIntersectionTask.INPUT_RASTER2 = Time2SubsetTask.OUTPUT_RASTER
ImageIntersectionTask.Execute
Task = ENVITask('SAMImageDifference')
Task.INPUT_RASTER1 = ImageIntersectionTask.OUTPUT_RASTER1
Task.INPUT_RASTER2 = ImageIntersectionTask.OUTPUT_RASTER2
Task.OUTPUT_RASTER_URI = e.GetTemporaryFilename()
Task.Execute
DataColl = e.Data
DataColl.Add, Task.OUTPUT_RASTER
View = e.GetView()
Layer = View.CreateLayer(Task.OUTPUT_RASTER)
View.Zoom, 0.4
Version History
See Also
ENVITask, ImageBandDifference Task, SubsetRaster Task, ImageIntersection Task, Masking Support in ENVITasks