This is a Model which takes an n band image, performs image segmentation on it and then applies unsupervised classification to the segments to cluster them into spectrally similar classes.
|Landsat image:||Clustered Segments:|
The way this model works uses two Operators which are a little different from the majority of the raster operators provided in Spatial Modeler. Consequently additional, and perhaps non-intuitive, steps need to be taken to include them in a working Model. Effectively, both Image Segmentation FLS and Unsupervised Classification are Command Line operators (and you would probably encounter similar requirements when using the Command Line and Python Script operators). As such they do not take in and produce the normal raster stream of pixel blocks which is Spatial Modelers normal currency for passing around pixel information. Instead these operators take in a disk file and produce a disk file. Consequently, if there is more of the model downstream of these operators there will need to be one or more temporary files created on disk while the Model executes (which also means that such models tend to be slower to complete than Models which user raster stream operators).
The Port Input operator named "Input MS Image" enables the user to select a multispectral input image file. That filename is passed directly as an input to Image Segmentation FLS. The filename is also passed to a Raster Input operator, but that operator creates a raster stream and a raster steam is not a valid input to Image Segmentation FLS. If you look at the Properties for the Image Segmentation FLS operator (or the Help), you will see that the InputFile port is defined as requiring a data type of IMAGINE.File, not IMAGINE.Raster. The same is true for naming the output image.
|Properties for Image Segmentation FLS, showing the Supported Object types|
Since we only need the output of Image Segmentation FLS as an input to the rest of the model, we don't need to keep the output file permanently. So the Create Temp Filename operator is used on the OutputImgFileIn port to create a disk file to temporarily store the results of Image Segmentation FLS. This temporary file will be deleted when the Model is destroyed (I.,e. when the Spatial Model Editor is closed, or the Model is removed from the Editor, or the model finishes running in background).
That temporary image segmentation file is then fed as an input into the Zonal Mean Iterator.
|Zonal Mean Iterator sub-model|
Within the Iterator the image segmentation (Zone File) file is a file, so it has to be fed into a Raster Input which turns the data into a raster stream. The stream of segments is then used as the Zones for a Zonal Mean operation. This Zonal Mean is iterated through each band of the original input image (coming into the Iterator via the Class Raster port. So each Zone ends up with n (however many bands there were originally) values representing the mean of the pixels which fall within that zone, per band.
Each iteration is fed out to a Stack Layers operator which assembles each Zonal Mean layer into an n band raster stream.
Finally we want to feed that information into the Unsupervised Classification operator so the Isodata algorithm can assign the Zones to spectrally similar classes. However the output from Stack Layers is a raster stream (IMAGINE.Raster), whereas the Unsupervised Classification operator, like Image Segmentation FLS, expects IMAGINE.File (an on-disk image file).
So first the Stack Layers has to be fed to a Raster Output (with an another attached Create Temp File name for the file that will be produced). The filename produced by the Raster Output then provides the input (temporary) filename fed to the Unsupervised Classification operator. It is also fed the name of the output classified file to produce. There is no need for another Raster Output operator because Unsupervised Classification already produces an output file (IMAGINE.File).
This model is intended to act as an example of how to deal with Command Line operators, and the handful of other operators which act in a similar filename in / filename out manner. If you want to actually make use of the model to classify imagery you'll want to make sure you investigate all the options available on the Image Segmentation FLS and Unsupervised Classification operators and set values appropriate to the task at hand. You might even want to add Port Inputs to expose them as user-configurable parameters to users wishing to run the model outside of the Spatial Model Editor.
Input MS Image: Raster input filename of the multispectral image to be segmented and clustered.
Class Filename Out: Name of output grouped segments thematic image.