我正在一个项目上,该项目要求我使用类和对象使用PIL在Python中操纵图像。
我已经消除了格式化文件路径的正确方式,因此代码本身必须包含某些内容。
class image_play(object):
def __init__(self,im_name):
self.im_name = im_name
def rgb_to_gray_image(self):
im = Image.open(self.im_name)
im = im.convert('LA')
return im
# editing pixels of image to white
def loop_over_image(self):
im = Image.open(self.im_name)
width, height = im.size
# nested loop over all pixels of image
temp = []
for i in range(width):
for j in range(height):
temp.append((255,255,255)) # append tuple for the RGB values for each pixel
image_out = Image.new(im.mode,im.size) #create new image using PIl
image_out.putdata(temp) #use the temp list to create the image
return image_out
pic = image_play('test.png')
picGray = pic.rgb_to_gray_image()
picWhite = pic.loop_over_image()
答案 0 :(得分:0)
我只是添加了picGray.show()和picWhite.show(),现在有了可查看的输出。嗯...