You are here : matlabImage Processingsuperpixels

superpixels() - Image Processing

[L,NumLabels]
= superpixels(A,N) computes
superpixels of the 2-D grayscale or RGB image A. N specifies
the number of superpixels you want to create. The function returns L,
a label matrix of type double, and NumLabels,
the actual number of superpixels that were computed.The superpixels function uses the simple
linear iterative clustering (SLIC) algorithm. This algorithm groups
pixels into regions with similar values. Using these regions in image
processing operations, such as segmentation, can reduce the complexity
of these operations.[L,NumLabels]
= superpixels(___,Name,Value,...) computes
superpixels of image A using with Name-Value pairs used to control
aspects of the segmentation.Code Generation support:
Yes. MATLABĀ® Function Block support: No.


Syntax

[L,NumLabels]
= superpixels(A,N) example[L,NumLabels]
= superpixels(___,Name,Value,...)


Example

Compute Superpixels of Input RGB ImageOpen This Example
Read image into the workspace.A = imread('kobi.png');
Calculate superpixels of the image.[L,N] = superpixels(A,500);
Display the superpixel boundaries overlaid on the original image.figure
BW = boundarymask(L);
imshow(imoverlay(A,BW,'cyan'),'InitialMagnification',67)

Set the color of each pixel in the output image to the mean RGB color of the superpixel region.outputImage = zeros(size(A),'like',A);
idx = label2idx(L);
numRows = size(A,1);
numCols = size(A,2);
for labelVal = 1:N
    redIdx = idx{labelVal};
    greenIdx = idx{labelVal}+numRows*numCols;
    blueIdx = idx{labelVal}+2*numRows*numCols;
    outputImage(redIdx) = mean(A(redIdx));
    outputImage(greenIdx) = mean(A(greenIdx));
    outputImage(blueIdx) = mean(A(blueIdx));
end

figure
imshow(outputImage,'InitialMagnification',67)

Related ExamplesPlot Land Classification with Color Features and Superpixels


Output / Return Value


Limitations


Alternatives / See Also


Reference