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

image.py 711 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
19
20
21
22
23
24
25
26
27
28
  1. import os
  2. import cv2
  3. import numpy
  4. def img_resize(current_dir,save_dir,size_x=300,size_y=300,):
  5. img_list = os.listdir(current_dir)
  6. if not os.path.exists(save_dir):
  7. os.mkdir(save_dir)
  8. #os.chdir(save_dir)
  9. for name in img_list:
  10. print(name)
  11. img = cv2.imread(os.path.join(current_dir,name),1)
  12. #cv2.imshow('',img)
  13. res = cv2.resize(img, dsize=(size_x, size_y), interpolation=cv2.INTER_CUBIC)
  14. ind = name.rfind('.')
  15. img_name,ext = name[:ind],name[ind+1:]
  16. if ext != 'jpg':
  17. name = img_name+'.jpg'
  18. cv2.imwrite(os.path.join(save_dir,name),res)
  19. img_resize('../../datasets/train/Brain/','../../datasets/train/Brains')
Tip!

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

Comments

Loading...