Tight Boundary around a Set of Points
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jason Nicholson
el 16 de Ag. de 2016
Editada: Jason Nicholson
el 4 de En. de 2018
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');
0 comentarios
Respuesta aceptada
Thorsten
el 16 de Ag. de 2016
Editada: Thorsten
el 17 de Ag. de 2016
[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
Más respuestas (2)
FirefoxMetzger
el 16 de Ag. de 2016
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 comentarios
Sinvaldo Moreno
el 24 de Dic. de 2017
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
el 4 de En. de 2018
Editada: Jason Nicholson
el 4 de En. de 2018
Image Analyst
el 16 de Ag. de 2016
You might try the envelope function in the Signal Processing Toolbox:
Ver también
Categorías
Más información sobre Bounding Regions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!