添加和检索一些元数据到 png 图像

2024-02-10

I need to add some metadata to a lot of images. For example I need to add the position of the right eye and left eye to the metadata. That is righteye(291,493), lefteye(453,491) like that. I am working with png files now. Example with gimp is given bleow. enter image description here Is there any good way to add these information to image metadata? I have seen keywords and strings in png http://www.w3.org/TR/PNG/#11keywords file. Is that the solution to my problem? Also I need a tool to edit the metadata. I have a lot of facial images, and I need a tool to add these metadata to each image. And also I need to retrieve these data from each image programmatically. Please suggest a proper way to solve all these tasks.


似乎您可以使用以下任一方法在 PNG 图像中设置注释exiv2 or ImageMagick两者都有命令行版本和 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's 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

添加和检索一些元数据到 png 图像 的相关文章

随机推荐