clc;close all;clear;%Mutual conversion of geographic coordinates and pixel coordinates [PIC,R]=geotiffread ('boston.tif'); %read a TIF image with geo-coordinate information [M,n,~]=size (pic);%convert pixel coordinates to geographic coordinates figure (1), Imshow (pic), title ('static picture without geographic coordinates'); hold on; Scatter (n/4, m/4, -,'R.'); % Selection 1/4 pixel coordinates and marked [Lon,lat] on the graph=pix2map (r,m/4, n/4); %Convert to geographic coordinates figure (2), Mapshow (pic,r); Mapshow (Lon,lat,'Marker','.','Markeredgecolor','R'); Title ('TIF imagery with geographic coordinates'); axis off;%Print Results disp (['(', Num2str (m/4),',', Num2str (n/4),'), (', Num2str (Lon),',', Num2str (LAT),')']); %geographic coordinates are converted to pixel coordinates. Note that geographic coordinates start at the lower-left corner, and pixel coordinates start at the upper-left corner% start point in the lower left corner geographical coordinates for [R.xlimworld (1), R.ylimworld (1)]%R.rasterwidthinworld represents the geographic width of the image x=r.xlimworld (1)+(3/4) *r.rasterwidthinworld; % get Image 3/geographical coordinates y at 4=r.ylimworld (1)+(1/4)*R.rasterheightinworld;figure (3), Mapshow (pic,r), Axis off;mapshow (x, Y,'Marker','*','Markeredgecolor','R'); [Row,col]=Map2pix (r,x,y); figure (4), Imshow (pic), hold On;scatter (Col,row, -,'r*');%Print Results disp on the command line (['(', Num2str (x),',', Num2str (y),'), (', Num2str (Row),',', Num2str (COL),')']);
Pixel coordinates to geographical coordinates: PIX2MAP
Geographical coordinates to pixel coordinates: MAP2PIX
Conversion of geographic coordinates and pixel coordinates in MATLAB