category
AI summary
tags
password
summary
date
icon
status
字数统计
type
slug
orgsrc
URL
在上一篇文章里,我们从 visionOS 模拟器运行时中提取出空间照片(Spatial Photo)的原始文件, 本文尝试解析这一文件格式,并尝试将两张普通的视差图像合并成一张空间照片。
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F5b1339ca-b29b-4e7e-b47b-ca546dd31bdf%2F2023-10-10_23.46.48.gif?table=block&id=ba8ef188-9c3a-4688-b85a-7795870b6f37)
HEIF 文件格式
HEIF 是指高效图像文件格式(High Efficiency Image File Format),它是一种现代图像文件格式,用于存储静态图像和图像序列(例如 HDR 照片、Panoramas 全景照片等),由 Moving Picture Experts Group(MPEG)开发,作为 HEVC(高效视频编码,又称H.265)的补充。Apple 于 2017 年的 iOS 11 中首次采用 HEIF,取代了之前的JPEG格式。这大大减小了照片文件的大小,同时提高了质量。此后,HEIF 也用于 macOS 和其他平台。
你可以在 iPhone 相机设置中选择使用存储照片的格式:
- 高效,即保存 HEIF 格式的照片
- 兼容,即保存 JPEG 格式的照片
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F42afcc03-a7a2-4761-ae62-b591891bc7f1%2FIMG_0533.jpg?table=block&id=2e0c5edb-85ec-4907-be06-c30a21aa8890)
相比 JPEG,HEIF 能够在保持同等视觉质量的前提下使文件大小减小50%。它支持10位色深、高动态范围、包含 透明度 Alpha 通道等特性:
![不同编码格式文件图像质量对比](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2Feea63f47-4f61-4d9d-97d6-01b70824621e%2FUntitled.png?table=block&id=fb7c3b5b-d309-4673-8164-7906a8c57b59)
读写 HEIC 文件
HEIF 作为一种容器格式,它可以包含以不同格式编码的静态图像和图像序列,其中使用 HEVC 作为图像内容编码格式的变体,称为 HEIC(后缀名为
.HEIC
):![HEIC 文件后缀名](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2Fab085398-f96f-4d99-988b-d6eca70ce6be%2FUntitled.png?table=block&id=3a56654c-dffb-4cf9-a249-9e43814ec0ec)
苹果在 WWDC2017 中专门介绍了由 JPEG 转向 HEIF 的原因和细节:
![WWDC2017 - Session 513](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2Fb7a1277e-9d28-4140-8b10-e4d8f7e8a80d%2FUntitled.png?table=block&id=eb5fa068-3a02-497d-88c5-e1c9e559893f)
通过一些图像处理程序库,我们可以对 HEIC 文件进行读写操作:读取文件中的元数据信息、将 JPEG 图片转换成 HEIC 。我们使用 Python 图像处理库 Pillow 的 HEIF 插件:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F4c2c2b92-f710-4523-9d3e-3fc1678b3dcc%2FUntitled.png?table=block&id=b574864e-6f3d-4fb6-8e30-98e623839ba0)
读取
.HEIC
文件,可以看到空间照片是由两张 HEIF 图像序列(Image-Sequence)组成:![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F64c1779f-8bb9-4f7b-900f-365bac8c93cf%2FUntitled.png?table=block&id=d8359b39-19ec-4652-9885-3b1e0f2ebc77)
两张图像分别是左右视差图像:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F75371cc7-62f8-4bfd-a9c4-27137d8ca868%2FUntitled.png?table=block&id=9a710168-c533-4389-a938-6269c6033811)
其中任意一张图像的
info
都保存了图像的元数据:![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F4139391a-26d0-404b-b462-5a85fefa094d%2FUntitled.png?table=block&id=5490b47a-cf01-413d-a5ca-4233aa6182c3)
格式化后的 XMP 数据标签如下,可以从中读取苹果的命名信息:
- SpatialMedia,version=0.3
- 创建工具:SpatialMediaIO
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2Fcf9f778e-ab74-4dec-a625-c8b32dd32727%2FUntitled.png?table=block&id=a8676194-e0ab-48c5-86db-7d1925583988)
如果将读入的原始文件重新导出一份,虽然仍可以保存为
.HEIC
格式,但部分元数据会缺失,再次导入 Apple Vision Pro 模拟器,将无法被正确识别为空间照片:![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F26fa7ab9-33d3-4ce4-ac5c-1c02b463c242%2FUntitled.png?table=block&id=9f2cd78f-068e-4611-8d9d-7f358d8a49ec)
与原始空间图片相比,缺失的信息是元数据中的
HEIC
数据,具体如下:![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2F61de6d99-e5f5-4ac8-9e62-d8a049df6bd3%2FUntitled.png?table=block&id=1c7cb16e-83fe-4d7c-9535-7139e883811f)
总结
Apple Vision Pro 支持的空间照片是以 HEIF 格式存储的图像序列(两张左右视差图像),这也是 iPhone 自 2017 年开始采用的照片格式;可以使用通用处理软件读取、解析空间照片文件,但是如果要自己创建空间照片格式,还缺少必要的元数据信息,只能期待后续 iOS 17 在 iPhone 15 Pro 系列上的更新:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F3c35714a-89c3-4d33-ad58-389eb4cfea25%2Fcbee23cb-8939-4a03-84b8-646d5c559eb6%2FUntitled.png?table=block&id=989d6791-91f4-4702-b260-8ffc5cacd0bf)
参考
- High Efficiency Image File Format | Wikipedia
- HEIF Technical information | https://nokiatech.github.io/heif/technical.html
- High Efficiency Image File Format | WWDC2017-513
- 作者:V2XR
- 链接:https://hackvision.pro/post/apple-vision-pro-spatial-photo-file-format
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。