util.py
'''
File: util.py
-------------
This file holds all the helper methods that
students can use for assn3
'''
import numpy as np
import matplotlib.pyplot as plt
# Define a few global variables
image_x = 32 # width of image
image_y = 32 # height of image
patch_dim = 8 # height/width of a patch
# Function: Load Train Images
# ---------------------
# Loads all *training* images from the dataset
# and returns them in a python list
def loadTrainImages():
return image_list
# Function: Load Test Images
# --------------------------
# Loads all *testing* images from the dataset
# and returns them in a python list
def loadTestImages():
return image_list
# Function: View Patches
# ----------------------
# Pass in a list of patches (or centroids)
# in order to view them as images.
def viewPatches(patches):
class Image(object):
# Constructor
# -----------
# Takes image related data, called on image
# creation.
def __init__(self,data,label,patches):
self.label = label # image label
self.patches = patches.transpose().tolist()
self.__img_data = data
# Function: View
# --------------
# Call function to view RGB image
def view(self):
# Function: Label
# ---------------
# Returns label of image
def getLabel(self):
# Function: Patches
# -----------------
# Returns list of patch vectors. Each patch
# length patch_size
def getPatches(self):