Exemple #1
0
def scramble_blocks(mat_in,block_height,block_width, key):
 dim=numpy.shape(mat_in)
 #print(dim)
 blocks_vert=scipy.uint8((dim[0])/block_height) #number of rows of blocks 
 blocks_hor=scipy.uint8((dim[1])/block_width) #number of columns of blocks
 #key is divided in two parts.
 #the most significant digits determine th shift in the rows, and the least significant digits determine shift in rows
 key_sr=scipy.floor(key/10000) #rows shifted_by key_sr
 key_sc=key-(key_sr*10000)
 matrix_of_matrices=numpy.zeros((blocks_vert,blocks_hor,block_height,block_width))
 matrix_of_matrices2=numpy.zeros((blocks_vert,blocks_hor,block_height,block_width))
 matrix_buf=numpy.zeros(dim)
 matrix_out=numpy.zeros(dim)
 for i in range (blocks_vert):
  for j in range (blocks_hor):
   matrix_of_matrices[int((i+j*key_sc)%blocks_vert),int((j+key_sr)%blocks_hor),:,:]=mat_in[i*block_height:int((i+1)*block_height),j*block_width:int((j+1)*block_width)]
 for i in range (blocks_vert):
  for j in range (blocks_hor):
   matrix_buf[i*block_height:(i+1)*block_height, j*block_width:(j+1)*block_width]=matrix_of_matrices[i,j,:,:]
 for j in range (blocks_hor):
  for i in range (blocks_vert):
   matrix_of_matrices2[int((i+key_sc)%blocks_vert),int((j+i*key_sr+7)%blocks_hor),:,:]=matrix_buf[i*block_height:int((i+1)*block_height),j*block_width:int((j+1)*block_width)]
 for i in range (blocks_vert):
  for j in range (blocks_hor):
   matrix_out[i*block_height:(i+1)*block_height, j*block_width:(j+1)*block_width]=matrix_of_matrices2[i,j,:,:]
 return matrix_out
Exemple #2
0
def test_compare_two(placer):
    tile = scipy.array(Image.open("./eye.jpg"))
    tile = resize_chunk(target, placer.compareChunkSize)
    cand = scipy.array(Image.open("./imgs0/img_0gxHKNvoka.jpg"))
    ID, best_pos, bestCorr = placer.compare(tile, [cand])
    idx = best_pos
    
    result = scipy.zeros(cand.shape)
    result[idx[0]:idx[0]+50, idx[1]:idx[1]+50] = tile
    Image.fromarray(scipy.uint8(result)).show()
    Image.fromarray(scipy.uint8(cand)).show()
def filtro(P,vec):
    if P==1:
        filtromediana = scipy.ones((3, 3)) / 9
        filtromediana = scipy.signal.convolve2d(vec, filtromediana, mode='same')
        filtro = scipy.uint8(filtromediana)
    ####GAUSSIANO#####
    else:
        filtro = scipy.ndimage.gaussian_filter(vec, 2)
    return filtro
Exemple #4
0
def test_img_reconstr(placer):
    img_obj = Image.open("Matilda.JPG")
    img = scipy.array(img_obj)
    img_obj.show()
    
    data = placer.pack(img, 0)
    img_r = placer.unpack(data, img.shape)
    img_recon = Image.fromarray(scipy.uint8(img_r))
    img_recon.show()
Exemple #5
0
def test_compare_many(placer, target_fn, cnt):
    target = scipy.array(Image.open(target_fn))
    resizedTarget = resize_chunk(target, placer.compareChunkSize)
    
    cand_names = os.listdir("./imgs0/")
    cands = []
    for i in range(cnt):
        cands.append(scipy.array(Image.open("./imgs0/" + cand_names[i])))
        if (cands[i].ndim == 2):
            csh = cands[i].shape
            cands[i] = scipy.reshape(cands[i], (csh[0], csh[1], 1))
    resizedCands = placer.resizeTiles(scipy.array(cands))
    ID, best_pos, bestCorr = placer.compare(resizedTarget, resizedCands)
    cand = cands[ID]
    idx = best_pos
    
    result = scipy.zeros((75,75,3))
    result[idx[0]:idx[0]+50, idx[1]:idx[1]+50] = target
    Image.fromarray(scipy.uint8(result)).show()
    Image.fromarray(scipy.uint8(cand)).show()
Exemple #6
0
    use_cam = True

    if use_cam:
        box=(rect[0]+5, rect[1]+5, rect[2]-5,rect[3]-5) # contract region to avoid including border
        cap = cv2.VideoCapture(0)

        while True:
            ret,camimg = cap.read()
            cv2.rectangle(camimg,(rect[0],rect[1]),(rect[2],rect[3]),(0,255,0),1)
            cv2.imshow('video',camimg)

            key = cv2.waitKey(10)
            if key == 27:       # esc key
                exit()
            if ord('a')<=key<=ord('z') or key==ord(' '):   #press any key to take image
                camimg = Image.fromarray(uint8(camimg)).convert('L')
                print camimg
                camimg = camimg.crop(box)
                camimg=array(camimg)
                break

        cap.release()
        cv2.destroyAllWindows()

    else:
        camimg = Image.open("jakie.jpg") # open colour image
        camimg = Image.fromarray(uint8(camimg)).convert('L') # convert image to monochrome - this works
        camimg=array(camimg)
        box=(0,0,len(camimg[0]), len(camimg))

 def genImage(self):
     self.img=Image.fromarray(scp.uint8(self.terrain))
Exemple #8
0
    use_cam = True

    if use_cam:
        box=(rect[0]+5, rect[1]+5, rect[2]-5,rect[3]-5) # contract region to avoid including border
        cap = cv2.VideoCapture(0)

        while True:
            ret,camimg = cap.read()
            cv2.rectangle(camimg,(rect[0],rect[1]),(rect[2],rect[3]),(0,255,0),1)
            cv2.imshow('video',camimg)

            key = cv2.waitKey(10)
            if key == 27:       # esc key
                break
            if ord('a')<=key<=ord('z') or key==ord(' '):   #press any key to take image
                camimg = Image.fromarray(uint8(camimg)).convert('L')
                camimg = camimg.crop(box)
                camimg=array(camimg)
                break

        cap.release()
        cv2.destroyAllWindows()

    else:
        camimg = Image.open("jake.jpg") # open colour image
        camimg = Image.fromarray(uint8(camimg)).convert('L') # convert image to monochrome - this works
        camimg=array(camimg)
        box=(0,0,len(camimg[0]), len(camimg))


    edges = camimg
Exemple #9
0
        box = (rect[0] + 5, rect[1] + 5, rect[2] - 5, rect[3] - 5
               )  # contract region to avoid including border
        cap = cv2.VideoCapture(0)

        while True:
            ret, camimg = cap.read()
            cv2.rectangle(camimg, (rect[0], rect[1]), (rect[2], rect[3]),
                          (0, 255, 0), 1)
            cv2.imshow('video', camimg)

            key = cv2.waitKey(10)
            if key == 27:  # esc key
                exit()
            if ord('a') <= key <= ord('z') or key == ord(
                    ' '):  #press any key to take image
                camimg = Image.fromarray(uint8(camimg)).convert('L')
                print camimg
                camimg = camimg.crop(box)
                camimg = array(camimg)
                break

        cap.release()
        cv2.destroyAllWindows()

    else:
        camimg = Image.open("jakie.jpg")  # open colour image
        camimg = Image.fromarray(uint8(camimg)).convert(
            'L')  # convert image to monochrome - this works
        camimg = array(camimg)
        box = (0, 0, len(camimg[0]), len(camimg))