# Sampling nodes equally to cover all the environment

조회 수: 1 (최근 30일)
mohammed alany 2019년 7월 28일
댓글: mohammed alany 2019년 7월 30일
if i have this binary image, and i would like to distributed nodes in
the white area, which is the best way can distributed nodes to cover all the environments equally?
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Walter Roberson 2019년 7월 28일
As a first attempt, you could find() the row, column positions of all of the white pixels. Arrange as row column pairs as rows [r1 c1; r2 c2; ...]. Now kmeans requesting 50 clusters.
mohammed alany 2019년 7월 28일
i am new in matlab
i perform this, how i can use kmeans now please?
BW = im2bw(map)
[y, x] = find(map)
c = [x, y]

댓글을 달려면 로그인하십시오.

### 채택된 답변

Walter Roberson 2019년 7월 30일
NC = 50;
BW = im2bw(map);
[y, x] = find(BW);
c = [x, y];
initpos = c(randperm(size(c,1),NC),:);
[idx,cents] = kmeans(c, NC, 'maxiter', 500, 'start', initpos);
ddd = squareform(pdist(cents));
ddd(1:(NC+1):end) = inf;
image(BW);
colormap(gray(2));
N = string(1 : NC);
hold on
scatter(cents(:,1), cents(:,2));
text(cents(:,1), cents(:,2), N);
hold off
You might notice some points at the bottom of the image. That white stripe along the bottom is part of the original image, and so distributing equally in the white portion requires placing some points in that white stripe.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
mohammed alany 2019년 7월 30일
Many thanks, all the time you are giving me the best solutions

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Neighborhood and Block Processing에 대해 자세히 알아보기

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by