我正在做一个项目,在这个项目中,我需要使用类和对象来使用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()发布于 2019-05-28 03:16:09
我只是简单地添加了picGray.show()和picWhite.show(),现在我有了可查看的输出。嗯..。
https://stackoverflow.com/questions/56331199
复制相似问题