-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiftojpg.py
28 lines (23 loc) · 1.1 KB
/
tiftojpg.py
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
from PIL import Image
import os
from os import walk
from os import listdir
from os.path import isfile, join
yourpath = "D:/Javra/Research/ObjectDetectionTensorflowSharp/PngTOJpg/Image/tiffFolder"
outputdir = "D:/Javra/Research/ObjectDetectionTensorflowSharp/PngTOJpg/Image/jpgFolder/"
for root, dirs, files in os.walk(yourpath, topdown=False):
for name in files:
print(os.path.join(root, name))
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"):
print ("A jpeg file already exists for %s" % name)
# If a jpeg is *NOT* present, create one from the tiff.
else:
outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
try:
im = Image.open(os.path.join(root, name))
print ("Generating jpeg for %s" % name)
im.thumbnail(im.size)
im.save(outfile, "JPEG", quality=100)
except Exception as e:
print (e)