Showing results for 
Search instead for 
Do you mean 

Clustered Segments

by Technical Evangelist on ‎12-15-2016 01:12 PM - edited on ‎02-21-2020 08:59 AM by Community Manager (2,962 Views)


Download model




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:
Landsat5.png Clustered_Segments.png


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 parameters:


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.






on ‎12-05-2017 07:07 AM

I keep getting the error message:


" There is a problem on line 1 in file "c:/program
files/hexagon/erdas imagine
2016/etc/models/clustered_segments_v16_1_3.gmdx" at or
near "Unexpected End"



And ideas why?

by Technical Evangelist
‎12-05-2017 09:33 AM - edited ‎12-05-2017 12:45 PM

Hi William,


My guess would be that you are using a version of ERDAS IMAGINE prior to ERDAS IMAGINE 2016 v16.1?


If not, what is it that you are doing when you receive this message and what is the exact content of the Session Log that is produced?