IOGS - ARDF Projects - Dehazing

This file is a helper for browsing the dehazing data and saving it in numpy arrays

Imports

In [ ]:
import numpy as np
import os

from matplotlib.pyplot import imshow
from PIL import Image
%matplotlib inline

Get original data

Information on the NTIRE dehazing competition can be found:

Registration is required to access the images. This script save the images in numpy array. Another script contains the dataloader, to load the numpy arrays and prepare them to train learning algorithms.

In [ ]:
folder = "./data/dehazing/NN-HAZE_train/GT"

onlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]

print("Working with {0} images".format(len(onlyfiles)))
print("Image examples: ")

train_gt = []
for i in range(len(onlyfiles)):
#for i in range(40, 42):
    print(onlyfiles[i])
    pil_im = Image.open(folder + "/" + onlyfiles[i], 'r')
    #imshow(np.asarray(pil_im))
    #display(Image(filename=folder + "/" + onlyfiles[i], width=240, height=320))
    #pil_im.show() # open image outside of the notebook
    #print(pil_im.size)
    #width, height = pil_im.size
    
    np_im = np.array(pil_im)
    #np_im = np_im.reshape((3, width, height))
    train_gt.append(np_im)
    #print(np.size(np_im))

train_gt = np.array(train_gt)    
print(train_gt.size)

print('Saving train ground-truth data')
np.save('./data/dehazing/train_gt.npy', train_gt)
In [ ]:
folder = "./data/dehazing/NN-HAZE_train/HAZY"

onlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]

print("Working with {0} images".format(len(onlyfiles)))
print("Image examples: ")

train_hazy = []
for i in range(len(onlyfiles)):
#for i in range(40, 42):
    print(onlyfiles[i])
    pil_im = Image.open(folder + "/" + onlyfiles[i], 'r')
    #pil_im.show() # open image outside of the notebook
    #print(pil_im.size)
    
    np_im = np.array(pil_im)
    train_hazy.append(np_im)

train_hazy = np.array(train_hazy)    
print(train_hazy.size)

print('Saving train hazy data')
np.save('./data/dehazing/train_data.npy', train_hazy)
In [ ]:
folder = "./data/dehazing/NN-HAZE_val/HAZY"

onlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]

print("Working with {0} images".format(len(onlyfiles)))
print("Image examples: ")

val_hazy = []
for i in range(len(onlyfiles)):
#for i in range(40, 42):
    print(onlyfiles[i])
    pil_im = Image.open(folder + "/" + onlyfiles[i], 'r')
    #pil_im.show() # open image outside of the notebook
    print(pil_im.size)
    
    np_im = np.array(pil_im)
    val_hazy.append(np_im)

val_hazy = np.array(val_hazy)    
print(val_hazy.size)

print('Saving validation hazy data')
np.save('./data/dehazing/val_data.npy', val_hazy)