In [1]:
!pip install six pypng pillow


Requirement already satisfied: six in /usr/lib/python2.7/site-packages (1.11.0)
Requirement already satisfied: pypng in /usr/lib/python2.7/site-packages (0.0.18)
Requirement already satisfied: pillow in /usr/lib64/python2.7/site-packages (5.3.0)

In [2]:
import PIL
from PIL import Image
from PIL import ImageFilter, ImageEnhance
import numpy as np
import matplotlib.pyplot as plt
import six
from six.moves import cPickle as pickle
import png
import os

In [3]:
def extractImagesAndLabels(path, file):
    f = open(path+file, 'rb')
    dict = pickle.load(f)
    images = dict['data']
    print (images.shape)
    labels = dict['labels']
    return images, labels, dict

images, labels, datadict = extractImagesAndLabels("data/CIFAR-10/cifar-10-batches-py/", "test_batch")

def extractCategories(path, file):
    f = open(path+file, 'rb')
    dict = pickle.load(f)
    return dict['label_names']

categories = extractCategories("data/CIFAR-10/cifar-10-batches-py/", "batches.meta")

def getImage(images, id):
    image = images[id]
    image = image.transpose([1, 2, 0])
    image = image.astype('float32')
    image /= 255
    return image

def showImage(id):
    image = getImage(images,id)
    %matplotlib inline
    imgplot = plt.imshow(image)
    labelid = labels[id]
    category = categories[labelid]
    print("category : "+category)


(10000, 3072)

In [10]:
#Get data from cifar dataset, convert to a png
png.from_array(images[6].reshape((32, 32, 3), order='F').swapaxes(0,1), mode='RGB').save('tmp.png')
img = Image.open( 'tmp.png' )
img.load()

#resize image
dim = 100
img = img.resize((dim, dim), Image.ANTIALIAS)

%matplotlib inline
imgplot = plt.imshow(img)



In [11]:
#img = img.filter( ImageFilter.SHARPEN )
#%matplotlib inline
#imgplot = plt.imshow(img)

In [12]:
img = img.filter( ImageFilter.EDGE_ENHANCE_MORE )
%matplotlib inline
imgplot = plt.imshow(img)



In [ ]: