jp4_batch_convert_singles.py 922 Bytes
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
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
#!/usr/bin/env python3

from jp4_composite import JP4_C
#import cv2
import numpy as np
import sys
from PIL import Image, ImageOps
import os

try:
  src = sys.argv[1]
except IndexError:
  src = "."

try:
  dst = sys.argv[2]
except IndexError:
  dst = "."

lst = os.listdir(src)
lst.sort()

for f in lst:

  path = os.path.join(src,f)
  if os.path.isfile(path):
    print("Converting "+f)
    img = JP4_C(path)
    #print(img.exif.toString())
    #print(img.exif.data['Model'])
    img.deblock()
    img.demosaic_bilinear()
    img_arr = img.saturation()
    im = Image.fromarray(img_arr.astype(np.uint8))
    im.save(os.path.join(dst,img.basename+"_"+str(img.subnames)+".jpeg"))

    #subs = img.extract_subframes()
    #for i in range(len(subs)):
      #subs[i].save(os.path.join("../res",img.basename+"_"+str(img.subnames[i])+".png"))
    #  subs[i].save(os.path.join(dst,img.basename+"_"+str(img.subnames[i])+".jpeg"))