Exemple #1
0
def transform_im(image, NUM_MVP = 20):
    rowid, colid = np.where( image <100)
    id2cs = np.random.choice(range(len(rowid)), NUM_MVP, replace=False)
    
    p = np.stack((rowid, colid)).transpose()
    p = p[id2cs]
    q = p + (20*(np.random.rand(p.shape[0], p.shape[1]) -0.5 ) ).astype(int)
    
    transformed_image = 255*mls_rigid_deformation_inv(image, p, q, alpha=1, density=1)

    if np.random.uniform()>0.5:
        transformed_image = affine_im(transformed_image, transpix=0.05*image.shape[0]*(np.random.uniform(size=[2])-0.5), angle=5*(np.random.uniform()-0.5))
    return binary(transformed_image)
Exemple #2
0
def demo():
    p = np.array([[30, 155], [125, 155], [225, 155], [100, 235], [160, 235],
                  [85, 295], [180, 293]])
    q = np.array([[42, 211], [125, 155], [235, 100], [80, 235], [140, 235],
                  [85, 295], [180, 295]])

    image = plt.imread('mr_big_ori.jpg')
    plt.subplot(121)
    plt.axis('off')
    plt.imshow(image)
    transformed_image = mls_rigid_deformation_inv(image, p, q)
    plt.subplot(122)
    plt.axis('off')
    plt.imshow(transformed_image)
    plt.tight_layout(w_pad=1.0, h_pad=1.0)
    plt.show()
        #print(count)       
		
                    
                #print(p.shape)
                #print(q.shape)
        #filename = './Users\Sony\Desktop\MSR\face morphing code\video frame extract\output' + "frame%d.jpg";count+=1
        #cv2.imwrite(filename, image)
        #cv2.imwrite(''+"framer%d.jpg" % countt,image)
        #cv2.imshow('frame',image)
        #count += 1
    #transformed_image = mls_rigid_deformation_inv(image, p, q, alpha=1, density=0.7)
       # cv2.imwrite("framesave/frame%d.jpg" % count, image)
        lstart=time.time()
        print('Preprocessing Time : ',(lstart-start))
        astart=time.time()
        transformed_image = mls_rigid_deformation_inv(image, p, q, alpha=1, density=1)
        end=time.time()
    # Display the resulting frame
        print('Frame processing Time : ',(end-astart))
        cv2.imwrite("frameM%d.jpg" % count, transformed_image)
        out.write(transformed_image)
		
	
        cv2.imshow('frame',transformed_image)
        print("success")
    if cv2.waitKey(60) & 0xFF == ord('q'):
        break
  


# When everything done, release the capture
    noise[:, [0,-1], :] = 0
    q = p + noise.reshape(size**2, 2)
    return p, q


if __name__ == "__main__":
    npzfile = np.load(all_img_lab_path)

    train_images = npzfile['train_images']

    height = train_images.shape[1]
    width = train_images.shape[2]

    plt.figure(figsize=(10, 10))
    plt.subplot(221)
    plt.axis('off')
    plt.imshow(train_images[0], cmap='gray')
    plt.title("Original image")
    
    for i in range(3):
        p, q = generate_ctrl_pts(height, width, size=5, range=20)
        rigid = mls_rigid_deformation_inv(train_images[0], p, q)
        plt.subplot(2, 2, i+2)
        plt.imshow(rigid, cmap='gray')
        plt.title("Generate rigid " + str(i + 1))
        plt.axis('off')
    plt.tight_layout(w_pad=1.0)

    plt.show()