我想从图像中渲染级别曲线,为此我只需要一个通道。当使用read_image
时,它会生成RGBRGBRGB,这与matplotlib
轮廓不兼容。从ImageInput
的文档来看,我应该能够执行以下操作:
pixels = numpy.zeros((spec.nchannels, spec.height, spec.width), "uint8")
for channel in range(spec.nchannels) :
pixels[channel] = file.read_image(0, 0, channel, channel + 1, "uint8")
字符串
由于我使用的是float
,我的代码现在看起来像这样:
import OpenImageIO as oiio
import matplotlib.pyplot
import numpy
inp = oiio.ImageInput.open('test.exr')
if inp:
spec = inp.spec()
xres = spec.width
yres = spec.height
nchannels = spec.nchannels
print(nchannels)
pixels = numpy.zeros((spec.nchannels, spec.height, spec.width), 'float')
for channel in range(spec.nchannels) :
pixels[channel] = inp.read_image(0, 0, channel, channel + 1, 'float')
inp.close()
matplotlib.pyplot.contour(pixels[0], extent = [0, 49152, 0, 49252])
matplotlib.pyplot.colorbar()
matplotlib.pyplot.show()
型
但这个例子似乎有bug:
Traceback (most recent call last):
File "/home/torbjorr/Dokument/terraformer/experiments/levelcurves.py", line 14, in <module>
pixels[channel] = inp.read_image(0, 0, channel, channel + 1, 'float')
ValueError: could not broadcast input array from shape (1024,1024,1) into shape (1024,1024)
型
在我的例子中正确的形状是(1024,1024)
。
1条答案
按热度按时间rkue9o1l1#
我找到解决办法了。似乎该文档中存在一个bug。下面是一个工作解决方案:
字符串