Azzera filtri
Azzera filtri

How to select data inside a shape from a map figure

10 visualizzazioni (ultimi 30 giorni)
Adrien
Adrien il 14 Giu 2022
Commentato: Adrien il 14 Giu 2022
Hello,
So, I have a map figure that I obtained through the binaryOccupancyMap function.
I want to manually select an area to filter out the rest. (Since the map cells have binary states, either occupied or free (1 or 0), I'd just have to set every cell ouside my selected area as free).
To select that area, I would use the ginput function to select the vertices of a shape.
Say for example I have this:
If the shape was a rectangle, I would filter out anything to the left of x1 and to the right of x3 and (in this case because of the direction of the y axis) above y3 and under y1.
And that's what I already did (without the ginput, i set the limits on the script itself directly), I took my map, converted it to a matrix using occupancyMatrix and filtered out the rest.
However, I don't know how to do that with a shape that is not rectangular.
The problem is that my data is either map, or a matrix the size of my map (say 50x50 cells) with binary values. From searching a bit I fouund this: isinterior. With this I know how to create a polygon, and get data from inside this polygon, but the function needs both the polygon and x-coordinates and y-coordinates (or a 2 column matrix with one column for x and the other for y).
Would you have any indsight on that?
Thx in advance for any help,
  2 Commenti
KSSV
KSSV il 14 Giu 2022
ginput gives you (x,y) coordinates already.
Adrien
Adrien il 14 Giu 2022
yes, but that is not the issue here. ginput is only to select the polygon vertices. the x and y mentioned on the last paragraph was the data xy, i get how that might have been confusing.
Anyway, I found a solution:
I use the find function to get the indices (rows,columns) of the occupied cells (the ones with a value of 1).
Then this function: TFin = isinterior(polyin,row,col) that returns an vector of ones and zeros (respectively: is inside the polygone, is not inside the polygon).
And since the length of TFin and rows and col is the same, I check for every line of TFin if it's 0 or 1. And for all the lines of TFin equal to 0, I set the cell in my matrix with the indice row,col of the same line as TFin to 0.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by