using boundary command from matlab R2015a
Mostrar comentarios más antiguos
Dear All,
I'm trying to find the boundary for a set of points for dimension n=>2, so I start with dimension 2. This code is from matlab tool box, why the command boundary doesn't work in my version R2013a or R2014a or R2012b, it gave this answer
Undefined function 'boundary' for input arguments of type 'double'.
I need to find the boundary without using the convhull command even in high dimensions. Can anyone answer me which is the appropriate method and why boundary command doesn't work.
x = gallery('uniformdata',30,1,1);
y = gallery('uniformdata',30,1,10);
plot(x,y,'.')
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
Thanks in advance, Imola.
Respuestas (2)
Walter Roberson
el 7 de Jun. de 2015
Introduced in R2014b
9 comentarios
Image Analyst
el 7 de Jun. de 2015
Cool - I didn't know about that. Looks similar to activecontour() except that it works on individual coordinates instead of a solid binary image blob(s).
Walter Roberson
el 8 de Jun. de 2015
You cannot use the boundary() command in R2012b. It was not introduced until R2014b. The obvious solution is to upgrade your MATLAB.
Image Analyst
el 9 de Jun. de 2015
imola, Walter gave you a link to boundary(). It was me that mentioned how it was sort of similar to activecontour(), which is for images. You originally gave no indication that you were dealing with images, in fact you mentioned individual coordinates, and for that boundary() is probably more appropriate.
If your x,y vectors are actually an ordered list of points on the perimeter of a region, then you can use poly2mask to turn it into an image. You would not use bwtraceboundary() but would actually use bwboundaries(), like you did. However you would not need to do that if you already had x and y since bwboundaries() would just give you back the same x and y you passed in to poly2mask() to create the binary image in the first place.
Like you said, bwboundaries gives you the (x,y) coordinates of the boundary/perimeter/outline of each/every blob. I don't know what you mean by "without indices" since it's an ordered list. The index just states what point you are at for that point on the perimeter, for example an index of 5 would mean that x(5), y(5) is the 5th point from the point that it started tracing the boundary around the blob. So please explain "without indices".
I don't know what you mean by "i want for all the points". If you want the rows and columns for every point in the solid regions, you can do
[rows, columns] = find(binaryImage);
but this finds coordinates for the whole image column by column, and you can't tell which points are in which region. This is rarely useful so you'd need to explain more so I can see if that's what you really need. At this point I still don't know if
- you have points and want to create and image and then do something with it, or
- if you have an image and need to find boundary points and then do something with them.
Which is it?
For what it's worth (to others), I have attached an activecontour() demo, though you won't be able to run it until you upgrade your old version of MATLAB, which hopefully you'll do soon.
imola
el 9 de Jun. de 2015
Walter Roberson
el 9 de Jun. de 2015
What properties do you require the boundaries to have?
Why is convexhulln not to be used?
imola
el 10 de Jun. de 2015
Walter Roberson
el 10 de Jun. de 2015
Why are you not allowed to use convexhulln? Is this an assignment intended to have you think about how to implement convex hulls yourself? Or is the routine continued to be too expensive? Or is it a patent issue of some kind?
Given a non-convex shape defined only by vertices, what does it mean for a point to be "inside" it or "outside" of it?
Given any finite set of infinitely-small points and any given point in the list, it is always possible to find a viewpoint from "outside" in which the distinguished point is directly visible, not hidden behind some other point. More formally, given any point in the finite list, it is possible to create a ray from the point to infinity that does not intersect any other point in the list. Thus it is always possible to rotate and translate the cloud so that any given point is at the origin and one is looking down to it from "above" and there are no other points in the way to that origin. Project all the other points onto the x-y plane, and you will have a finite set of points "around" the origin. Take the subset of those points that would be "above" the x-y plane from the view and make a surface from those that does not cross the origin, so that the point at the origin is at the bottom of a "well". That is one valid interpretation of what the point cloud "means", that the well was "always there" and you just didn't realize it because you were looking from a direction that was hiding the walls of the well. From this perspective, with that point at the bottom of the well -- the point at the origin, the distinguished point -- is exactly on the surface.
We thus find that given any cloud of points, we can find a perspective and covering in which any given point in the cloud is on the surface of a covering of the cloud.
Now given any particular test point, is it "inside" the cloud or outside of it? Provided the point is not identical to any other point, provisionally add it to the list, rotate and center the right way, establish the covering in which the point would be on the surface. But the point wasn't originally part of the set, so therefore that point must be on the outside. By induction, every test point that is not identical to one of the original points can be shown to be outside of some covering of the cloud.
Unless, that is, you establish rules about how the points have to be connected. The most easily justified of those rules is to declare that the resulting surface must be convex; this is the surface that would be found by convexhulln()... whether you program the routine yourself or use the library routine, imposing the convex requirement gives very clear conditions that are difficult to argue with.
doreminh
el 29 de Dic. de 2017
Editada: Walter Roberson
el 29 de Dic. de 2017
I tried by this way, it's good,can reply for boundary function:
x = randn(250,1);
y = randn(250,1);
DT = delaunayTriangulation(x,y);
k = convexHull(DT);
n=length(k(:));
for i=1:n
bd(i,1)=x(k(i));
bd(i,2)=y(k(i));
end
figure
fill(bd(:,1),bd(:,2),'r')
hold on
plot(DT.Points(:,1),DT.Points(:,2), '.','markersize',10);
hold on
plot(DT.Points(k,1),DT.Points(k,2),'r')
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!