#!/usr/bin/env python
# coding: utf-8

# In[1]:


import time, os, sys, datetime, platform, logging, shutil, re
import numpy as np
import cv2
from multiprocessing import Pool


# In[2]:


in_dir = "Vechta/p_12_img/"
out_dir = "Vechta/p_13_img/"


# In[20]:


def png_to_tif(fn_in):
    data_in = cv2.imread(os.path.join(in_dir, fn_in), cv2.IMREAD_ANYDEPTH + cv2.IMREAD_COLOR)
    fn_out = fn_in[:-3]+'tif'
    if cv2.imwrite(os.path.join(out_dir, fn_out), data_in):
#        for fn in [temp_fn_1, temp_fn_2, temp_fn_3]:
#            os.remove(fn)
        return True
    return False


# In[30]:


to_process = [fn for fn in os.listdir(in_dir) if fn.endswith(".png")]


# In[ ]:


if __name__ == '__main__':
    start = time.time()
    with Pool(processes=4) as pool:
        results = pool.map(png_to_tif, to_process)
        print(results)
    print(time.time()-start, "seconds")
    # for a,b,c,d,e in func_args:
    #     if a > 5:
    #         break
    #     print(a,b,c,d,e)
        #print(raw_to_8bit(img_counter=ctr, filename_raw=raw_f_name, dir_temp_files=temp_dir, dir_img_out=out_dir_img, png_header=correct_header))


# In[ ]:




