In [1]:
%matplotlib inline
import SimpleXMLRPCServer
import numpy as np
import matplotlib.pyplot as plt
import scipy.misc
class ImageMethods:
""" object containing all methods for image manipulation, callable by client """
def crop_image(self, image, left=.25, right=.25, top=.1, bottom=.1):
""" Crop the image by the specified percentage on each side; Call with the following parameters:
crop_image(image, left=.25, right=.25, top=.1, bottom=.1)"""
image = np.array(image)
scipy.misc.imsave('server_original_crop.jpg', im)
image_shape = image.shape
self.cropped = image[image_shape[0]*top:image_shape[0]*(1-bottom),image_shape[1]*left:image_shape[1]*(1-right)]
scipy.misc.imsave('server_processed_crop.jpg', self.cropped)
return self.cropped.tolist()
def flip_image(self, image, vertical=True, horizontal=False):
""" Flip the image vertically and/or horizontally. Call with the following parameters:
flip_image(image, vertical=True, horiontal=False"""
self.flipped = np.array(image)
scipy.misc.imsave('server_original_flip.jpg', im)
if vertical == True:
self.flipped = self.flipped[::-1]
if horizontal == True:
self.flipped = self.flipped[:,::-1,:]
scipy.misc.imsave('server_processed_flip.jpg', self.flipped)
return self.flipped.tolist()
def color_complement(self,im):
""" Inverts the color channels in the image, it subtracts each element of each channel from 255.
Call with the following parameters: color_complement(image)"""
im=np.array(im)
scipy.misc.imsave('OriginalServerSide.jpg', im)
self.imCI=255-im
scipy.misc.imsave('ChannelInversedServerSide.jpg', self.imCI)
self.imCI=self.imCI.tolist()
return self.imCI
host, port = "127.0.0.1", 8001
server = SimpleXMLRPCServer.SimpleXMLRPCServer((host, port), allow_none=True)
server.register_instance(ImageMethods())
server.register_multicall_functions()
server.register_introspection_functions()
print "XMLRPC Server is starting at:", host, port
server.serve_forever()