A list,

1 the concept

A superpixel is a small area consisting of adjacent pixels with similar color, brightness, texture, and other characteristics. Most of these small regions retain the effective information for further image segmentation and generally do not destroy the boundary information of objects in the image.

A pixel-level map, divided into district-level maps, is an abstraction of basic information elements.



(a) is the original image, (b) is the groundtruth based on human perspective, (c) is the image of super pixel segmentation, (d) is the image of segmentation based on (c).

One of the biggest functions of superpixels is that they act as preprocessing for other algorithms in image processing, reducing dimensions without sacrificing too much accuracy.

The most intuitive interpretation of superpixels is to “aggregate” a number of pixels with similar properties into a larger, more representative “element”. This new element will serve as the basic unit for other image processing algorithms. This can reduce the dimension and eliminate some abnormal pixels.

Theoretically, any over-segmentation algorithm can generate superpixels.

In image segmentation, superpixel refers to the irregular pixel blocks with certain significance formed by adjacent similar features such as texture, color and brightness. It uses the similarity of features among pixels to group pixels, and uses a small number of superpixels to replace a large number of pixels to express image features, which greatly reduces the complexity of image processing, so it is usually used as a pre-processing step of segmentation algorithms.

2. Superpixel discriminant conditions

(1) Undersegmentation Error



(2) As shown in the figure above, white is an object in the image, red lines are the Outlines of each superpixel, and pink areas are the undersegmentation areas. The larger the area, the worse it is.

Boundary Recall



As shown above, black dotted and solid lines are the Outlines of objects in the image, and red lines are the boundaries of the superpixels. A good superpixel algorithm should overwrite the contours of objects in the image. As much as the superpixel edge can cover the image object edge (solid black line), the better, given a certain buffer (pink area).

(3) Compactness Score

Measure whether the superpixel is “tight”.



3. Method of super pixel initialization

Seed pixel initialization

SLIC uses a simple clustering (greedy) algorithm. Initially, the centers of each cluster are evenly distributed in the image, and the number of superpixels can be basically determined by these centers. At each iteration, the seed pixel merges the surrounding pixels to form a superpixel.



Rectangle area initialized

The initialization of SEEDS is to evenly divide the image into many rectangles. The initial superpixels are these rectangles. With each iteration, the edges of the superpixels change until they converge.

4. Super pixel algorithm



5 SLIC algorithm

Simple Linear clustering (SLIC) is a simple linear iterative clustering. It is an algorithm proposed in 2010 with simple idea and convenient implementation. It converts color images into 5-dimensional feature vectors in CIELAB color space and XY coordinates, and then constructs distance metrics for the 5-dimensional feature vectors to perform local clustering of image pixels. The SLIC algorithm can generate compact and nearly uniform superpixels, and has a high comprehensive evaluation in terms of computing speed, object contour retention and superpixel shape, which is more in line with the expected segmentation effect.

5.1 ADVANTAGES of the SLIC

The generated superpixels are as compact and neat as cells, and the neighborhood features are easy to express. In this way, the pixel-based method can be easily transformed into the superpixel-based method. It can not only segment color image, but also compatible with gray image segmentation. There are very few parameters to set, and by default you only need to set a number of pre-split superpixels. Compared with other methods of superpixel segmentation, SLIC is ideal in terms of running speed, compactness of superpixel generation and contours preservation.

5.2 Algorithm steps:

Initialization of seed points (clustering center) : distribute seed points evenly in the image according to the set number of superpixels. Assuming that the image has N pixels in total and is pre-divided into K superpixels of the same size, then the size of each superpixel is N/K, and the distance (step) of adjacent seed points is approximately S= SQRT (N/K).

Reselect the seed point in the N * N field of the seed point (generally n=3) : calculate the gradient value of all pixel points in the field and move the seed point to the place with the smallest gradient in the field. Avoid seed points falling on the contour boundary with large gradient, so as not to affect the subsequent clustering effect.

Each pixel is assigned a category label (i.e. which cluster center it belongs to) in the domain around each seed point: the search range of SLIC is 2S2S and the desired superpixel size is SS, which speeds up algorithm convergence.

Distance measurement: includes color distance and space distance. For each pixel point searched, the distance between it and the seed point is calculated separately.



Ii. Source code

The core program that determines the location of the superpixel is EnforceLabelConnectivity %11- 123.CLC clear close all; tic img = imread('bee.jpg');
imshow(img)
title('original') % Set the number of super pixels K =500; % Set the superpixel compactness factor m_compactness =100;

%%
img = DeSample(img,2); img_size = size(img); % convert to LAB color space cform = makecForm ('srgb2lab'); Create color transformation structure img_Lab = applycform(img, cform); % RGB is converted into lab space figure; imshow(img_Lab) title('img_lab'Img_sz = img_size(1)*img_size(2); superpixel_sz = img_sz/K; % Number of pixels per superpixel STEP = uint32(sqrt(superpixel_sz)); Xstrips = uint32(IMG_Size (2)/STEP); Ystrips = uint32(IMG_Size ()1)/STEP); % number of superpixels in y direction xstrips_adderr =double(img_size(2)) /double(xstrips);  
ystrips_adderr = double(img_size(1)) /double(ystrips); numseeds = xstrips*ystrips; % Actual number of superpixels % Seed point xy information initial value is the sub-pixel coordinates of the lattice center % Seed point Lab color information is the color channel value of the corresponding point closest to the pixel point kseedsx = Zeros (Numseeds,1);
kseedsy = zeros(numseeds, 1);
kseedsl = zeros(numseeds, 1);
kseedsa = zeros(numseeds, 1);
kseedsb = zeros(numseeds, 1);

n = 1;
for y = 1: YStrips % Y Super pixelfor x = 1: XStrips % X Super Pixel KSEEDSX1) = (double(x)0.5)*xstrips_adderr; % x seed point center coordinates, inexact description kseedsy(n,1) = (double(y)0.5)*ystrips_adderr; % y seed point center coordinates, inaccurately describe % seed point center corresponding to the location on the LAB map of the three-channel value kseedsl(n,1) = img_Lab(fix(kseedsy(n, 1)), fix(kseedsx(n, 1)), 1);  % fix 417.1296417
        kseedsa(n, 1) = img_Lab(fix(kseedsy(n, 1)), fix(kseedsx(n, 1)), 2); 
        kseedsb(n, 1) = img_Lab(fix(kseedsy(n, 1)), fix(kseedsx(n, 1)), 3);
        n = n+1;
    end
end

n = 1; Klabels = PerformSuperpixelSLIC(img_Lab, kSEEDSL, kseedsa, kseedsb, kseedsx, kseedsy, STEP, m_compactness); % Merge small partitions [Supmtrx, Supmtry,nlabels] = EnforceLabelC(img_Lab, klabels, K); Function klabels = PerformSuperpixelSLIC(img_Lab, kSEEDSL, kseedsa, kseedsb, kseedsx, kseedsy, STEP, compactness) [m_height, m_width, m_channel] = size(img_Lab); [numseeds xxxxx]= size(kseedsl); img_Lab =double(img_Lab); % pixel labels are formatted as (x, y) (row, column) klabels = zeros(m_height, m_width); Clustersize = Zeros (numseeds,1);
inv = zeros(numseeds,1);
sigmal = zeros(numseeds,1);
sigmaa = zeros(numseeds,1);
sigmab = zeros(numseeds,1);
sigmax = zeros(numseeds,1);
sigmay = zeros(numseeds,1);
invwt = 1/( (double(STEP)/double(compactness)) *(double(STEP)/double(compactness)) );
%invwt = double(compactness)/double(STEP);
distvec = 100000*ones(m_height, m_width);
numk = numseeds;
for itr = 1: 10Sigmal = zeros(numseeds,1);
    sigmaa = zeros(numseeds, 1);
    sigmab = zeros(numseeds, 1);
    sigmax = zeros(numseeds, 1);
    sigmay = zeros(numseeds, 1);
    clustersize = zeros(numseeds, 1);
    inv = zeros(numseeds, 1);
    distvec = double(100000*ones(m_height, m_width)); % Calculate the attribution of each pixel according to the current seed point informationfor n = 1: numk
        y1 = max(1, kseedsy(n, 1)-STEP);
        y2 = min(m_height, kseedsy(n, 1)+STEP);
        x1 = max(1, kseedsx(n, 1)-STEP);
        x2 = min(m_width, kseedsx(n, 1)+STEP); % Calculates distance in pixelsfor y = y1: y2
            for x = x1: x2
                %dist_lab = abs(img_Lab(y, x, 1)-kseedsl(n))+abs(img_Lab(y, x, 2)-kseedsa(n))+abs(img_Lab(y, x, 3)-kseedsb(n)); Dist_lab = (img_Lab(y, x, y, y, y)1)-kseedsl(n, 1)) ^2+(img_Lab(y, x, 2)-kseedsa(n, 1)) ^2+(img_Lab(y, x, 3)-kseedsb(n, 1)) ^2; % change to square ah!! @ @ @!!!!!! @ @ @!!!!!! dist_xy = (double(y)-kseedsy(n, 1)) * (double(y)-kseedsy(n, 1)) + (double(x)-kseedsx(n, 1)) * (double(x)-kseedsx(n, 1));
                %dist_xy = abs(y-kseedsy(n)) + abs(x-kseedsx(n)); % distance = Lab color space distance + space distance weight × space distance dist = dist_lab + dist_xy*invwt; % Store klabels %m = (y) on the nearest four seed points- 1)*m_width+x;
                if(dist<distvec(y, x)) distvec(y, x) = dist; Klabels (y, x) = n; End end end % After completing the classification, recalculate the seed position and move it to the lowest gradient ind =1;
    for r = 1: m_height
        for c = 1: m_width
            sigmal(klabels(r, c),1) = sigmal(klabels(r, c),1)+img_Lab(r, c, 1); % add all channel values in the pixel block sigmaA (klabels(r, C),1) = sigmaa(klabels(r, c),1)+img_Lab(r, c, 2);
            sigmab(klabels(r, c),1) = sigmab(klabels(r, c),1)+img_Lab(r, c, 3);
            sigmax(klabels(r, c),1) = sigmax(klabels(r, c),1)+c; % add all the abscissa in the pixel block sigmay(klabels(r, C),1) = sigmay(klabels(r, c),1)+r; Clustersize (klabels(r, C),1) = clustersize(klabels(r, c),1) +1; % add all the numbers in the pixel block end endfor m = 1: numseeds % Specifies the MTH seed pointif (clustersize(m, 1) < =0)
            clustersize(m, 1) = 1;
        end
        inv(m, 1) = 1/clustersize(m, 1);
    end
    function [supmtrx,supmtry,nlabels] = EnforceLabelC(img_Lab, labels, K)

dx = [- 1.0.1.0]; % quadrangle dy = [0.- 1.0.1]; [m_height, m_width, m_channel] = size(img_Lab); [M, N] = size(labels); numlabel = max(max(labels)); SUPSZ = (m_height*m_width)/K; % Standard area nlabels = (- 1)*ones(M, N);

label = 1;
adjlabel = 1;
xvec = zeros(m_height*m_width, 1);
yvec = zeros(m_height*m_width, 1);
supmtrx = zeros(2*floor(SUPSZ), numlabel);
supmtry = zeros(2*floor(SUPSZ), numlabel);
m = 1;
n = 1;

for j = 1: m_height
    for k = 1: m_width % Looks point by point for unmarked areas less than0To performif (0>nlabels(m, n)) % From the first unlabeled (m,n) to set a new labels, label the starting point of the field, use the butterfly shape to advance nlabels(m, n) = label; % Start a new partition record starting coordinates xvec(1.1) = k;
            yvec(1.1) = j;
            supmtrx(1, label) = k;
            supmtry(1, label) = j; % If the starting point is connected to a known region, the region number is recorded with AdjLabel. If the current region is too small, it is merged with adjacent regionsfor i = 1: 4
                x = xvec(1.1)+dx(1, i);
                y = yvec(1.1)+dy(1, i);
                if (x>0 && x<=m_width && y>0 && y<=m_height)
                    if (nlabels(y, x)>0) adjlabel = nlabels(y, x); % is usually the label of the left or upper neighbor end end EndCopy the code

3. Operation results







Fourth, note

Version: 2014 a