## How can I get a mask matrix from a fill?

### Antonio Barrella (view profile)

on 4 Mar 2019

on 9 Mar 2019
Hello everyone!
I've been struggling with this problem for a while now. I have some SAR images in the form of longitude and latitude matrices. These are images of the ocean, and my task is to identify some areas on the ocean, areas that lie between two different level lines (depth). My task is to create a mask matrix that can only show me the area between the two level lines. So I thought about closing the layer lines in a polygon as shown here in the image, because my initial intention was to use the inpolygon function. This function, however, takes an unreasonable time, so I have to find another way.
Then I noticed that the fill function allows me to highlight the target area...
The problem is that the fill function works only on the graphic part, I would like to know if there is a way to use the fill function in order to build a mask matrix useful to filter from the longitude and latitude matrices only the value in that zone.
Can someone help me? Thanks in advance!
The code is:
%Given MatrLon and MatrLat, I want to work with arrays:
VectLon=reshape(MatrLon,1,[]);
VectLat=reshape(MatrLat,1,[]);
%At this point I can display the image ad a rectangle:
figure
scatter(VectLon,VectLat)
axis([-6 3 44 52])
hold on
%Once I've computed the -5 m and -70 m isolines, I can create a closed
%polygon as follow:
xv=[xdata5 xdata70 xdata5(1)];
yv=[ydata5 ydata70 ydata5(1)];
%At this point I can display the polygon on the image:
plot(xv,yv)
xlabel('longituge')
ylabel('latitude')
legend('image pixel','iso-Depth polygon')
%Now I would like to have a mask matrix in order to filter only points with
%(lat,lon) coordinates inside the polygon, but I have tried inpolygon
%function and it takes too long.
A = fill(xv,yv,'r')
%With fill function I can see the area that I would like to filter, but...
%How can I use the patch object A in order to get a mask matrix?

Jan

### Jan (view profile)

on 4 Mar 2019
If you post a small example for the inputs, it is easier to post a working code. Guessing what your inputs are and inventing some test data at first is inconvenient.
Antonio Barrella

### Antonio Barrella (view profile)

on 4 Mar 2019
You're right, I have just inserted the code!
Rik

### Rik (view profile)

on 4 Mar 2019
There is still no test data attached (or code to generate dummy data).