【问题标题】:skimage color space conversions turn image to staticskimage 颜色空间转换将图像转换为静态
【发布时间】:2017-11-29 15:40:47
【问题描述】:

我正在使用 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]

print 语句的输出似乎或多或少是合适的,但是生成的图像肯定不是。

有没有我遗漏的步骤才能正常工作?

原图:

结果:

【问题讨论】:

标签: python scikit-image


【解决方案1】:

这种往返转换让我恢复了原始图像(或非常接近的图像):

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()

【讨论】:

  • PIL 显示图像的方式一定有问题。用pyplot措辞!
  • 但是在你的代码中这个断言会失败:assert (image == rgb).all().
  • 是的,范围不同。以下将成功:np.allclose(util.img_as_float(image), util.img_as_float(rgb))
猜你喜欢
  • 2018-08-26
  • 2018-04-09
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
  • 2021-03-01
  • 2021-02-14
  • 2021-05-27
  • 1970-01-01
相关资源
最近更新 更多