Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python skimage在每个通道的实验室颜色空间中使用什么范围?_Python_Python 3.x_Scikit Learn_Scikit Image - Fatal编程技术网

Python skimage在每个通道的实验室颜色空间中使用什么范围?

Python skimage在每个通道的实验室颜色空间中使用什么范围?,python,python-3.x,scikit-learn,scikit-image,Python,Python 3.x,Scikit Learn,Scikit Image,当使用skimage.color.rgb2lab将图像从RGB转换到LAB时,我真的找不到文档,三个通道中的每个通道在skimage中都可以有哪个值范围。 我对下面代码的尝试表明,对于L频道,[-6952.277924.33]对于A频道,[-8700.717621.43]对于B频道,[-8700.717621.43]但在我看来,这既不像典型的LBA值([01100],[-170100],[-100150]),也不像人们在描述中看到的那样,数字的比率似乎也不相似,而且这些通常都是看起来很“奇怪”的

当使用
skimage.color.rgb2lab
将图像从RGB转换到LAB时,我真的找不到文档,三个通道中的每个通道在skimage中都可以有哪个值范围。 我对下面代码的尝试表明,对于
L
频道,
[-6952.277924.33]
对于
A
频道,
[-8700.717621.43]
对于
B
频道,
[-8700.717621.43]

但在我看来,这既不像典型的LBA值(
[01100]
[-170100]
[-100150]
),也不像人们在描述中看到的那样,数字的比率似乎也不相似,而且这些通常都是看起来很“奇怪”的范围,似乎根本没有标准化

那么,如果通过
skimage
转换,LBA图像的每个通道可以有什么值呢

(和/或下面我的错误在哪里?试着确定它们?)


好吧,您的第一个错误是使用纯Python循环而不是NumPy表达式,但这与主题无关请参阅下文,了解您试图实现的目标的更有效版本

第二个错误更为微妙,可能是scikit image新手最常见的错误。从版本0.16开始,scikit映像为不同的数据类型使用隐式数据范围,详细信息请参见
np.zeros
默认为浮点数据类型,因此上面的输入数组的浮点范围为0-255,比预期的0-1大得多,因此在实验室空间中的范围也同样大

通过将
imgs
声明更改为
imgs=np.zero((16777216,1,1,3),dtype=np.uint8),可以使用
numpy.uint8
值而不是浮点值查看实验室值的范围。但是,请在下面填写“NumPy way”的完整代码:

[2]中的
:将numpy作为np导入
在[3]中:colors=np.mgrid[0:256,0:256,0:256].aType(np.uint8)
在[4]:颜色。形状
Out[4]:(3,256,256,256)
在[6]中:all_rgb=np.转置(颜色)
在[7]:从脱脂进口颜色
在[8]中:all_lab=color.rgb2lab(all_rgb)
在[9]中:np.max(所有轴=(0,1,2))
Out[9]:数组([100,98.23305386,94.47812228])
在[10]中:np.min(所有实验室,轴=(0,1,2))
Out[10]:数组([0.,-86.18302974,-107.85730021])
为了说明数据范围问题,您可以看到在0-1中使用浮点输入会得到相同的结果:

[12]中的
:all_lab2=color.rgb2lab(all_rgb/255)
在[13]中:np.max(所有λlab2,轴=(0,1,2))
Out[13]:数组([100,98.23305386,94.47812228])
# WARN: can take a while to calculate
import numpy as np
from skimage.color import rgb2lab
import multiprocessing as mp

colors = [[r,g,b] for r in range(256) for g in range(256) for b in range(256)]

imgs = np.zeros((16777216,1,1,3))
for i, color in enumerate(colors):
    imgs[i,:,:] = color


labs = np.zeros((16777216,1,1,3))
pool = mp.Pool(mp.cpu_count()-1)
try:
    labs = pool.map(rgb2lab, imgs)
except KeyboardInterrupt:
    # without catching this here we will never be able to manually stop running in a sane way
    pool.terminate()
pool.close()
pool.join()

print(np.min(labs[:,:,:,0]), np.max(labs[:,:,:,0]), np.min(labs[:,:,:,1]), np.max(labs[:,:,:,1]), np.min(labs[:,:,:,2]), np.max(labs[:,:,:,2]))

# 0.0 9341.570221995466 -6952.27373084052 7924.333617630548 -8700.709143439595 7621.42813486568