Python数据复制器
我正在努力完成上述任务。我需要第一阶段的帮助。我试图让我的程序读入一个缓冲区,将其写入输出文件,然后重复这个过程,直到输入耗尽。我的代码在python中运行时不会返回任何错误,但它无法将ppm图像文件的头信息写入文本文件。我该怎么做Python数据复制器,python,image,image-processing,Python,Image,Image Processing,我正在努力完成上述任务。我需要第一阶段的帮助。我试图让我的程序读入一个缓冲区,将其写入输出文件,然后重复这个过程,直到输入耗尽。我的代码在python中运行时不会返回任何错误,但它无法将ppm图像文件的头信息写入文本文件。我该怎么做 class PPM(): def __init__(self, infile, outfile): self.infile=infile self.oufile=outfile #Read in data o
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")
def否定红色(自身):
对于范围(0,(len(自像素)),3)中的b:
余数=abs(255 self.color)为什么@user3204229有三个答案,每个答案都有一个向上投票?@CodyPiersall该用户还问了一个关于同一个家庭作业的问题-也许他们彼此认识?@PeterGibson我想你知道些什么。用户提供了大量的赏金;也许他是想获得所需的声誉,所以回答了很多次,他的朋友给了他更高的评价。可能是一起做作业。@CodyPerSall:可能是合并帐户。如果主持人将袜子木偶合并为一个,那么我们现在将它们视为一个。此后,投票也被取消。
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]
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))
self.type=splits[0]
self.columns=splits[1]
self.row=splits[2]
self.colour=splits[3]
self.pixels=splits[4:]