Many formats of image files like jpg, png, tiff enable to read/write inside binary file information some comments, captions (so called IPTC data), EXIF data. They can accesible, for example, by XnView viewer, by Edit\Metadata\Edit IPTC data\ or by <Ctrl i> key combination.
It would be very useful and convenient to read/write such fields from Matlab to keep there some service information deals with image processing or parameters of image acquisiton.
Searching of Matlab answers and file exchange shows only possibility to read EXIF data or putting comments, annotation directly into image of such image file.
Is it possible and how is it possible to operate with such fields from Matlab?
Thank you

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Dez. 2019

0 Stimmen

MATLAB only permits reading EXIF, and only for some image formats.
There is a File Exchange contribution for MS Windows that can invoke an external .exe to write EXIF information.
EXIF-like information can be written into TIFF files if you use the Tiff() class interface and set the appropriate tag fields. It is not all that convenient to do so, but it can be done.
Those are the only things that are available.

5 Kommentare

Valeriy
Valeriy am 22 Dez. 2019
Thank you, Walter Robertson and Image Analyst for your informative reply.
Happily I'm working now with tiff format. After performing
t = Tiff(FileName,'r');
I have following fields:
t.FileName, t.TagID, t.SubFileType, t.Compression, t.Photometric, t.Thresholding, t.Orientation, t.PlanarConfiguration, t.ExtraSamples, t.Group3Options, t.ResolutionUnit, t.InkSet, t.SampleFormat, t.YCbCrPositioning, t.SGILogDataFmt, t.JPEGColorMode
All of them, except t.FileName, which I don't like to touch, are numerical ones, but what I'd like is to put in some of them mixed, string and numerical values. Is it possible and where?
Thanks a lot for your help
Walter Roberson
Walter Roberson am 23 Dez. 2019
The Tiff class has some internal functions to display values in nicer format. Unfortunately the routines are not public. The way they work is to getTag to get the numeric value of the tag, and then they compare the numeric value with the contents of the fields of the structure obj.(propertyname) until they find a match, and then pull out the corresponding field name to complete the printable representation. That is logic that you can duplicate yourself.
If you really want to inject EXIF into a TIFF file, then according to https://en.wikipedia.org/wiki/Exif#Technical
When Exif is employed in TIFF files (also when used as "an embedded TIFF file" mentioned earlier), the TIFF Private Tag 0x8769 defines a sub-Image File Directory (IFD) that holds the Exif specified TIFF Tags.
Thus you would create an IFD containing the EXIF tags you wanted, and you would set tag 0x8769 of the main image to contain the IFD number.
Note that most of the EXIF tags store the data in numeric form: you are just accustomed to having the numeric forms decoded for you.
Please note the warnings in the wikipedia EXIF page, that adding or altering EXIF information in an image can result in the image becoming unusable with the original camera it was taken on.
Valeriy
Valeriy am 24 Dez. 2019
Thank you, Walter, for your detailed answer. Now situation is much more clear. It seems that for purposes I have mentioned, it is reasonable to use FileName, to code/decode service information into it.
From the other hand, image files have a lot of possibilities to keep text information. Probably further Matlab development will open for user possibility to use it, to work with IPTC fields.
Walter Roberson
Walter Roberson am 24 Dez. 2019
EXIF effectively doesn't work for any of the common image formats except for JPEG and TIFF, and the EXIF wikipedia page explains why it is less than ideal in practice (data pointers are only relative, so you have to rebuild the pointers every time you modify the size of anything; encrypted private tags are used by some manufacturers to lock you into their eco-system; cameras / instruments do not have full EXIF processing and so moving an adjusted image back to the device is often incompatible.)
Valeriy
Valeriy am 26 Dez. 2019
Dears Walter Robertson, Image Analyst,
At first, Merry Christmas!
Thanks for your help. As usually, reading Matlab Help is useful activity: after all I have found there answer on my question.
To write additional information into image file one can use:
imwrite(MatrVar,'FileName.jpg','Comment','This is my information'); % or
imwrite(MatrVar,'FileName.png','Comment','This is my information',...
'Author','Another information','Description','Additional information field'); % or
imwrite(MatrVar,'FileName.tif','Description','This is my information')
To read this information:
info = imfinfo('FileName.png'); % for example
MyFirstInformation = info.Comment;
AnotherInformation = info.Author; % etc.
Verification shows that it works.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Community Treasure Hunt

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

Start Hunting!

Translated by