0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでOpenImageIO(OIIO)を使ってlinearな色空間をsRGBに変換する

Last updated at Posted at 2025-04-09

自己紹介

株式会社digitalbigmoのパイプラインエンジニアの小池@plinecomです。

これは何?

OpenEXRを単純にJPEGにすると暗くなってしまうことがある。大体の場合、OpenEXRがLinearでJPEGがsRGBを要求するからだ。その辺をいい感じにしてくれる関数がOpenImageIOにあるので、使い方を記録する。

とりあえず、コード

main.py
import OpenImageIO as oiio
import glob

if __name__ == '__main__':

    for path in glob.glob('/foo/bar/*.exr'):
        print(path)
        jpg_path = path.replace('.exr', '.jpg')

        #Read File
        buf = oiio.ImageBuf(path)

        #Convert ColorSpace
        dst = oiio.ImageBufAlgo.colorconvert(buf, "linear", "sRGB")

        #Write File
        dst.write(jpg_path)

必要なPython外部モジュール

  • OpenImageIO
  • NumPy

Dockerfileも用意した。

Dockerfile
FROM rockylinux:8
RUN dnf install -y which python3 epel-release
RUN dnf config-manager --set-enabled powertools
RUN dnf install -y python3-openimageio python3-numpy
terminal
docker pull plinecom/py_oiio

コードの説明

色空間の変換方法の指示

        #Convert ColorSpace
        dst = oiio.ImageBufAlgo.colorconvert(buf, "linear", "sRGB")

とても単純にlinearをsRGBに変換している。

宣伝

株式会社digitalbigmoでは美肌プラグインの販売や映像VFXの制作業務を行なっています。ご興味のある方は、webページを見にきてください。一緒にお仕事しましょう。

参考文献

OpenImageIO本家(英語)
OpenImageIO本家リファレンス(英語)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?