11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonのCIE DE2000計算速度比較

Posted at

みんな大好き速度比較

色差式CIE DE2000は、人間の知覚にかなり近い値を得られるが、そのかわり計算が重い。Pythonですぐに使えるパッケージ3つの速度を比較してみた。

sRGBの[32,32,32]と[32,31,32]を比較する。3つとも色差関数が引数に取るのはLabなので、計算時間にはsRGB→Labの変換も含む。

import numpy as np
import timeit

RGB1 = np.array([32,32,32],np.uint8)
RGB2 = np.array([32,31,32],np.uint8)

from skimage import color
def skimage_rgb2lab(rgb):
	return color.rgb2lab(rgb.reshape(1,1,3))
ski = timeit.timeit('color.deltaE_ciede2000(skimage_rgb2lab(RGB1), skimage_rgb2lab(RGB2))', globals=globals(), number=1000)
print(f'skimage.color: {ski} millisecond.')

from colormath.color_diff import delta_e_cie2000 as cm_delta_e_cie2000
from colormath.color_objects import sRGBColor as cm_sRGBColor, LabColor as cm_LabColor
from colormath.color_conversions import convert_color as cm_convert_color
def colormath_rgb2lab(rgb):
	return cm_convert_color(cm_sRGBColor(*(rgb / 255)), cm_LabColor, target_illuminant='d65')

cm = timeit.timeit('cm_delta_e_cie2000(colormath_rgb2lab(RGB1), colormath_rgb2lab(RGB2))', globals=globals(), number=1000)
print(f'colormath: {cm} millisecond.')

import colour as cs
cs_d65 = cs.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
def cs_rgb2lab(rgb):
	return cs.XYZ_to_Lab(cs.sRGB_to_XYZ(rgb / 255, chromatic_adaptation_method='Bradford', illuminant=cs_d65), illuminant=cs_d65)

colour_science = timeit.timeit('cs.difference.delta_E_CIE2000(cs_rgb2lab(RGB1), cs_rgb2lab(RGB2))', globals=globals(), number=1000)
print(colour-science: {colour_science} millisecond.')

結果

skimage.color: 0.306773 millisecond.
colormath: 0.29326620000000014 millisecond.
colour-science: 0.5313292000000001 millisecond.

わずかにcolormathが勝ったが、Numpy前提ではないパッケージなので、画像データだとscikit-imageが逆転すると思う。colour-scienceはCIECAM02に対応していたりと多機能なので、速度はダメらしい。

11
4
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
11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?