Skip to content

Instantly share code, notes, and snippets.

@robgon-art
Created April 3, 2022 17:44
Show Gist options
  • Save robgon-art/4b96a922cc23375a595ffbdc85bf7203 to your computer and use it in GitHub Desktop.
Save robgon-art/4b96a922cc23375a595ffbdc85bf7203 to your computer and use it in GitHub Desktop.
Generate texture for an image
from torchvision import transforms as T
import torch
texture_amount = 0.15
texture_size = 9
noise = torch.normal(0, texture_amount*texture_size**(1./3.),
size=[resized.shape[0], 1, resized.shape[2], resized.shape[3]]).to(device)
noise = noise.repeat(1, 3, 1, 1)
noise_blurred = T.GaussianBlur(kernel_size=texture_size, sigma=1)(noise)
noise_blurred = noise*0.25 + noise_blurred*0.75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment