MATLAB: How to plot coast on an image

coastimageimage processinglandmasklatitudelongitudemercatorprojection

Hi,
Here is my problem :
I got an image wich is 10980*10980 (from sentinel-2, in jp2). Showing a part of the england (in the south west). There is land, water and cloud.
First, I displayed the picture from RGB to B&W. And now i'm trying to find the coast (and land) to create a mask on the B&W image.
Here is my question : How can I do that ?
I already have use the m_map toolbox (free to use and I can't go for the mapping toolbox unfortunatly). I used the m_gshhs (with full resolution) on my region of interest. And now, I'm looking for "ploting" the mask from m_gshhs to my image. My problem here is that m_gshhs don't give any matrix at all (and so no image) meaning that I can't "compare" them.
EDIT : I just find a way with m_gshhs (from m_map) and my coordinate. But I can't get a matrix from this function.. so I'm trying to "plot" my picture in a georefenced grid currently.
EDIT2 : Currently my image gives me a matrix of intensity. I have the latitude/longitude of the top left corner and right bottom corner. I'm using mercator representation. When I'm using the m_map toolbox I got a white picture. Is there a way to associate long./lat. to my data and plot all of that on a map ? Here is, what I have currently :
% figure,
m_proj('mercator','lon',[a b],'lat',[c d]) %where a,b,c & d are my coordinates (long./lat.)
image([a b],[c d], Inb); % I'm trying to fix my image with the coordinate i have
m_grid; % making a grid which just making my image disappear...
As I know it's a georeference problem, but I don't know how to handle that… How can said to matlab that the point for Img(1,1) refered to lat1/long1 ?
If someone have any ideas to look at.. Thank You,
Lionel DETE

Best Answer

Ok I got it myself ! I just forgot to go from lat./long. to x/y...
Here is some code if someone have the same trouble :
LowLong = A % Lowest value of the longitude
LowLat = B % Lowest value of the latitude
UpLong = C % Highest value of the longitude
UpLat = D % Highest value of the Latitude
img_long = [LowLong UpLong];
img_lat = [UpLat LowLat];
I=imread('path'); % reading the image using your path
m_proj('mercator','longitudes',[LowLong UpLong],'latitudes',[LowLat UpLat]);
hold on % Assign the projection you want (here mercator)
[X,Y]=m_ll2xy(img_long,img_lat); % Assign long/lat to row/column of the matrix
clf;
image([X],[Y],I1,'CDataMapping','scaled');
set(gca,'ydir','normal');
m_grid('tickdir','out','linewi',2,'fontsize',14); %plot georeferenced grid
m_gshhs_f('patch',[0.3 0.7 0.5]); % Patch the coast (making land appear) with different resolution (f=full, h=high, i=intermediate, c=crue)
[data0,long0,lat0] = m_etopo2([Longb Longh Latb Lath]);
testBath=data0 > 0 ;
topo = fl_getBathy(-5,50,long0,lat0,testBath) %return 0 if sea, 1 in land
Related Question