In [2]:
import numpy as np
import PIL
import cv2
import matplotlib.pyplot as plt
from dmdlib.ALP import *
%matplotlib inline

In [3]:
dmd = np.array(disp_affine_pattern(), dtype='float32')


Device image size is 1024 x 768.
set PROJ_MODE: master 0
(1, 768, 1024)
Press Enter key to end...

In [ ]:


In [4]:
# displays right to left on the camera image.

# dmd = np.array(([450, 300], [550, 275], [500, 430]), dtype='float32')
pic = np.array([[1321, 791],[1092, 433], [802, 1040]], dtype='float32')
# pic = np.fliplr(pic)
# pic = np.flipud(pic)

In [5]:
print(pic)


[[ 1321.   791.]
 [ 1092.   433.]
 [  802.  1040.]]

In [6]:
pic_to_dmd = cv2.getAffineTransform(pic, dmd)

In [7]:
from PIL import Image, ImageFont
import numpy as np
import numba

font = ImageFont.load_default()

def make_text_fast(text, array, margins=(10, 10, 150, 150),):
    height, width = array.shape
    mask = font.getmask(text)
    mask_array = np.asarray(mask, dtype=bool)
    mask_array.shape = mask.size[1], mask.size[0]
    top, bottom, left, right = margins
    _array_maker(array, mask_array, top, bottom, left, right, width, height)
    return array

# @numba.jit(nopython=True, parallel=True)
def _array_maker(arrayout, arrayin, top, bottom, left, right, width, height):
    W_margins = width - right - left
    H_margins = height - top - bottom
    mH, mW = arrayin.shape
    W_scale = np.ceil(W_margins / mW)
    H_scale = np.ceil(H_margins / mH)

    for x in range(W_margins):
        x_mask = int(x // W_scale)
        for y in range(H_margins):
            y_mask = int(y // H_scale)
            maskv = arrayin[y_mask, x_mask]
            arrayout[y+top, x+left] = maskv
    return

In [8]:
cam_w = 2048
cam_h = 1536
cam_arr = np.zeros((cam_h, cam_w), dtype='float32')
txtbitmap = make_text_fast('hello', cam_arr, margins=(500,500,500,500))

In [86]:
plt.imshow(txtbitmap)


Out[86]:
<matplotlib.image.AxesImage at 0x21f96e15668>

In [9]:
# dmd_arr = np.zeros_like(cam_arr)
dmd_arr = cv2.warpAffine(cam_arr, pic_to_dmd, (1024,768))
dmd_arr *= 255

In [88]:
plt.imshow(dmd_arr)


Out[88]:
<matplotlib.image.AxesImage at 0x21f96eaff60>

In [89]:
disp_image_pattern(dmd_arr.astype('uint8'))


Device image size is 1024 x 768.
set PROJ_MODE: master 0
Press Enter key to end...

In [1]:
pic_to_dmd


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-a1428fa66f98> in <module>()
----> 1 pic_to_dmd

NameError: name 'pic_to_dmd' is not defined

In [10]:
import pickle

In [11]:
forsave = {'camera_points': pic, 'dmd_points': dmd, 'cam_to_dmd': pic_to_dmd}

In [14]:
with open('d:/patters/mouse_11101/transform.pickle', 'wb') as f:
    pickle.dump(forsave, f)

In [36]:
with open('transform.pickle', 'rb') as f2:
    a = pickle.load(f2)

In [39]:
pwd


Out[39]:
'C:\\Users\\labadmin\\Dropbox\\PycharmProjects_ephys\\DmdLib\\testing'

In [41]:
ls


 Volume in drive C is BOOT
 Volume Serial Number is 469D-0D27

 Directory of C:\Users\labadmin\Dropbox\PycharmProjects_ephys\DmdLib\testing

09/15/2017  04:14 PM    <DIR>          .
09/15/2017  04:14 PM    <DIR>          ..
09/15/2017  10:35 AM    <DIR>          .ipynb_checkpoints
09/11/2017  05:00 PM    <DIR>          __pycache__
09/13/2017  11:14 AM            12,917 dmd upload basics.ipynb
09/11/2017  10:45 AM             3,809 dmd upload loop.ipynb
09/15/2017  04:14 PM            20,282 image to dmd transform.ipynb
09/11/2017  10:23 AM            24,684 number image generator.ipynb
09/13/2017  09:00 AM             1,428 progress.ipynb
09/14/2017  09:58 AM            47,547 rand performance testing.ipynb
09/11/2017  04:59 PM             2,704 test_imgen.py
09/11/2017  10:06 AM             2,129 test_imgen.pyc
09/15/2017  04:05 PM               431 transform.json
09/11/2017  10:45 AM             1,410 tt.ipynb
09/11/2017  01:39 PM               582 Untitled.ipynb
09/14/2017  09:47 AM             7,285 Untitled1.ipynb
09/14/2017  10:20 AM               677 Untitled2.ipynb
09/15/2017  02:58 PM             5,566 Untitled3.ipynb
              14 File(s)        131,451 bytes
               4 Dir(s)  28,337,315,840 bytes free

In [ ]: