相关疑难解决方法(0)

使用PIL和NumPy将图像转换为Lab数组,修改值然后转换回来

我正在尝试使用NumPy将PIL图像转换为数组.然后,我想将该数组转换为Lab值,修改值,然后将数组转换回图像并保存图像.我有以下代码:

import Image, color, numpy

# Open the image file
src = Image.open("face-him.jpg")

# Attempt to ensure image is RGB
src = src.convert(mode="RGB")

# Create array of image using numpy
srcArray = numpy.asarray(src)

# Convert array from RGB into Lab
srcArray = color.rgb2lab(srcArray)

# Modify array here

# Convert array back into Lab
end = color.lab2rgb(srcArray)

# Create image from array
final = Image.fromarray(end, "RGB")

# Save
final.save("out.jpg")
Run Code Online (Sandbox Code Playgroud)

此代码取决于PIL,NumPy和颜色.颜色可以在SciPy主干中找到.我下载了color.py文件以及某些colordata .txt文件.我修改了color.py,以便它可以从SciPy的源独立运行,这一切似乎来做工精细-数组中值改变,当我运行转换.

我的问题是,当我运行上面的代码只是将图像转换为Lab,然后回到RGB并保存它我得到以下图像:

替代文字

出了什么问题?这是我使用color.py函数的事实吗? …

python numpy colors color-space python-imaging-library

14
推荐指数
2
解决办法
2万
查看次数

将十六进制值转换为python中的颜色名称

我的程序输出十六进制值,例如 (#673429ff)。
我想将其转换为颜色名称。我怎样才能得到颜色名称?我正在使用 python。这是我代码的最后一部分:

index_max = scipy.argmax(counts)                    # find most frequent
peak = codes[index_max]
colour = binascii.hexlify(bytearray(int(c) for c in peak)).decode('ascii')
print('most frequent is %s (#%s)' % (peak, colour))
Run Code Online (Sandbox Code Playgroud)

python rgb hex image image-processing

1
推荐指数
1
解决办法
4594
查看次数