Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

crappify.py 742 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  1. from fastai.vision import *
  2. from PIL import Image, ImageDraw, ImageFont
  3. class crappifier(object):
  4. def __init__(self, path_lr, path_hr):
  5. self.path_lr = path_lr
  6. self.path_hr = path_hr
  7. def __call__(self, fn, i):
  8. dest = self.path_lr/fn.relative_to(self.path_hr)
  9. dest.parent.mkdir(parents=True, exist_ok=True)
  10. img = PIL.Image.open(fn)
  11. targ_sz = resize_to(img, 96, use_min=True)
  12. img = img.resize(targ_sz, resample=PIL.Image.BILINEAR).convert('RGB')
  13. w,h = img.size
  14. q = random.randint(10,70)
  15. ImageDraw.Draw(img).text((random.randint(0,w//2),random.randint(0,h//2)), str(q), fill=(255,255,255))
  16. img.save(dest, quality=q)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...