Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python imaging library PIL-can';t将图像类型从L转换为F后更改像素值-AttributeError:';int';对象没有属性';数据';_Python Imaging Library - Fatal编程技术网

Python imaging library PIL-can';t将图像类型从L转换为F后更改像素值-AttributeError:';int';对象没有属性';数据';

Python imaging library PIL-can';t将图像类型从L转换为F后更改像素值-AttributeError:';int';对象没有属性';数据';,python-imaging-library,Python Imaging Library,我有一个“L”类型的图像,我将其转换为float“F”。在转换后尝试更改其像素值时出错。下面是一个片段 a = mnist_images[i].convert(mode="F") a = a.point(lambda j: 0) 以及错误消息 <ipython-input-45-f89cda3cf30e> in generate_moving_mnist(shape, seq_len, seqs, num_sz, nums_per_image) 86

我有一个
“L”
类型的图像,我将其转换为float
“F”
。在转换后尝试更改其像素值时出错。下面是一个片段

a = mnist_images[i].convert(mode="F")
a = a.point(lambda j: 0)
以及错误消息

<ipython-input-45-f89cda3cf30e> in generate_moving_mnist(shape, seq_len, seqs, num_sz, nums_per_image)
     86                 b=mnist_images[i].point(lambda j: 0)
     87                 a=mnist_images[i].convert(mode="F")#.point(lambda j: 0)
---> 88                 a = a.point(lambda j: 0)
     89 
     90                 # paste the mnist_images[i] at position[i] on the current canvas

~\anaconda3\envs\tf\lib\site-packages\PIL\Image.py in point(self, lut, mode)
   1572                 # UNDONE wiredfool -- I think this prevents us from ever doing
   1573                 # a gamma function point transform on > 8bit images.
-> 1574                 scale, offset = _getscaleoffset(lut)
   1575                 return self._new(self.im.point_transform(scale, offset))
   1576             # for other modes, convert the function to a table

~\anaconda3\envs\tf\lib\site-packages\PIL\Image.py in _getscaleoffset(expr)
    483 def _getscaleoffset(expr):
    484     stub = ["stub"]
--> 485     data = expr(_E(stub)).data
    486     try:
    487         (a, b, c) = data  # simplified syntax

AttributeError: 'int' object has no attribute 'data'
我目前正在使用一种变通方法,但我认为它相当缓慢

a=mnist_images[i].copy()
a=a.convert(mode="F")
  for row in range(a.size[0]):
    for col in range(a.size[1]):
      a.putpixel((row, col), new_pixel_value)

PIL/Image.py
的第1581行可以看出
point()
函数在类型
“F”
浮点图像上不受支持:

if self.mode == "F":
    # FIXME: _imaging returns a confusing error message for this case
    raise ValueError("point operation not supported for this mode")

如果您愿意说出您真正想做的事情,我可以建议一个解决方法。

谢谢,我也意识到了这一点。我目前正在使用变通方法(编辑我的帖子)。我将PIL图像复制到一个新图像中,然后在行和列之间循环。它不是有效的,但同时也足够了。我只是尝试对每个像素执行一些操作。如果您只是尝试将所有像素设置为单一纯色,则可以使用
Image.paste(newcolor)
我不会尝试将所有像素设置为单一颜色。这只是一个简短的例子。我正在对一个邻居进行计算。但这很好,我只需要对整个数据集运行一次。谢谢你。
if self.mode == "F":
    # FIXME: _imaging returns a confusing error message for this case
    raise ValueError("point operation not supported for this mode")