How to get the pixel vales along a line?

10 views (last 30 days)
Sophia
Sophia on 27 Oct 2017
Commented: Sophia on 30 Oct 2017
Let's say i want the pixel values along a line that connects two points
lat11 = 72;
lat21 = 81;
long12 = -150;
long22 = -180;
If i do the following i get the pixels for the entire area instead, How to get the pixels just along the line
[i1,j1] = find((lat1>=lat11 & lat1<=lat21) &(long1 >=long22 & long1<=long12));

Answers (2)

Walter Roberson
Walter Roberson on 27 Oct 2017
If you were using an image, then improfile() would be appropriate.
However, you appear to be using a map.
If your georeference just happens to be rectangular linear, then you can use improfile() by matching lat and long to array indices.
However, your latitudes are much too high for you to be able to meaningfully use a rectangular linear georeference: there is very significant compression of the lines that far north.
At this point you need to start asking yourself which "line" you are talking about: Great Cicle? Small Circle? Geodesic taking into account the oblateness of the Earth? You appear to be looking up in the Beaufort Sea or the Arctic Ocean, where there might possibly have been significant scraping or depression due to glaciers, so you might need a more detailed shape model. There might perhaps be a Mapping Toolbox tool that is usable for this purpose; I am not familiar enough with that toolbox to say.
  2 Comments
Sophia
Sophia on 27 Oct 2017
Thanks Walter, i have been using m_map and i did check the great circle script. But honestly just a simple transect would work for me for a simple line plot that shows how the values over that transect has been changing over the years.
Walter Roberson
Walter Roberson on 27 Oct 2017
m_map appears to be a third-party package https://www.eoas.ubc.ca/~rich/map.html . I am not familiar with that package.

Sign in to comment.


Jan
Jan on 27 Oct 2017
It depends on what "the pixels" are. You can get n points on the line from [lat11, long12] to [lat21, long22] (by the way: strange names!):
n = 100;
latPos = linspace(lat11, lat21, n);
longPos = linspace(long21, long22, n);
In your question the variables "lat1" and long1" appear, but you did not explain any details. Perhaps they are matrices and you want to get the pixels nearest to the line? Or all pixels, which are touched by this line? This must be clarified at first.
  2 Comments
Sophia
Sophia on 27 Oct 2017
hahaha..I realized the names were weird, i was typing and those were the first ones(weirdos) that came to my mind.. well, i got the curved line using the code that you mentioned.
lat1 and long1 are the original latitudes and longitudes from the dataset.and i1 and j1 are the associated pixels in which the data is stored.so basically once i have the lat and longs along that line i need to find in which i&j they are located.
My idea is to make a transect and see how the values over this transect has been changing over time. so i need the i and j which are the pixels that i will be looking into to plot for each year.
Sophia
Sophia on 30 Oct 2017
n = 100;
latPos = linspace(lat11, lat21, n);
longPos = linspace(long21, long22, n);
gives me the random lats and long Positions between those values but the trick is how to find the index associated with such values.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!