Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

numpy - Convert an image RGB->Lab with python

What is the preferred way of doing the conversion using PIL/Numpy/SciPy today?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since 2010 when the linked question was asked the corresponding code moved from scipy to a separate toolkit: http://scikit-image.org/

So here's the code I was actually looking for:

from skimage import io, color
rgb = io.imread(filename)
lab = color.rgb2lab(rgb)

It should also be noted that due to Lab nature srgb->lab conversion depends on an additional parameter: whitepoint, eg:
   ? Photoshop uses a white point called D50 (which is a standard for icc)
   ? OpenCV and skimage use D65 (which is a standard for srgb).
   ? default Matlab implementation uses D50 (it is capable of using others),

This nice FAQ explains it this way:

You should use D65 unless you have a good reason to use something else.
The print industry commonly uses D50 and photography commonly uses D55.
These represent compromises between the conditions of indoor (tungsten) and daylight viewing.

You can tell which whitepoint you're dealing with by converting RGB (0,0,255) to Lab:
   ? D50 would give you (30, 68, -112)
   ? D55                         (30, 73, -110)
   ? D65                         (32, 79, -108)

The numbers after 'D' correspond to (internally) used color temperature of white point: D50 = 5003 K (yellowish), D65 = 6504 K (blueish)

I'm grateful to Alex and Roman for their answers because they pointed me into the right direction.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...