Tight Boundary around a Set of Points

13 ビュー (過去 30 日間)
Jason Nicholson
Jason Nicholson 2016 年 8 月 16 日
編集済み: Jason Nicholson 2018 年 1 月 4 日
I want to draw a tight boundary around a set of points. The code is used below to draw the black boundary around the blue points. The red areas show areas that are not tight enough for my application. Does anyone have a suggestion on how to get a tighter boundary? The data is attached.
clc; clear; close all;
load('xy.mat')
xy = [x y];
plot(xy(:,1), xy(:,2),'.')
grid on;
hold all;
xyNormalized = xy;
for iColumn = 1:2
minValue = min(xy(:,iColumn));
maxValue = max(xy(:,iColumn));
xyNormalized(:,iColumn) = (xy(:,iColumn)-minValue)/(maxValue - minValue);
end
k = boundary(xyNormalized,1);
xyBoundary = xy(k,:);
h = plot(xyBoundary(:,1), xyBoundary(:,2),'k');

採用された回答

Thorsten
Thorsten 2016 年 8 月 16 日
編集済み: Thorsten 2016 年 8 月 17 日
[ux, ia, ib] = uniquetol(x, 0.01);
for i= 1:max(ib), M(i,:) = [min(y(ib == i)) max(y(ib == i))]; end
plot(x, y, '.')
hold on
plot(ux, M(:,1), 'r-')
plot(ux, M(:,2), 'r-')
This is how it looks like
  2 件のコメント
Jason Nicholson
Jason Nicholson 2016 年 8 月 17 日
編集済み: Jason Nicholson 2016 年 8 月 17 日
Good answer. It works. I did have to tighten the tolerance to 0.001.
clc; clear; close all;
load('xy.mat')
xy = [x y];
plot(xy(:,1), xy(:,2),'.')
grid on;
hold all;
[ux, ia, ib] = uniquetol(x, 0.001);
for i= 1:max(ib)
M(i,:) = [min(y(ib == i)) max(y(ib == i))];
end
plot(ux, M(:,1), 'r-')
plot(ux, M(:,2), 'r-')
Thorsten
Thorsten 2016 年 8 月 17 日
You're welcome. Please accept my answer if it works for you.

サインインしてコメントする。

その他の回答 (2 件)

FirefoxMetzger
FirefoxMetzger 2016 年 8 月 16 日
This draws a boundary along the highest elements of each class, the lowest elements of each class and has the left and right outer classes as boundary:
load('xy.mat')
xy = [x y];
plot(xy(:,1), xy(:,2),'.')
grid on;
hold all;
%split data into classes and find max/min for each class
class_label = unique(x);
upper_boundary = zeros(size(class_label));
lower_boundary = zeros(size(class_label));
for idx = 1:numel(class_label)
class = y(x == class_label(idx));
upper_boundary(idx) = max(class);
lower_boundary(idx) = min(class);
end
% plot a nice boundary in red
left_boundary = y(x == class_label(1));
right_boundary = y(x == class_label(end));
plot(class_label(1)*ones(size(left_boundary)),left_boundary,'r')
plot(class_label,upper_boundary,'r')
plot(class_label(end)*ones(size(right_boundary)),right_boundary,'r')
plot(class_label,lower_boundary,'r')
  3 件のコメント
Sinvaldo Moreno
Sinvaldo Moreno 2017 年 12 月 24 日
I believe the fast and easy way is get the boundaries:
% code
load('xy.mat');
xy = [x y]
[k, v] = boundary(xy(:,1),xy(:,2));
plot(xy(:,1), xy(:,2),'.');
hold on;
plot(xy(k,1),xy(k,2));
Jason Nicholson
Jason Nicholson 2018 年 1 月 4 日
編集済み: Jason Nicholson 2018 年 1 月 4 日
Sinvaldo. This is not correct. I want a tight boundary.
The boundary command has an input s called the "shrink factor." A shrink factor of 0 corresponds to the convex hull of the points. A shrink factor of 1 corresponds to the tightest signel region boundary the points. By default, the shrink factor is 0.5 when it is not specified in the boundary command. For example, your code yields the following graph. Look at the answer that I accepted and you will see that the boundary is tighter than the boundary in the graph below.
Even if the shrink factor is set to 1 like in the code and picture below, I still don't think the boundary is tight enough for my purposes. Thanks for the answer but it just isn't what I am looking for.
[k, v] = boundary(xy(:,1),xy(:,2),1);

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 8 月 16 日
You might try the envelope function in the Signal Processing Toolbox:
  1 件のコメント
Jason Nicholson
Jason Nicholson 2016 年 8 月 17 日
Interesting idea. However, the envelope function needs the input to output to be single valued. In math this is called a function, f(x). i.e. There cannot be multiple y values for a single x value.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeBounding Regions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by