#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Oct 18 14:41:30 2017 @author: lena """ from rawkit.raw import Raw from rawkit.options import WhiteBalance from PIL import Image import numpy as np from scipy import misc import matplotlib.pyplot as plt import os # *** convert all images in folder or only specific one *** # convertFolder = bool(True) # *** path to data files *** # path = '../Data/' def convert(name): ''' Converts image file 'name' from raw format to .tiff ''' with Raw(filename=path + 'Raw/'+ name+'.CR2') as raw: raw.options.white_balance = WhiteBalance(camera=False, auto=True) raw.save(filename=path + name +'.tiff') # check if want to convert all images in folder or only specific one if(convertFolder): files = os.listdir('/home/lena/RHUL/Bachelor project/Data/Raw/') else: # *** specific image to convert *** # files = ['IMG_5985'] # convert raw image(s) for f in files: convert(f.split('.')[0]) # open image if not convertFolder: #im = Image.open('../Data/image2.tiff') #im.show() im = misc.imread(path + files[0] +'.tiff') plt.imshow(im) plt.show() # convert to numpy array (uint8) imarray = np.array(im) print(imarray.shape) print(im.size)