How do I append metadata to an image in Matlab?

断了今生、忘了曾经 提交于 2019-12-05 02:36:53

You have a (very) limited ability to do this in imwrite : for JPEG it only accepts BitDepth, Comment, Mode and Quality. And Mode and Quality don't get returned from iminfo. In imwrite you can do:

iminfo = imfinfo('Base_Pic.jpg')
imwrite(...,'BitDepth',iminfo.BitDepth, 'Comment',iminfo.Comment);

Other than that, there isn't a way to do this with Image Processing Toolbox/Matlab as far as I know. If you have TIFF or medical images there are a number of toolboxes that do it, but I haven't ever found any for jpeg, even on the File Exchange...

If you have exiftool on your system, you can use

[status info]=system('exiftool -s Base_Pic.jpg');

info now contains a list of tag names and tag values, e.g.:

ExifToolVersion                 : 8.75
FileName                        : Base_Pic.jpg
Directory                       : Pictures
FileSize                        : 2.0 MB
FileModifyDate                  : 2011:10:27 08:41:55+10:00
FilePermissions                 : rw-rw-r--
FileType                        : JPEG
MIMEType                        : image/jpeg
JFIFVersion                     : 1.01
ExifByteOrder                   : Big-endian (Motorola, MM)
Make                            : Apple
Model                           : iPhone 4
...

And if you split on colon : you can write them back using exiftool -[TAG]=[VALUE], e.g. exiftool -Make=Apple -Model="iPhone 4" ....

Or you can copy them "all" in one foul hit:

system('exiftool -overwrite_original -tagsFromFile Base_Pic.jpg Updated_Image.jpg')

Read this : http://www.mathworks.co.uk/help/matlab/import_export/exporting-to-images.html#br_c_iz-1

under the title : "Exporting Image Data and Metadata to TIFF Files" ...

If you aren't modifying too many of the fields you could make use of exiftool, which is an executable which can read and write exif tags.

I'd probably do something like:

image = imread('src.jpg');  
image_info = imfinfo('src.jpg');
%Process image...
%Update metadata...
imwrite(image,'dst.jpg','JPEG','Quality',100);

% copy over all the tags
system('exiftool -tagsfromfile src.jpg dst.jpg');

% then use exif tool to update the specific tags
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!