How to plot coast on an image

7 次查看(过去 30 天)
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

采纳的回答

Lionel Dété
Lionel Dété 2017-5-3
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
  1 个评论
santiago ancapichun
Thank you very much for share this solution. I spend 1 day, and now 2 am finally i find the answer to finish my figure: ''[X,Y]=m_ll2xy(img_long,img_lat); % Assign long/lat to row/column of the matrix clf; image([X],[Y],I1,'CDataMapping','scaled');'' Ty very much again!

请先登录,再进行评论。

更多回答(1 个)

Telmo Vieira
Telmo Vieira 2020-1-13
For an image like this example created using imagesc, as simple as following:
load coastlines
figure(1);
imagesc('xdata', lon, 'ydata', (lat), 'cdata', var1);
line(coastlon, coastlat)
  1 个评论
Abdollah Darya
Abdollah Darya 2021-8-8
You are a lifesaver. Been searching for an answer to this problem for ages. Much appreciated.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mapping Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by