MeanShiftSmoothing - MeanShift Smoothing

This application smooths an image using the MeanShift algorithm.

Detailed description

MeanShift [1,2,3] is an iterative edge-preserving image smoothing algorithm often used in image processing and as a first step for image segmentation. The MeanShift algorithm can be applied to multispectral images.

At first iteration, for any given pixel of the input image, the filtered value correspond to the average spectral signature of neighborhood pixels that are both spatially closer than the spatial radius parameter (spatialr) and with spectral signature that have an euclidean distance to the input pixel lower than the range radius (ranger), that is, pixels that are both close in space and in spectral signatures. Subsequent iterations will repeat this process by considering that the pixel signature corresponds to the average spectral signature computed during previous iteration, and that the pixel position corresponds to the average position of pixels used to compute the average signature.The algorithm stops when the maximum number of iterations (maxiter) is reached, or when the position and spectral signature does not change much between iterations, according to the convergence threshold (thres). If the modesearch option is used then convergence will also stops if the spatial position reaches a pixel that has already converged. This will speed-up convergence, at the expense of stability of the result.

The application outputs the image of the final averaged spectral signatures (fout), and can also optionally output the 2D displacement field between input pixel position and final pixel position after convergence (foutpos).

Note that computing an euclidean distance between spectral signatures may be inaccurate and that techniques such as color space transform or image normalisation could be applied before using this application. Also note that most satellite images noise model is not gaussian, since noise variance linearly depends on radiance (the higher the radiance, the higher the noise variance). To account for such noise model, the application provides the range radius ramp option (rangeramp), which will vary the range radius linearly with the central pixel intensity. Default value is 1. (no ramp).

This application is the first step of the large scale MeanShift method depicted in [4]. Both outputs (fout and foutpos) can be passed to the large scale MeanShift segmentation application [5]. If the application is used for large scale MeanShift, modesearch option should be off.

Parameters

This section describes in details the parameters available for this application. Table [1] presents a summary of these parameters and the parameters keys to be used in command-line and programming languages. Application key is MeanShiftSmoothing .

[1]Table: Parameters table for MeanShift Smoothing.
Parameter Key Parameter Name Parameter Type
in Input Image Input image
fout Spectral filtered output Output image
foutpos Spatial filtered displacement output Output image
ram Available RAM (Mb) Int
spatialr Spatial radius Int
ranger Range radius Float
thres Mode convergence threshold Float
maxiter Maximum number of iterations Int
rangeramp Range radius ramp coefficient Float
modesearch Mode search. Boolean
inxml Load otb application from xml file XML input parameters file
outxml Save otb application to xml file XML output parameters file
  • Input Image: The input image can be any single or multiband image. Beware of pontential imbalance between bands ranges as it may alter euclidean distance.
  • Spectral filtered output: This output image contains the final average spectral signatures of each pixel. The output type should be at least as wide as the input image type. Floating point encoding is advised. This output can be used as input image (in) of the LSMSSegmentation application [4,5].
  • Spatial filtered displacement output: This output image contains the 2D displacement between the input pixel spatial position and the final position after convergence. Floating point encoding is mandatory. This output can be used as input image (in) of the LSMSSegmentation application [4,5].
  • Available RAM (Mb): Available memory for processing (in MB).
  • Spatial radius: Radius of the spatial neighborhood for averaging. Higher values will result in more smoothing and higher processing time.
  • Range radius: Threshold on spectral signature euclidean distance (expressed in radiometry unit) to consider neighborhood pixel for averaging. Higher values will be less edge-preserving (more similar to simple average in neighborhood), whereas lower values will result in less noise smoothing. Note that this parameter has no effect on processing time.
  • Mode convergence threshold: Algorithm will stop if update of average spectral signature and spatial position is below this threshold.
  • Maximum number of iterations: Algorithm will stop if convergence threshold is not met after the maximum number of iterations.
  • Range radius ramp coefficient: Vary the range radius linearly with the central pixel intensity (experimental).
  • Mode search.: If activated pixel iterative convergence is stopped if the path crosses an already converged pixel. Be careful, with this option, the result will slightly depend on thread number and the results will not be stable (see [4] for more details).
  • Load otb application from xml file: Load otb application from xml file.
  • Save otb application to xml file: Save otb application to xml file.

Example

To run this example in command-line, use the following:

otbcli_MeanShiftSmoothing -in maur_rgb.png -fout smooth.tif -foutpos position.tif -spatialr 16 -ranger 16 -thres 0.1 -maxiter 100

To run this example from Python, use the following code snippet:

#!/usr/bin/python

# Import the otb applications package
import otbApplication

# The following line creates an instance of the MeanShiftSmoothing application
MeanShiftSmoothing = otbApplication.Registry.CreateApplication("MeanShiftSmoothing")

# The following lines set all the application parameters:
MeanShiftSmoothing.SetParameterString("in", "maur_rgb.png")

MeanShiftSmoothing.SetParameterString("fout", "smooth.tif")

MeanShiftSmoothing.SetParameterString("foutpos", "position.tif")

MeanShiftSmoothing.SetParameterInt("spatialr", 16)

MeanShiftSmoothing.SetParameterFloat("ranger", 16)

MeanShiftSmoothing.SetParameterFloat("thres", 0.1)

MeanShiftSmoothing.SetParameterInt("maxiter", 100)

# The following line execute the application
MeanShiftSmoothing.ExecuteAndWriteOutput()

Limitations

When modesearch is on, the application will yield slightly different results between executions, due to multi-threading. Results will also not be stable [4].

Authors

This application has been written by OTB-Team.

See Also

These additional resources can be useful for further information:
[1] Comaniciu, D., & Meer, P. (2002). Mean shift: A robust approach toward feature space analysis. IEEE Transactions on pattern analysis and machine intelligence, 24(5), 603-619.
[2] Comaniciu, D., & Meer, P. (1997, June). Robust analysis of feature spaces: color image segmentation. In Computer Vision and Pattern Recognition, 1997. Proceedings., 1997 IEEE Computer Society Conference on (pp. 750-755). IEEE.
[3] Comaniciu, D., & Meer, P. (1999). Mean shift analysis and applications. In Computer Vision, 1999. The Proceedings of the Seventh IEEE International Conference on (Vol. 2, pp. 1197-1203). IEEE.
[4] Michel, J., Youssefi, D., & Grizonnet, M. (2015). Stable mean-shift algorithm and its application to the segmentation of arbitrarily large remote sensing images. IEEE Transactions on Geoscience and Remote Sensing, 53(2), 952-964.
[5] LSMSSegmentation application