Issue in reading GPS info from JPG images ?

I have some JPG images that are Geo-Tagged, am trying to read Lat & Long information from them in (Deg,Min,Sec) and want to convert them in decimal degree(DD), but getting some issue, My code is as follow
info = imfinfo('DSC_0011.JPG');
The result of above statement is as follow
**nfo.GPSInfo**
GPSVersionID: [2 3 0 0]
GPSLatitudeRef: 'N'
GPSLatitude: [33 34.2657 0]
GPSLongitudeRef: 'E'
GPSLongitude: [73 8.5707 0]
GPSAltitudeRef: 0
GPSAltitude: 456
GPSTimeStamp: [5 5 48.6400]
GPSSatellites: '05'
GPSMapDatum: 'WGS-84'
GPSDateStamp: '2016:03:31'
As you can see from above result in both rows Lat & Long seconds are 0, but in actually when i checked the properties of corresponding image it was this:
can some one help me to resolve the issue, i am facing same error while reading different images...

4 Comments

Are.D
Are.D on 1 Feb 2017
Edited: Are.D on 1 Feb 2017
Were you able to solve this problem? I am currently struggling with this, and would like to have an answer that maintains the same precision as the original image.
34 minutes 15.941999999999546 second is 34.2657 minutes to within eps() of that value range. So just do the usual
seconds = (minutes - floor(minutes)) * 60
minutes = floor(minutes)
Yes but he may need more accurate than that. Even though there's a 4 meter accuracy in GPS, 1e-16 times the circumference of the earth is 4 nanometers. What if he needs to specify his location down to the nearest angstrom? ;-)
Even if the position were represented in one double (instead of being split into degrees and minutes+fractions),
eps(40075)
ans =
7.27595761418343e-12
and angstrom is 10^10, so double is already capable of representing down to about 1/13th of an angstrom.

Sign in to comment.

 Accepted Answer

What did you use for the second method of getting GPS info? Why not just take the fractional part and multiply by 60 to get seconds:
secs = 0.2657 * 60; % = 15.942 seconds
It will give you the same number of seconds. What's wrong with doing that, if anything?

1 Comment

I just checked the property of image and it provided me the complete GPS information, but thanks for helping...

Sign in to comment.

More Answers (2)

Take the seconds mod 1 and multiply that by 60
Hello,
I would like some help if it is possible for the function imfinfo().
I need a really good accuracy when I export my GPS coordinates from a jpg file.
More particularly on the longitude and on the latitude of the exif data.
Here is my code
filelist = dir('test/*.jpg');
nfiles = length(filelist);
fid = fopen('localisation.csv','w');
Entete={'file','latitude','longitude'};
fprintf(fid,'%s,%s,%s\n',Entete{:});
for i=1:nfiles
disp(['Traitement du fichier n° ',sprintf('%d',i)])
probname = filelist(i).name;
filesource = strcat('test/',probname);
f = imfinfo(filesource);
latitudeTab=f.GPSInfo.GPSLatitude;
longitudeTab=f.GPSInfo.GPSLongitude;
latitude = dms2degrees(latitudeTab);
longitude = dms2degrees(longitudeTab);
formatSpec = '%s,%f,%f\n';
str = sprintf(formatSpec,probname,latitude,longitude);
fprintf(fid,str);
end
fclose(fid);
Don't pay attention to the entire code. The problem is only when I save the data in the f variable.
Matlab rounds the value of latitude and longitude and I don't know how to solve this. Maybe it's the imfinfo function that does this and I cannot do anything about ?
Here is the real value in the jpg file :
Here is the rounded value with matlab :
I already tried with the vpa and with a new Digits, but it seems it doesn't change something. I need the exact value, not a rounded one.
Thanks for your help in advance !

3 Comments

Actually, I claim you don't need that precision. If I do the math correctly
% Subtract the arcseconds (1/3600 of a degree)
deltaLongitudeDegrees = (3.55-3.54999999998824478) / 3600 % Degrees
radiansPerDegree = pi / 180;
circumference = 40075000; % Meters around the earth
radius = circumference / (2*pi) % Radius of earth in meters
distance = radius * deltaLongitudeDegrees * radiansPerDegree
You can see
deltaLongitudeDegrees =
3.26528927353643e-15
radius =
6378134.34440771
distance =
3.63490187880479e-10
so the difference is about "eps" or about 10^(-16) so that's about as accurate you can get with double precision variables. But look at the distance in meters. It's about a third of a nanometer! Three angstroms or about the diameter of an atom. Now the GPS accuracy from your phone and the GPS satellites is only accurate to about the nearest 4 meters: "The United States government currently claims 4 meter RMS (7.8 meter 95% Confidence Interval) horizontal accuracy for civilian (SPS) GPS. " So you're wanting to claim that you need accuracy to within the nearest nanometer when the GPS itself is no accurate than the nearest 4 meters. It just doesn't matter. Even if you used quadruple or octuple precision variables (if they even exist), you'd have mathematical precision that just doesn't make sense when you consider the physical limitations.
Hello,
Okay I got it ! Thank you very much for your answer !
Besides that: the difficulty is probably in your choice of default format for displaying values. Try using
format long g
and also go into Preferences and adjust the default display format.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!