How use add GPS locations to metadata for images? (I don't understand demo for the run_exiftool toolbox)

3 views (last 30 days)
I have GPS locations saved as part of the file name. I can read this image in and get the metadata using getexif function. Also, I can add the GPS locations to the metadata. But how can I save the new metadata to the image using putexif?
I have attached an image with two metadata variable in Matlab.
I don't understand the example for the run_exiftool.
[f,p] = uigetfile({'*.jpg';'*.tif'}, ...
'Select image file');
% Read Exif data
exifdata = getexif([p,f]);
disp(exifdata) % this will generate a metadata string after selecting the image
dat = imread([p,f]);
imagesc(dat), axis image % read the same image in
%
% Do processing image data here ...
% (For this demo. we save the original data)
%
[f1,p1] = uiputfile({'*.jpg';'*.tif'},'Save as'); % it will generate a file path and name for me to save the image
% Save image with original Exif data
status = putexif(dat,[p1,f1], [p,f]);
% putexif has can NOT take the new metadata as an input. What can I do?

Answers (1)

Siraj
Siraj on 25 Sep 2023
Hi!
I understand that you want to add latitude and longitude data to the existing metadata of an image and save it along with the image file.
It appears that you are considering using the "run_exiftool" wrapper for this task. However, based on my knowledge, the "run_exiftool" wrapper copies the entire metadata from a reference image, which may not be desirable in your situation.
Alternatively, you can explore using the TIFF object to accomplish your goal. The TIFF object provides the ability to modify and rewrite specific tags within the image metadata. To determine which tags are supported and can be utilized for adding latitude and longitude data, you can refer to the following link:
You can modify these tags repeatedly as needed, and then use the "rewriteDirectory" function to write the modified metadata to an existing directory. For more information on how to use the "rewriteDirectory" function and its capabilities, you can refer to the following link:
To learn about TIFF objects in general you can refer to the following link:
If you encounter limitations in using the supported TIFF tags for writing latitude and longitude information, you can utilize GeoTIFF objects instead. For more detailed information about GeoTIFF and its capabilities, you can refer to the following link:
Hope this helps.

Community Treasure Hunt

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

Start Hunting!