我有一个来自Image(PIL/Pillow)对象的numpy 3D数组.
[[178 214 235]
[180 215 236]
[180 215 235]
...,
[146 173 194]
[145 172 193]
[146 173 194]]
...,
[[126 171 203]
[125 169 203]
[128 171 205]
...,
[157 171 182]
[144 167 182]
[131 160 180]]]
Run Code Online (Sandbox Code Playgroud)
图像大小约为500x500像素.我需要为每个像素应用两个函数.
[157, 171, 182]并返回带有LAB颜色的1D数组,例如[53.798345635, -10.358443685, 100.358443685].scipy.spatial.cKDTree.自定义调色板是kd-tree.
palette = [[0,0,0], [127,127,127], [255,255,255]] # or [[0.,0.,0.], [50.,0.,0.], [100.,0.,0.]] for LAB color
tree = scipy.spatial.cKDTree(palette)
def find nearest(pixel):
distance, result …Run Code Online (Sandbox Code Playgroud)