向 png 图像添加和检索一些元数据
Adding and retrieving some Meta data to a png Image
我需要为很多图像添加一些元数据。例如,我需要将右眼和左眼的位置添加到元数据中。
就是这样的右眼(291,493),左眼(453,491)。我现在正在处理 png 文件。下面给出了 gimp 的例子。
有什么好的方法可以将这些信息添加到图像元数据中吗?我看过 keywords and strings in png 文件。这是我的问题的解决方案吗?我还需要一个工具来编辑元数据。我有很多面部图像,我需要一个工具来将这些元数据添加到每张图像中。而且我还需要以编程方式从每个图像中检索这些数据。请提出解决所有这些任务的正确方法。
您似乎可以使用 exiv2
或 ImageMagick
在 PNG 图像中设置注释,两者都具有命令行版本和 C++ 库绑定。
所以,如果你这样做:
# Set image description using "exiv2"
exiv2 -M"add Exif.Image.ImageDescription Ascii 'left eye (200,201) right eye(202,203)'" image.png
# Set image comment usimg "ImageMagick"
convert -comment "left eye(76,77) right eye(78,79)" image.png image.png
您现在可以使用 exiftool
查看结果
exiftool image.png
ExifTool Version Number : 10.00
File Name : image.png
Directory : .
File Size : 496 bytes
File Modification Date/Time : 2015:09:20 20:45:29+01:00
File Access Date/Time : 2015:09:20 20:49:22+01:00
File Inode Change Date/Time : 2015:09:20 20:45:29+01:00
File Permissions : rw-r--r--
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 1
Image Height : 1
Bit Depth : 1
Color Type : Grayscale
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
White Point X : 0.3127
White Point Y : 0.329
Red X : 0.64
Red Y : 0.33
Green X : 0.3
Green Y : 0.6
Blue X : 0.15
Blue Y : 0.06
Background Color : 1
Modify Date : 2015:09:20 20:45:29
Exif Byte Order : Little-endian (Intel, II)
Image Description : left eye (200,201) right eye(202,203) <--- HERE
Comment : left eye(76,77) right eye(78,79) <--- HERE
Datecreate : 2015-09-20T20:45:29+01:00
Datemodify : 2015-09-20T20:45:29+01:00
Exif Image Description : left eye (200,201) right eye(202,203)
Image Size : 1x1
Megapixels : 0.000001
或者用ImageMagick
的identify
命令查看结果:
identify -verbose image.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: PseudoClass
Geometry: 1x1+0+0
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 1
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: nan
Colors: 1
Histogram:
1: ( 0, 0, 0) #000000 gray(0)
Colormap entries: 2
Colormap:
0: ( 0, 0, 0) #000000 gray(0)
1: (255,255,255) #FFFFFF gray(255)
Rendering intent: Undefined
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1x1+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
comment: left eye(76,77) right eye(78,79) <--- HERE
date:create: 2015-09-20T20:45:29+01:00
date:modify: 2015-09-20T20:45:29+01:00
exif:ImageDescription: left eye (200,201) right eye(202,203) <--- HERE
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:IHDR.bit-depth-orig: 1
png:IHDR.bit_depth: 1
png:IHDR.color-type-orig: 0
png:IHDR.color_type: 0 (Grayscale)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1, 1
png:text: 5 tEXt/zTXt/iTXt chunks were found
png:text-encoded profiles: 1 were found
png:tIME: 2015-09-20T20:45:29Z
signature: 709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c
Profiles:
Profile-exif: 70 bytes
Artifacts:
filename: image.png
verbose: true
Tainted: False
Filesize: 496B
Number pixels: 1
Pixels per second: 1PB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-09-08 http://www.imagemagick.org
或使用:
exiftool -s -Comment image.png
Comment : left eye(76,77) right eye(78,79)
或使用 exiftool
设置评论并使用 ImageMagick
以两种方式之一阅读:
exiftool -comment="Crazy Comment" image.png
identify -verbose image.png | grep Crazy
comment: Crazy Comment
identify -format "%[c]" image.png
Crazy Comment
我需要为很多图像添加一些元数据。例如,我需要将右眼和左眼的位置添加到元数据中。
就是这样的右眼(291,493),左眼(453,491)。我现在正在处理 png 文件。下面给出了 gimp 的例子。
您似乎可以使用 exiv2
或 ImageMagick
在 PNG 图像中设置注释,两者都具有命令行版本和 C++ 库绑定。
所以,如果你这样做:
# Set image description using "exiv2"
exiv2 -M"add Exif.Image.ImageDescription Ascii 'left eye (200,201) right eye(202,203)'" image.png
# Set image comment usimg "ImageMagick"
convert -comment "left eye(76,77) right eye(78,79)" image.png image.png
您现在可以使用 exiftool
exiftool image.png
ExifTool Version Number : 10.00
File Name : image.png
Directory : .
File Size : 496 bytes
File Modification Date/Time : 2015:09:20 20:45:29+01:00
File Access Date/Time : 2015:09:20 20:49:22+01:00
File Inode Change Date/Time : 2015:09:20 20:45:29+01:00
File Permissions : rw-r--r--
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 1
Image Height : 1
Bit Depth : 1
Color Type : Grayscale
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
White Point X : 0.3127
White Point Y : 0.329
Red X : 0.64
Red Y : 0.33
Green X : 0.3
Green Y : 0.6
Blue X : 0.15
Blue Y : 0.06
Background Color : 1
Modify Date : 2015:09:20 20:45:29
Exif Byte Order : Little-endian (Intel, II)
Image Description : left eye (200,201) right eye(202,203) <--- HERE
Comment : left eye(76,77) right eye(78,79) <--- HERE
Datecreate : 2015-09-20T20:45:29+01:00
Datemodify : 2015-09-20T20:45:29+01:00
Exif Image Description : left eye (200,201) right eye(202,203)
Image Size : 1x1
Megapixels : 0.000001
或者用ImageMagick
的identify
命令查看结果:
identify -verbose image.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: PseudoClass
Geometry: 1x1+0+0
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: Gray
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 1
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: nan
Colors: 1
Histogram:
1: ( 0, 0, 0) #000000 gray(0)
Colormap entries: 2
Colormap:
0: ( 0, 0, 0) #000000 gray(0)
1: (255,255,255) #FFFFFF gray(255)
Rendering intent: Undefined
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: gray(255)
Border color: gray(223)
Matte color: gray(189)
Transparent color: gray(0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1x1+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
comment: left eye(76,77) right eye(78,79) <--- HERE
date:create: 2015-09-20T20:45:29+01:00
date:modify: 2015-09-20T20:45:29+01:00
exif:ImageDescription: left eye (200,201) right eye(202,203) <--- HERE
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:IHDR.bit-depth-orig: 1
png:IHDR.bit_depth: 1
png:IHDR.color-type-orig: 0
png:IHDR.color_type: 0 (Grayscale)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 1, 1
png:text: 5 tEXt/zTXt/iTXt chunks were found
png:text-encoded profiles: 1 were found
png:tIME: 2015-09-20T20:45:29Z
signature: 709e80c88487a2411e1ee4dfb9f22a861492d20c4765150c0c794abd70f8147c
Profiles:
Profile-exif: 70 bytes
Artifacts:
filename: image.png
verbose: true
Tainted: False
Filesize: 496B
Number pixels: 1
Pixels per second: 1PB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-09-08 http://www.imagemagick.org
或使用:
exiftool -s -Comment image.png
Comment : left eye(76,77) right eye(78,79)
或使用 exiftool
设置评论并使用 ImageMagick
以两种方式之一阅读:
exiftool -comment="Crazy Comment" image.png
identify -verbose image.png | grep Crazy
comment: Crazy Comment
identify -format "%[c]" image.png
Crazy Comment