猿问

如何编辑单个像素?

我决定只使用该方法提供给我的数组来制作一个图像编辑程序matplotlib.pyplot.imread,但是当我尝试将一个像素的内容分配给另一个像素时,它告诉我:can't assign to function call.


import matplotlib.pyplot as plt


f = plt.imread("GreenScreen.png")

x1 = 250

y1 = 350

x2 = 750

xCount = x2

xCount2 = xCount

xCountStart = x2

xSet = 0

for xCount in range(xCountStart, x1):

    xCount2 = (x1 + xCount) / 2

    xSet = xCount2

    for y1 in range(350, 360):

        for xCount2 in range(xSet, xCount):

            f(xCount2, y1) = f(xSet, y1)

            f(xCount2, y1) = f(xSet, y1)

            f(xCount2, y1) = f(xSet, y1)

            f(xCount2, y1) = f(xSet, y1)

        xCount2 = xSet

    y1 = 350


plt.imshow(f)

plt.show()


芜湖不芜
浏览 136回答 2
2回答

catspeake

将括号更改为用于索引()的方括号。[]像这样的东西应该工作:for xCount in range(xCountStart, x1):    xCount2 = (x1 + xCount) / 2    xSet = xCount2    for y1 in range(350, 360):        for xCount2 in range(xSet, xCount):            f[xCount2, y1] = f[xSet, y1]            f[xCount2, y1] = f[xSet, y1]            f[xCount2, y1] = f[xSet, y1]            f[xCount2, y1] = f[xSet, y1]        xCount2 = xSet    y1 = 350     ...

鸿蒙传说

f(xCount2, y1) = f(xSet, y1)f(xCount2, y1) = f(xSet, y1)f(xCount2, y1) = f(xSet, y1)f(xCount2, y1) = f(xSet, y1)要在 中设置字段f,请使用f[xCount2, y1]。括号用于调用函数,方括号用于索引。
随时随地看视频慕课网APP

相关分类

Python
我要回答