skimage 颜色 space 转换将图像转换为静态
skimage color space conversions turn image to static
我正在使用 sci-kits 模块 skimage 将图像从 RGB 色彩空间转换为 LAB,然后再转换回来。我从这个问题中找到了以下功能:Convert an image RGB->Lab with python,但这并没有解决如何将图像减少为静态的问题。
代码:
file = 'C://Users/Alec/Pictures/25 zone test.png'
pix = numpy.array(PIL.Image.open(file))
print(pix[0,0])
pix = color.rgb2lab(pix)
print(pix[0,0])
pix = color.lab2rgb(pix)
print(pix[0,0])
pix *= 255
print(pix[0,0])
pix = pix.astype(int)
print(pix[0,0])
pic = PIL.Image.fromarray(pix, 'RGB')
pic.show()
输出:
[255 255 255]
[ 1.00000000e+02 -2.45493786e-03 4.65342115e-03]
[ 1. 1. 1.]
[ 255. 255. 255.]
[255 254 254]
打印语句的输出似乎或多或少是合适的,但是,生成的图像肯定不是。
我是否缺少一个步骤才能使其正常工作?
原图:
结果:
此往返转换返回原始图像(或非常接近的图像):
from skimage import io, color
import matplotlib.pyplot as plt
image = io.imread('/tmp/colors.png')
lab = color.rgb2lab(image)
rgb = color.lab2rgb(lab)
plt.imshow(rgb)
plt.show()
我正在使用 sci-kits 模块 skimage 将图像从 RGB 色彩空间转换为 LAB,然后再转换回来。我从这个问题中找到了以下功能:Convert an image RGB->Lab with python,但这并没有解决如何将图像减少为静态的问题。
代码:
file = 'C://Users/Alec/Pictures/25 zone test.png'
pix = numpy.array(PIL.Image.open(file))
print(pix[0,0])
pix = color.rgb2lab(pix)
print(pix[0,0])
pix = color.lab2rgb(pix)
print(pix[0,0])
pix *= 255
print(pix[0,0])
pix = pix.astype(int)
print(pix[0,0])
pic = PIL.Image.fromarray(pix, 'RGB')
pic.show()
输出:
[255 255 255]
[ 1.00000000e+02 -2.45493786e-03 4.65342115e-03]
[ 1. 1. 1.]
[ 255. 255. 255.]
[255 254 254]
打印语句的输出似乎或多或少是合适的,但是,生成的图像肯定不是。
我是否缺少一个步骤才能使其正常工作?
原图:
结果:
此往返转换返回原始图像(或非常接近的图像):
from skimage import io, color
import matplotlib.pyplot as plt
image = io.imread('/tmp/colors.png')
lab = color.rgb2lab(image)
rgb = color.lab2rgb(lab)
plt.imshow(rgb)
plt.show()