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

postprocess.py 1.1 KB

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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  1. import numpy as np
  2. from PIL import Image
  3. from matplotlib import pyplot as plt
  4. import matplotlib.image as mpimg
  5. import cv2
  6. import imageio
  7. import os
  8. from os import listdir
  9. from os.path import isfile, join
  10. import argparse
  11. import shutil
  12. args = argparse.ArgumentParser()
  13. args.add_argument("-i", "--input", required=True, help= "absolute path to mask")
  14. args.add_argument("-e", "--expected", required=True, help= "absolute path to image")
  15. args.add_argument("-o", "--output", required=True, help="path to save image")
  16. args = vars(args.parse_args())
  17. masked_file=args["input"]
  18. original_file=args["expected"]
  19. outdir=args["output"]
  20. img_pred = cv2.imread(masked_file)
  21. row = img_pred.shape[0]
  22. col = img_pred.shape[1]
  23. img_exp = cv2.imread(original_file)
  24. new_img = np.ones(img_exp.shape)*255
  25. new_img=new_img.astype(np.uint8)
  26. for r in range(row):
  27. for c in range(col):
  28. if img_pred[r,c][0] == 0 and img_pred[r,c][1] == 0 and img_pred[r,c][2] == 0:
  29. new_img[r,c][0] = img_exp[r,c][0]
  30. new_img[r,c][1] = img_exp[r,c][1]
  31. new_img[r,c][2] = img_exp[r,c][2]
  32. newimg = masked_file+"_pos"
  33. imageio.imwrite(newimg, new_img, format="png")
  34. shutil.move(newimg,outdir)
Tip!

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

Comments

Loading...