MATLAB Answers


Converting pixel coordinates to latitude and longitude in decimal degrees for a binary image.

Asked by Ushashi Podder on 22 Oct 2019
Latest activity Edited by Ushashi Podder on 25 Oct 2019
How can I convert the centroid of the pixel coordinates into latitude and longitude values in decimal degrees ?I have used several functions like Utm2deg and utm2ll for doing the same after converting the pixels coordinates to UTM but it does not give any result.I am attaching the code here.It will be helpful if someone can help me with it as I am a novice in matlab.
A= geotiffread("img.tif');
r = regionprops('table',l,'centroid',);
x_centroid= r.Centroid;
y_centroid= r.Centroid;
[lat, lon] = pix2latlon(R,x_centroid,y_centroid);
Thanks in Adavance!


Show 1 older comment
How to display it? Is it the image?
I see nothing
What are boudaries of images (lat/long)?
Maybe this data can be used for scaling?
RasterExtentInWorldX: 20820
RasterExtentInWorldY: 17790
You want to scale your data?
[m,n,~] = size(A); % size in pixels
xx = Left + (Right-Left)/n*x_centroid; % worlds coordinates
yy = Bottom + (Top-Bottom)/m*y_centroid;

Sign in to comment.

1 Answer

Answer by darova
on 23 Oct 2019

You forgot about concantenating (cat) function
A= geotiffread('ems_a&n_subset.tif');
y = im2bw(A);
r = regionprops(y,'Centroid');
xy = cat(1,r.Centroid);
hold on
hold off
r.Centroid returns an asnwer as a structure not an array
>> r.Centroid
ans =
163.5000 235.0000
ans =
518.5882 368.7059


What is connection between degrees and pixels?
Did you try to express x and y?
lng = (x * radian - 135/180*pi) * earth_radius; %[km]
x = 1/radian*(lng/earth_radius + 135/180*pi)
lat = atanh(sin(y)) * earth_radius; %[km]
y = asin(tanh(lat/earth_radius))

Sign in to comment.