Python-3,我的程序不显示负片图像
Python-3, my program doesn't show a negative image
所以我需要按照我教科书上的功能,制作一个图像负片并显示负片图像。我已经尝试更改一些内容以复制以前的功能,看看这是否会改变任何东西,比如输入我想要负面的图像。它编译并运行良好,没有任何错误,只是没有显示我的负面形象,所以我不知道是什么问题。
from cImage import *
def negativePixel(oldPixel):
newRed = 255 - oldPixel.getRed()
newGreen = 255 - oldPixel.getGreen()
newBlue = 255 - oldPixel.getBlue()
newPixel = Pixel(newRed, newGreen, newBlue)
return newPixel`
def MakeNegative(imageFile):
oldImage = FileImage(imageFile)
width = oldImage.getWidth()
height = oldImage.getHeight()
myImageWindow = ImageWin("Negative Image", width * 2, height)
oldImage.draw(myImageWindow)
newIn = EmptyImage(width, height)
for row in range(height):
for col in range(width):
oldPixel = oldImage.getPixel(col, row)
newPixel = negativePixel(oldPixel)
newIn.setPixel(col, row, newPixel)
newIn.setPosition(width + 1, 0)
newIn.draw(myImageWindow)
myImageWindow.exitOnClick()
你的代码没有编译或者 运行 对我来说;我修复了一些问题 - 缩进、import image
(不是 cImage
)、不调用 MakeNegative()
、参数乱序等。这对我有用。我在 Ubuntu 18.04,Python 3.6.9,cImage-2.0.2,Pillow-7.2.0。
from image import *
def negativePixel(oldPixel):
newRed = 255 - oldPixel.getRed()
newGreen = 255 - oldPixel.getGreen()
newBlue = 255 - oldPixel.getBlue()
newPixel = Pixel(newRed, newGreen, newBlue)
return newPixel
def MakeNegative(imageFile):
oldImage = FileImage(imageFile)
width = oldImage.getWidth()
height = oldImage.getHeight()
myImageWindow = ImageWin(width * 2, height, "Negative Image")
oldImage.draw(myImageWindow)
newIn = EmptyImage(width, height)
for row in range(height):
for col in range(width):
oldPixel = oldImage.getPixel(col, row)
newPixel = negativePixel(oldPixel)
newIn.setPixel(col, row, newPixel)
newIn.setPosition(width + 1, 0)
newIn.draw(myImageWindow)
myImageWindow.exitOnClick()
MakeNegative('Lenna_test_image.png')
所以我需要按照我教科书上的功能,制作一个图像负片并显示负片图像。我已经尝试更改一些内容以复制以前的功能,看看这是否会改变任何东西,比如输入我想要负面的图像。它编译并运行良好,没有任何错误,只是没有显示我的负面形象,所以我不知道是什么问题。
from cImage import *
def negativePixel(oldPixel):
newRed = 255 - oldPixel.getRed()
newGreen = 255 - oldPixel.getGreen()
newBlue = 255 - oldPixel.getBlue()
newPixel = Pixel(newRed, newGreen, newBlue)
return newPixel`
def MakeNegative(imageFile):
oldImage = FileImage(imageFile)
width = oldImage.getWidth()
height = oldImage.getHeight()
myImageWindow = ImageWin("Negative Image", width * 2, height)
oldImage.draw(myImageWindow)
newIn = EmptyImage(width, height)
for row in range(height):
for col in range(width):
oldPixel = oldImage.getPixel(col, row)
newPixel = negativePixel(oldPixel)
newIn.setPixel(col, row, newPixel)
newIn.setPosition(width + 1, 0)
newIn.draw(myImageWindow)
myImageWindow.exitOnClick()
你的代码没有编译或者 运行 对我来说;我修复了一些问题 - 缩进、import image
(不是 cImage
)、不调用 MakeNegative()
、参数乱序等。这对我有用。我在 Ubuntu 18.04,Python 3.6.9,cImage-2.0.2,Pillow-7.2.0。
from image import *
def negativePixel(oldPixel):
newRed = 255 - oldPixel.getRed()
newGreen = 255 - oldPixel.getGreen()
newBlue = 255 - oldPixel.getBlue()
newPixel = Pixel(newRed, newGreen, newBlue)
return newPixel
def MakeNegative(imageFile):
oldImage = FileImage(imageFile)
width = oldImage.getWidth()
height = oldImage.getHeight()
myImageWindow = ImageWin(width * 2, height, "Negative Image")
oldImage.draw(myImageWindow)
newIn = EmptyImage(width, height)
for row in range(height):
for col in range(width):
oldPixel = oldImage.getPixel(col, row)
newPixel = negativePixel(oldPixel)
newIn.setPixel(col, row, newPixel)
newIn.setPosition(width + 1, 0)
newIn.draw(myImageWindow)
myImageWindow.exitOnClick()
MakeNegative('Lenna_test_image.png')