toruのブログ

月1くらいで記事書きたい。

Windows で HDRのスクリーンショットを撮影した際に生成される JPEG XR (.jxr) ファイルの RAW値を Python で読む

結論

imagecodecs というライブラリを使えばよい。

筆者が試した例の紹介

インストール

python -m pip install -U imagecodecs[all]

サンプルコードと実行結果

サンプルコードを以下に示す。

# -*- coding: utf-8 -*-
import sys
from imagecodecs import JPEGXR, imread

if not JPEGXR.available:
    print("JPEG XR is not supported.")
    sys.exit()

jpeg_xr_fname = "./Windows_HDR_Capture/600.jxr"
image = imread(jpeg_xr_fname)
print(f"image.shape = {image.shape}")
print(f"image.dtype = {image.dtype}")
print(f"image[1080, 1920] = {image[1080, 1920]}")

実行結果は以下の通り。RGBA の half float 形式であることがわかる。

image.shape = (2160, 3840, 4)
image.dtype = float16
image[1080, 1920] = [4.914 4.91  4.914 1.   ]

上記のサンプルコードで使用した画像データも参考までに添付しておく。

drive.google.com

その他の情報

JPEG XR ファイルを開けるビューアソフト

  • Windows 11 標準の Photos App
  • Affinity Photo 2
    • ただし以下の手順が必要
      • Windowメニューから "32-bit Preview" を選択してメニューを表示する
      • "32-bit Preview" メニューの "Enable HDR" にチェックを入れる

参考資料

[1] GitHub, "cgohlke/imagecodecs", https://github.com/cgohlke/imagecodecs