using boundary command from matlab R2015a

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
Walter Roberson el 7 de Jun. de 2015

9 comentarios

Image Analyst
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).
imola
imola el 8 de Jun. de 2015
Editada: imola el 9 de Jun. de 2015
Dear Walter,
this command is for image activecontour().
my version is R2012b.
I hope you have suggestion.
Regards,
Imola
Walter Roberson
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.
imola
imola el 9 de Jun. de 2015
Editada: imola el 9 de Jun. de 2015
Thanks Walter,
I will try. but for the command activecontour if it give me the indices of the set of points then how to use it because it read from
bw = activecontour(A,mask)
i'm confusing what to do, i read from central matlab some suggestions like using poly2mask then bwtraceboundaries to get the indices of the boundary but i dont know how to do it. i tried this
n=100;
m=2;
x=50*rand(n,1);
y= 50*rand(n,1);
BW = poly2mask(x, y,100,100);
D=bwboundaries(BW);
imshow(BW);
hold on
plot(x,y,'b.')
hold off
This give me the boundary of separate regions and without indices while i want for all the points. if activecontour give me the indices then how write it.
regards
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
  1. you have points and want to create and image and then do something with it, or
  2. 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
imola el 9 de Jun. de 2015
Dear Image Analyst,
thanks for answer, dear i'm dealing with a set of points and i don't know what to do i'm looking at every suggestion to see how to do it. i thought that i can deal with the set as an image to get the boundary.
Dear i have a set of points i need to find the boundary for them. the points of the boundary set is what i want, so I can use them in may work. I'm so sorry for confusing you and walter, and i'm sorry for discussing the function activecontour() with walter not you. my work doesn't deal with images. its very simple just find the points around the set and i need it not just in 2,3 dimensions but also in high dimensions.
thanks for both of you.
Walter Roberson
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
imola el 10 de Jun. de 2015
Dear Walter,
I'm not allowed to use convexhulln in my work. i have set of points and i want to check them inside a shape, when i check a large set that's will consume time so i decided to take the points in the border that's faster. now i think in 2-3 dimensions hopefully not bad but i will need to find it in high dimensions. I finally install R2015a and i run my code from there now i test it in 2-dimensions is good, but i need to run my code from R2012b which is faster and give better result from it. I decided to take the code of boundary from R2015a to use it in R2012b but still have problem to get some functions deal with the code (criticalAlpha and alphaShape) i'm trying to get them and use them in R2012b. If you have an idea how to get them because the function boundary it was easy to get it but these i search a lot for them inside the files and i tried to open them from command window by call them with wrong input and it failed.
Many thanks Walter and Image Analyst you help me a lot.
regards,
Walter Roberson
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.

Iniciar sesión para comentar.

doreminh
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')

Preguntada:

el 7 de Jun. de 2015

Editada:

el 29 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by