add image array code generator
This commit is contained in:
parent
f2aef6201a
commit
be9d6091d1
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
|
@ -0,0 +1,47 @@
|
|||
from PIL import Image
|
||||
import math
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog = 'Image Edit Script',
|
||||
description = 'Manipulate or extract information from an image file',
|
||||
epilog = '')
|
||||
|
||||
parser.add_argument('filename') # positional argument
|
||||
parser.add_argument('-o', '--output') # option that takes a value
|
||||
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
|
||||
|
||||
args = parser.parse_args()
|
||||
print(args.filename, args.output, args.verbose)
|
||||
|
||||
|
||||
im = Image.open(args.filename) # Can be many different formats.
|
||||
pix = im.load()
|
||||
print(im.size) # Get the width and hight of the image for iterating over
|
||||
print(pix[10,10]) # Get the RGBA Value of the a pixel of an image
|
||||
|
||||
|
||||
|
||||
def calculateDistance(x1,y1,x2,y2):
|
||||
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
|
||||
return dist
|
||||
|
||||
with open('result.txt', 'w') as f:
|
||||
for x in range(im.size[0]):
|
||||
f.write("backBuffer[")
|
||||
f.write(str(x))
|
||||
f.write("]=0b")
|
||||
for y in range(im.size[1]):
|
||||
c = pix[x,y] #get pixel
|
||||
if (c[0]>127):
|
||||
f.write("1")
|
||||
else:
|
||||
f.write("0")
|
||||
|
||||
|
||||
f.write(";")
|
||||
f.write('\r\n')
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Loading…
Reference in New Issue