In writing some image processing routines in Matlab, I found that I don’t know how to write metadata in to a newly processed and saved image. To keep it simple, my flow is as follows:
image = imread('Base_Pic.jpg');
image_info = imfinfo('Base_Pic.jpg');
%Process image...
%Update metadata...
imwrite(image,'Updated_Image.jpg','JPEG','Quality',100);
I basically want the newly processed image to have all the same metadata attributes as the original image, with a few fields updated of course.
How can I append the image_info structure to the newly saved JPEG?
You have a (very) limited ability to do this in
imwrite: for JPEG it only acceptsBitDepth,Comment,ModeandQuality. AndModeandQualitydon’t get returned fromiminfo.In
imwriteyou can do: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
exiftoolon your system, you can useinfonow contains a list of tag names and tag values, e.g.:And if you split on colon
:you can write them back usingexiftool -[TAG]=[VALUE], e.g.exiftool -Make=Apple -Model="iPhone 4" ....Or you can copy them “all” in one foul hit: