In [38]:
%matplotlib inline
In [39]:
import cPickle as pickle
import numpy as np
import PIL
import json
In [40]:
received = None
with open('receivedImage.pkl', 'rb') as fin:
received = pickle.load(fin)
In [41]:
encoded = received['the_file'].split(',')
imgData = encoded[1]
ext = encoded[0].split('/')[1].split(';')[0]
# or, more concisely using with statement
with open("imageToSave." + ext, "wb") as fh:
fh.write(imgData.decode('base64'))
In [42]:
type(imgData.decode('base64'))
Out[42]:
In [43]:
import base64
import io
from matplotlib import pyplot as plt
import matplotlib.image as mpimg
i = base64.b64decode(imgData)
i = io.BytesIO(i)
i = mpimg.imread(i, format=ext)
plt.imshow(i, interpolation='nearest')
plt.show()
In [44]:
type(i)
Out[44]:
In [45]:
i.shape
Out[45]:
In [46]:
np.average(i)
Out[46]:
In [47]:
tmp = 'hello'
name = tmp if tmp else 'goodbye'
name
Out[47]:
In [48]:
from laserCAM import Project, Image, Engraving, Laser
In [ ]:
project = None
In [ ]:
project = Project(name='TestProject')
In [ ]:
image = Image(image_data=i, original_extension=ext)
In [ ]:
project.image = image
In [ ]:
print type(project.image.image_data)
In [ ]:
del image
In [ ]:
print type(project.image.image_data)
In [ ]:
In [ ]:
data = np.asarray([12, 240, 241, 242, 245, 250, 251, 253, 255])
data[data>=245] = 255
data
In [ ]:
np.where(data < 255)[0][0], np.where(data < 255)[0][-1], np.where(data < 255)[0]
In [ ]:
np.where(data[::-1] > 255)[0]
In [ ]:
In [ ]:
In [ ]:
from laserCAM import Project, Image, Preprocessor
In [ ]:
project = Project()
In [ ]:
image = Image(i)
In [ ]:
i.shape
In [ ]:
preproc = Preprocessor(ignore_white=True, split_white=False, white_cutoff=240)
In [ ]:
project.image = image
project.preprocessor = preproc
In [ ]:
project.generate_gcode()
In [ ]:
In [ ]:
plt.imshow(project.image.normalized_data[::-1], interpolation='nearest')
plt.show()
In [ ]:
[1,2,3,4,5,6][:-1]
In [ ]:
In [ ]:
j = np.zeros_like(a=project.image.normalized_data)
for rowNum, row in enumerate(project.preprocessor._terminators):
low, high = row
if low is not None:
j[rowNum, low] = 1.0
if high is not None:
j[rowNum, high] = 1.0
plt.imshow(j[::-1], interpolation='nearest')
plt.show()
In [ ]:
In [ ]:
direction = -1
1 - int(direction == True)
In [ ]:
In [ ]:
project.image
In [ ]:
project.image.normalize_image(255)
In [ ]:
project.image.normalized_data.shape
In [ ]:
project.image.normalized_data[0]
In [ ]:
i.shape
In [ ]:
tmp = i.copy()
In [ ]:
tmp = np.average(tmp, axis=-1)
In [ ]:
tmp.shape
In [ ]:
i[0]
In [ ]:
In [ ]:
In [ ]: