Why does latlon2pix return non-integer values?

latlon2pix converts latitude-longitude coordinates to pixel coordinates.
[row, col] = latlon2pix(R,lat,lon)
So, as I understand it the output should be integer row and column indices into the map defined by R so that map(row,col) returns the pixel in map that contains the point [lat,lon].
I have ...
R =
0 -0.0028
0.0028 0
23.6282 -22.0506
lat = -23.8750
lon = 27.6250
then
[row, col] = latlon2pix(R,lat,lon)
returns
row = 657.1850
col = 1.4396e+003
so I have to resort to floor(row) and floor(col) before using them as subscripts. I suspect this may not be returning the intended pixel.
Any suggestions appreciated.
Best Wishes
Neil

 採用された回答

the cyclist
the cyclist 2011 年 9 月 24 日

0 投票

I don't have the Mapping Toolbox. But reading the documentation for the latlon2pix() function, I see no indication that the output is necessarily integer pixel values. In fact, the example here: http://www.mathworks.com/help/toolbox/map/ref/latlon2pix.html explicitly mentions getting a column value of 0.5.

4 件のコメント

Neil Caithness
Neil Caithness 2011 年 9 月 24 日
Sounds a bit like platform 10 1/2. I don't quite follow the intention then: what is x(0.5,0.5)?
??? Subscript indices must either be real positive integers or logicals.
the cyclist
the cyclist 2011 年 9 月 24 日
Well, I can't speak with authority, as I don't have the toolbox. But my speculation is that the output is the "exact" calculation of the pixel location, and you are left to use that as you wish (e.g. rounding or taking the floor as you did). I don't think it would be too difficult to devise some test cases to check, or to look inside the code at the algorithm
Walter Roberson
Walter Roberson 2011 年 9 月 24 日
Exact pixels would make sense for people who want to be able to create sub-sampled graphics. It is easy to throw away precision that you do not need, but difficult to regain precision that was thrown away on your behalf.
Neil Caithness
Neil Caithness 2012 年 2 月 2 日
Thanks. Getting the higher precision return is of course preferable.
ROUND (rather than FLOOR, as I expected) returns the correct absolute pixel values.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by