我制作了一个程序,它正在拍摄我上传的图像并将其划分为象限,以不同方式混淆每个图像中的颜色。我的问题是我无法看到这个部门正确。
import cImage as image
img = image.Image("/home/users/groth1/Downloads/selfie.JPG")
newimg = image.EmptyImage(img.getWidth(), img.getHeight())
win = image.ImageWin(title="Pic",width=img.getWidth(),height=img.getHeight())
for row in range(img.getHeight(0,186)): #Negative Q1
for col in range(img.getWidth(0,325)):
p = img.getPixel(col, row)
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
newpixel = image.Pixel(newred, newgreen, newblue)
img.setPixel(col, row, newpixel)
当我运行它时(使用介绍代码引入图像和所有这些)我得到一个错误,说“TypeError:getHeight()需要1个位置参数但是3个被给出” 那是什么意思?我该如何解决?
答案 0 :(得分:0)
该错误消息意味着函数cImage.Image.getHeight
和cImage.Image.getHeight
意味着在没有任何位置参数的情况下被调用。它们只返回图像的高度和宽度。通过传递0
,186
和325
,我无法理解您要实现的目标。以下是关于如何修复代码的想法:
xQuadrantBoundary = img.getWidth()//2
yQuadrantBoundary = img.getHeight()//2
for row in range(img.getHeight()): #Negative Q1
for col in range(img.getWidth()):
p = img.getPixel(col, row)
if row < yQuadrantBoundary:
if col < xQuadrantBoundary:
# Change this to what you want to happen to the colors in the upper left
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
elif col >= xQuadrantBoundary:
# Change this to what you want to happen to the colors in the upper right
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
elif row >= yQuadrantBoundary:
if col < xQuadrantBoundary:
# Change this to what you want to happen to the colors in the lower left
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
elif col >= xQuadrantBoundary:
# Change this to what you want to happen to the colors in the lower right
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
newpixel = image.Pixel(newred, newgreen, newblue)
img.setPixel(col, row, newpixel)