MATLAB Answers

0

How can I get a mask matrix from a fill?

Asked by Antonio Barrella on 4 Mar 2019
Latest activity Answered by Chad Greene
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?

  3 Comments

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.
You're right, I have just inserted the code!
There is still no test data attached (or code to generate dummy data).

Sign in to comment.

Tags

1 Answer

Answer by Chad Greene
on 9 Mar 2019

Perhaps you want to use inpolygon to get a mask of grid cells within the polygon?

  0 Comments

Sign in to comment.