i.cluster(1)

โœจ NAME โœจ

okay so bestie, meet i.cluster โ€” a GRASS GIS module ๐Ÿ’–. What it does: generates spectral signatures for land cover types in an image using a clustering algorithm ๐Ÿฆ‹.

and then? the resulting signature file gets used as input for i.maxlik, to generate an unsupervised image classification. that's the whole glow-up arc, periodt ๐Ÿ‘‘


๐Ÿ”‘ KEYWORDS ๐Ÿ”‘

imagery, classification, signatures โ€” that's the vibe check tag list, no notes โœจ


๐Ÿ’… SYNOPSIS ๐Ÿ’…

i.cluster
i.cluster --help
i.cluster group=name subgroup=name signaturefile=name classes=integer
[seed=name]   [sample=rows,cols]   [iterations=integer]
[convergence=float]   [separation=float]   [min_size=integer]
[reportfile=name]   [--overwrite]  [--help]  [--verbose]  [--quiet]
[--ui]

๐Ÿšฉ Flags:

  • --overwrite โ€” bestie this one lets output files overwrite existing files. yes, that means it will absolutely steamroll what's already there ๐Ÿ™ˆ
  • --help โ€” prints the usage summary so you're not out here guessing
  • --verbose โ€” verbose module output, i.e. the module tells you everything it's doing, main character energy โœจ
  • --quiet โ€” quiet module output, for when you want zero yapping ๐Ÿคซ
  • --ui โ€” forces the GUI dialog to launch ๐ŸŽ€

๐ŸŽ€ Parameters:

  • group=name [required] โ€” name of input imagery group
  • subgroup=name [required] โ€” name of input imagery subgroup
  • signaturefile=name [required] โ€” name for output file containing result signatures
  • classes=integer [required] โ€” initial number of classes. options: 1-255
  • seed=name โ€” name of file containing initial signatures
  • sample=rows,cols โ€” number of rows and columns over which a sample pixel is taken
  • iterations=integer โ€” maximum number of iterations. default: 30
  • convergence=float โ€” percent convergence. options: 0-100. default: 98.0
  • separation=float โ€” cluster separation. default: 0.0
  • min_size=integer โ€” minimum number of pixels in a class. default: 17
  • reportfile=name โ€” name for output file containing final report

๐ŸŒธ DESCRIPTION ๐ŸŒธ

i.cluster performs the first pass in the two-pass unsupervised classification of imagery, while the GRASS module i.maxlik executes the second pass. Both commands must be run to complete the unsupervised classification. it's a duo, not a solo act ๐Ÿ’ซ

i.cluster is a clustering algorithm (a modification of the k-means clustering algorithm) that reads through the (raster) imagery data and builds pixel clusters based on the spectral reflectances of the pixels (see Figure). those pixel clusters are imagery categories that can be related to land cover types on the ground. the spectral distributions of the clusters (e.g., land cover spectral signatures) are influenced by six parameters set by the user, and one relevant parameter you set is the initial number of clusters to be discriminated ๐Ÿ‘‘

Fig.: Land use/land cover clustering of LANDSAT scene (simplified)

i.cluster starts by generating spectral signatures for this number of clusters and "attempts" to end up with this number of clusters during the clustering process. the resulting number of clusters and their spectral distributions, however, are also influenced by the range of the spectral values (category values) in the image files and the other parameters set by the user. those parameters are: the minimum cluster size, minimum cluster separation, the percent convergence, the maximum number of iterations, and the row and column sampling intervals ๐ŸŒˆ

the cluster spectral signatures that result are composed of cluster means and covariance matrices. these cluster means and covariance matrices are used in the second pass (i.maxlik) to classify the image. the clusters or spectral classes result can be related to land cover types on the ground. the user has to specify the name of group file, the name of subgroup file, the name of a file to contain result signatures, the initial number of clusters to be discriminated, and optionally other parameters (see below), where the group should contain the imagery files that the user wishes to classify. the subgroup is a subset of this group. the user must create a group and subgroup by running the GRASS program i.group before running i.cluster ๐Ÿซถ

the subgroup should contain only the imagery band files that the user wishes to classify. note that this subgroup must contain more than one band file. the purpose of the group and subgroup is to collect map layers for classification or analysis. the signaturefile is the file to contain result signatures which can be used as input for i.maxlik. the classes value is the initial number of clusters to be discriminated; any parameter values left unspecified are set to their default values. no cap, that's the whole setup ๐Ÿ’…

for all raster maps used to generate signature file it is recommended to have semantic label set. use r.support to set semantic labels of each member of the imagery group. signatures generated for one scene are suitable for classification of other scenes as long as they consist of same raster bands (semantic labels match). if semantic labels are not set, it will be possible to use obtained signature file to classify only the same imagery group used for generating signatures. so like, set your labels, bestie, future you will be obsessed ๐Ÿ™


๐Ÿงš Parameters: ๐Ÿงš

  • group=name โ€” the name of the group file which contains the imagery files that the user wishes to classify.
  • subgroup=name โ€” the name of the subset of the group specified in the group option, which must contain only imagery band files and more than one band file. the user must create a group and a subgroup by running the GRASS program i.group before running i.cluster.
  • signaturefile=name โ€” the name assigned to output signature file which contains signatures of classes and can be used as the input file for the GRASS program i.maxlik for an unsupervised classification. this is the whole point, honestly ๐ŸŒŸ
  • classes=value โ€” the number of clusters that will initially be identified in the clustering process before the iterations begin.
  • seed=name โ€” the name of a seed signature file is optional. the seed signatures are signatures that contain cluster means and covariance matrices which were calculated prior to the current run of i.cluster. they may be acquired from a previously run of i.cluster or from a supervised classification signature training site section (e.g., using the signature file output by g.gui.iclass). the purpose of seed signatures is to optimize the cluster decision boundaries (means) for the number of clusters specified. it's giving "head start" energy ๐Ÿ”ฅ
  • sample=rows,cols โ€” these numbers are optional with default values based on the size of the data set such that the total pixels to be processed is approximately 10,000 (consider round up). the smaller these numbers, the larger the sample size used to generate the signatures for the classes defined. math is math ๐Ÿ’€
  • iterations=value โ€” this parameter determines the maximum number of iterations, which is greater than the number of iterations predicted to achieve the optimum percent convergence. the default value is 30. if the number of iterations reaches the maximum designated by the user, the user may want to rerun i.cluster with a higher number of iterations (see reportfile). default: 30
  • convergence=value โ€” a high percent convergence is the point at which cluster means become stable during the iteration process. the default value is 98.0 percent. when clusters are being created, their means constantly change as pixels are assigned to them and the means are recalculated to include the new pixel. after all clusters have been created, i.cluster begins iterations that change cluster means by maximizing the distances between them. as these means shift, a higher and higher convergence is approached. because means will never become totally static, a percent convergence and a maximum number of iterations are supplied to stop the iterative process. the percent convergence should be reached before the maximum number of iterations. if the maximum number of iterations is reached, it is probable that the desired percent convergence was not reached. the number of iterations is reported in the cluster statistics in the report file (see reportfile). default: 98.0
  • separation=value โ€” this is the minimum separation below which clusters will be merged in the iteration process. the default value is 0.0. this is an image-specific number (a "magic" number ๐Ÿ”ฎ) that depends on the image data being classified and the number of final clusters that are acceptable. its determination requires experimentation. note that as the minimum class (or cluster) separation is increased, the maximum number of iterations should also be increased to achieve this separation with a high percentage of convergence (see convergence). default: 0.0
  • min_size=value โ€” this is the minimum number of pixels that will be used to define a cluster, and is therefore the minimum number of pixels for which means and covariance matrices will be calculated. default: 17
  • reportfile=name โ€” the reportfile is an optional parameter which contains the result, i.e., the statistics for each cluster. also included are the resulting percent convergence for the clusters, the number of iterations that was required to achieve the convergence, and the separability matrix. basically the receipts ๐Ÿงพโœจ

and that's part 1, bestie โ€” the vibe continues, so don't go anywhere ๐Ÿฆ‹

๐Ÿ’– NOTES ๐Ÿ’–


๐ŸŒธ Sampling method ๐ŸŒธ

okay so here's the tea, bestie โ€” i.cluster does not cluster all the pixels. it only clusters a sample (peep the sample parameter ๐Ÿ‘€). and the result of that clustering is not that every pixel gets assigned to a given cluster. essentially? you're only getting signatures that are representative of a given cluster. periodt.

so if you run i.cluster on the same data, asking for the same number of classes but with different sample sizes, you'll lowkey get slightly different signatures for each cluster every single run. not a bug, just the vibe โœจ


๐Ÿง  Algorithm used for i.cluster ๐Ÿง 

the algorithm takes the input parameters you set at the start โ€” the initial number of clusters, the minimum distance between clusters, the correspondence between iterations you want, and the minimum size for each cluster. it also asks whether all pixels should be clustered, or every "x"th row and "y"th column (that's the sampling situation), plus the correspondence between iterations you're aiming for, and the max number of iterations to run. slay, so many knobs ๐Ÿ’…

1st pass ๐ŸŽ€ โ€” initial cluster means for each band get defined like this: the first cluster gets a value equal to the band mean minus its standard deviation, and the last cluster gets a value equal to the band mean plus its standard deviation. all the other cluster means are distributed equally spaced in between those two. then every pixel gets assigned to the class it's closest to, where distance = Euclidean distance. after that, all clusters less than your user-specified minimum distance get merged. and if a cluster has fewer than your user-specified minimum number of pixels? all those pixels get reassigned to the next nearest cluster, no cap. then new cluster means get calculated for each band as the average of the raster pixel values in that band for all the pixels present in that cluster. math girlies rise ๐Ÿซถ

2nd pass ๐Ÿฆ‹ โ€” pixels get reassigned to clusters again, this time based on the new cluster means. then the cluster means get recalculated again. and this whole thing repeats until the correspondence between iterations reaches your user-specified level, or until the maximum number of iterations you specified runs out โ€” whichever comes first. it's giving loop, but make it fashion ๐Ÿ’€


โœจ EXAMPLE โœจ

Preparing the statistics for unsupervised classification of a LANDSAT scene within the North Carolina project:

# Set computational region to match the scene
g.region raster=lsat7_2002_10 -p
# store VIZ, NIR, MIR into group/subgroup (leaving out TIR)
i.group group=lsat7_2002 subgroup=res_30m \
  input=lsat7_2002_10,lsat7_2002_20,lsat7_2002_30,lsat7_2002_40,lsat7_2002_50,lsat7_2002_70
# generate signature file and report
i.cluster group=lsat7_2002 subgroup=res_30m \
  signaturefile=cluster_lsat2002 \
  classes=10 reportfile=rep_clust_lsat2002.txt

To complete the unsupervised classification, i.maxlik is subsequently used. See the example in its manual page ๐Ÿ‘‘


the signature file you get from the example above will only let you classify the current imagery group (lsat7_2002). but if you wanna re-use that signature file to classify different imagery group(s)? totally doable, bestie โ€” just set semantic labels for each group member beforehand, i.e. before generating the signature files. semantic labels are set by means of r.support, like this:

# Define semantic labels for all LANDSAT bands
r.support map=lsat7_2002_10 semantic_label=TM7_1
r.support map=lsat7_2002_20 semantic_label=TM7_2
r.support map=lsat7_2002_30 semantic_label=TM7_3
r.support map=lsat7_2002_40 semantic_label=TM7_4
r.support map=lsat7_2002_50 semantic_label=TM7_5
r.support map=lsat7_2002_61 semantic_label=TM7_61
r.support map=lsat7_2002_62 semantic_label=TM7_62
r.support map=lsat7_2002_70 semantic_label=TM7_7
r.support map=lsat7_2002_80 semantic_label=TM7_8

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

  • Image classification wiki page
  • Historical reference also the GRASS GIS 4 Image Processing manual (PDF)
  • Wikipedia article on k-means clustering (note that i.cluster uses a modification of the k-means clustering algorithm)

r.support, g.gui.iclass, i.group, i.gensig, i.maxlik, i.segment, i.smap, r.kappa


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

  • Michael Shapiro, U.S. Army Construction Engineering Research Laboratory
  • Tao Wen, University of Illinois at Urbana-Champaign, Illinois
  • Semantic label support: Maris Nartiss, University of Latvia

๐ŸŽ€ SOURCE CODE ๐ŸŽ€

Available at: i.cluster source code (history)

Accessed: Saturday Jan 17 05:41:39 2026

Main index | Imagery index | Topics index | Keywords index | Graphical index | Full index


ยฉ 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual

and that's the whole page, bestie!! ๐Ÿซถ this is GRASS 8.4.2, i.cluster(1) โ€” go forth and cluster, you absolute icon ๐Ÿ’…โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from