Generating 2D arrays of the coordinates of irregular shapes

8 visualizaciones (últimos 30 días)
EDic
EDic el 16 de Nov. de 2018
Editada: DGM el 17 de Oct. de 2024
Hi,
For a rectangular meshgrid with equally spaced points, it is easy to generate a 2D-array containing either the x or y xoordinates of the points.
But, in the case of a non-rectangular/irregular shape, how can someone build a 2D-array containing its x-coordinates, for example?
Any help will be much appreciated.
Thanks. Efty

Respuestas (1)

Jaswanth
Jaswanth el 17 de Oct. de 2024
Hi,
To generate a 2D array of x-coordinates for an irregular shape in MATLAB, kindly go through the following step by step explanation:
  • Start by outlining your irregular shape with a series of points.
  • Use “meshgrid” to cover the area within the bounding box of your shape, providing a comprehensive grid of x and y coordinates.
  • Apply a logical mask to exclude points outside the irregular shape. The “inpolygon” function can help identify which grid points lie within the shape.
  • With the mask applied, extract the x-coordinates of points that fall inside the shape.
You may refer to the following MathWorks documentation to know more about the functions mentioned above:
I hope the solution provided above is helpful.
  1 comentario
DGM
DGM el 17 de Oct. de 2024
Editada: DGM el 17 de Oct. de 2024
The question was certainly unclear, but I can see one primary interpretation:
"I have a raster image with a shape in it. I want to find the coordinates of its pixels/perimeter/vertices"
Regardless of whether we're trying to find:
  • all the pixels in the region
  • all the pixels on the boundary of the region
  • the vertices of a simplified polygonal representation of the region boundary
... then finding the region/boundary/vertices itself is the first task. You've addressed the task of obtaining these points by telling the user to basically "just go get them", ostensibly manually. That's not much of an answer. If someone doesn't know how to use a mask for addressing an image, would they know how to construct a mask or a point list? Would they know what tools to use?
If OP is asking for coordinates in image space, then there's likely no need for meshgrid() or inpolygon(). Just use the mask for whatever addressing task is needed. Is there some addressing task that would need either? Possibly yes, but what suggests that it's needed here? Are we assuming that we're not working in image space? Are we using inpolygon() because we're trying to avoid creating a mask from a point list? If so, why?
Is my interpretation of the question wrong? I have no idea, because I think the question is too unclear to be answerable. That's why nobody answered it.
Maybe it seems more obvious to you. It's your prerogative to assert a particular interpretation, but you should make it clear what you think the question is asking. If you write answers by concrete example instead of vague bulleted lists, your intentions naturally tend to be more evident.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by