Python数据复制器

时间:2014-01-09 02:20:29

标签: python image image-processing

http://nifty.stanford.edu/2012/guerin-image-editor/我正在努力完成上述任务。我需要第1阶段的帮助。我试图让我的程序读入一个缓冲区,将其写入输出文件,然后重复该过程,直到输入用完为止。在python中运行时,我的代码不会返回任何错误,但它无法将ppm图像文件的标题信息写入文本文件。我该怎么办?

class PPM():
    def __init__(self, infile, outfile):
        self.infile=infile
        self.oufile=outfile

        #Read in data of image
        data= open(self.infile,"r")
        datain=data.read()
        splits=datain.split()

        #Header info
        self.type=splits[0]
        self.columns=splits[1]
        self.row=splits[2]
        self.colour=splits[3]
        self.pixels=splits[:4]

    def writeOut(self):
        dataout=open(self.outfile, "w")



sample= PPM("cake.ppm", "Replica.ppm")

3 个答案:

答案 0 :(得分:0)

    else:
        temp_list = []
        for b in range(int(self.row)):
            column_list = []
            column_list += self.pixels[0:int(self.columns) * 3]
            self.pixels = self.pixels[int(self.columns) * 3 : ]
            temp_list.append(column_list)
        #print temp_list
        new_list = []
        for i in range(int(len(temp_list))):
            new_list.append (temp_list[i][0])
            new_list.append (temp_list[i][1])
            new_list.append (temp_list[i][2])
            temp_list[i] = temp_list[i][::-1]

答案 1 :(得分:0)

def writetofile(self):
        dataout= open(self.outfile,"w")
        dataout.write(self.type +"\n" + self.columns + "\n" + self.row +"\n"+ self.colour +"\n"+ " ".join (self.pixels))def writetofile(self):
        dataout= open(self.outfile,"w")
        dataout.write(self.type +"\n" + self.columns + "\n" + self.row +"\n"+ self.colour +"\n"+ " ".join (self.pixels))

答案 2 :(得分:0)

self.type=splits[0]
self.columns=splits[1]
self.row=splits[2]
self.colour=splits[3]
self.pixels=splits[4:]

def negate_red(self):     对于范围内的b(0,(len(self.pixels)),3):         余数= ABS(255-self.colour)