Created
April 18, 2016 06:11
-
-
Save morris821028/e3dc82f8582eb25450f31f5e9a06f8a9 to your computer and use it in GitHub Desktop.
Image Process - Generator Testdata - Online Judge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import Image | |
import codecs | |
sys.stdout = codecs.getwriter('utf8')(sys.stdout) | |
for infile in sys.argv[1:]: | |
try: | |
im = Image.open(infile) | |
width = im.size[0] | |
height = im.size[1] | |
pix = im.load() | |
print height, width | |
for i in range(height): | |
for j in range(width): | |
print pix[j, i][0], pix[j, i][1], pix[j, i][2], | |
except IOError: | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import Image | |
import codecs | |
sys.stdout = codecs.getwriter('utf8')(sys.stdout) | |
with open(sys.argv[1]) as fin: | |
height, width = [int(x) for x in next(fin).split()] | |
img = Image.new('RGBA', (width, height)) | |
array = [] | |
for line in fin: | |
array.append([int(x) for x in line.split()]) | |
pixels = img.load() | |
for i in range(height): | |
for j in range(width): | |
pixels[j, i] = (array[i][j*3], array[i][j*3+1], array[i][j*3+2], 255) | |
img.save('test.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment