33 lines
827 B
Matlab
33 lines
827 B
Matlab
function germes = super_pixel(img, K, m, n)
|
|
N = size(img, 1) * size(img, 2);
|
|
S = sqrt(N / K);
|
|
X = S/2:S:size(img, 1);
|
|
Y = S/2:S:size(img, 2);
|
|
germes = zeros(length(X) * length(Y), 2);
|
|
c = 1;
|
|
for x = X
|
|
for y = Y
|
|
germes(c,:) = [x y];
|
|
c = c + 1;
|
|
end
|
|
end
|
|
|
|
c = 1;
|
|
for germe = germes'
|
|
x = germe(1);
|
|
y = germe(2);
|
|
xmin = max(x - n, 1);
|
|
interval_x = xmin:min(x + n, size(img, 1));
|
|
ymin = max(y - n, 1);
|
|
interval_y = ymin:min(y + n, size(img, 2));
|
|
Gmag = imgradient(img(interval_x, interval_y));
|
|
[~,ind_min] = min(Gmag(:));
|
|
[nr, nc] = ind2sub(size(Gmag), ind_min);
|
|
x = xmin + nr - 1;
|
|
y = ymin + nc - 1;
|
|
germes(c,:) = [x y];
|
|
c = c + 1;
|
|
end
|
|
end
|
|
|