Esempio n. 1
0
# batch_recon = pyr.reconstruct(coeff,pyr_type=pyr_type)
# cv2.imshow('img_recon',(batch_recon[0].cpu().numpy()*255).astype(np.uint8))
# # # Visualization
# # coeff_single = utils.extract_from_batch(coeff, 0)
# # coeff_grid = utils.make_grid_coeff(coeff_single, normalize=True)
# # cv2.imshow('Complex Steerable Pyramid', coeff_grid)
# cv2.waitKey(0)




# Requires PyTorch with MKL when setting to 'cpu' 
device = torch.device('cpu')

# Load batch of images [N,1,H,W]
im_batch_numpy = utils.load_image_batch('./assets/lena.jpg',32,600)
img=cv2.imread('./assets/lena.jpg',0)
cv2.imshow('yuantu',img)
im_torch = torch.from_numpy(img).to(device)
im_batch_torch=im_torch.unsqueeze(0).unsqueeze(0).float()
# Initialize Complex Steerbale Pyramid
height = 12
nbands = 4
scale_factor = 2**(1/2)
pyr = SCFpyr_PyTorch(height=height, nbands=nbands, scale_factor=scale_factor, device=device)
pyr_type = 1

# Decompose entire batch of images 
coeff = pyr.build(im_batch_torch,pyr_type)

# Reconstruct batch of images again
Esempio n. 2
0
    ############################################################################
    # Build the complex steerable pyramid

    pyr = SCFpyr_PyTorch(height=config.pyr_nlevels,
                         nbands=config.pyr_nbands,
                         scale_factor=config.pyr_scale_factor,
                         device=device)

    ############################################################################
    # Create a batch and feed-forward

    start_time = time.time()

    # Load Batch
    im_batch_numpy = utils.load_image_batch(config.image_file,
                                            config.batch_size,
                                            config.image_size)
    im_batch_torch = torch.from_numpy(im_batch_numpy).to(device)

    # Compute Steerable Pyramid
    coeff = pyr.build(im_batch_torch)

    duration = time.time() - start_time
    print(
        'Finishing decomposing {batch_size} images in {duration:.1f} seconds.'.
        format(batch_size=config.batch_size, duration=duration))

    ############################################################################
    # Visualization

    # Just extract a single example from the batch