如何在Matlab中将元数据附加到图像? [英] How do I append metadata to an image in Matlab?
问题描述
在Matlab中编写一些图像处理程序时,我发现我不知道如何将元数据写入新处理和保存的图像中。为了简单起见,我的流程如下:
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.
如何将 image_info
结构附加到新保存的 JPEG
?
How can I append the image_info
structure to the newly saved JPEG
?
推荐答案
你有一个(非常)有限的能力在 imwrite中执行此操作
:对于JPEG,它只接受 BitDepth
,评论
,模式
和质量
。并且模式
和质量
不会从 iminfo
返回。
在 imwrite
中你可以这样做:
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);
除此之外,到目前为止还没有办法用Image Processing Toolbox / Matlab做到这一点我所知。如果您有TIFF或医学图像,有许多工具箱可以做到这一点,但我还没有找到任何jpeg,即使在文件交换...
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...
如果您的系统上有 exiftool
,则可以使用
If you have exiftool
on your system, you can use
[status info]=system('exiftool -s Base_Pic.jpg');
info
现在包含标签名称列表和标记值,例如:
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
...
如果你拆分冒号:
你可以使用 exiftool - [TAG] = [VALUE]
将它们写回来,例如 exiftool -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')
这篇关于如何在Matlab中将元数据附加到图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!