import numpy as np
from scipy import signal
from opencv import adaptors
class scipyFromOpenCV(object):
"""This decorator can be used to wrap a function that takes
and returns a numpy array into one that takes and retuns an
opencv CvMat.
"""
def __init__(self, f):
self.f = f
def __call__(self, image):
# Convert CvMat to ndarray
np_image = adaptors.Ipl2NumPy(image)
# Call the original function
np_image_filtered = self.f(np_image)
# Convert back to CvMat
return adaptors.NumPy2Ipl(np_image_filtered)
@scipyFromOpenCV
def slowGaussianBlur(matrix):
"""Manual gaussian blur - Very very very slow!"""
filterSize = 3
filt = gauss_kern(filterSize)
r = signal.convolve(matrix[:,:,0],filt,'same')
g = signal.convolve(matrix[:,:,1],filt,'same')
b = signal.convolve(matrix[:,:,2],filt,'same')
result = array([r,b,g]).astype(uint8).transpose((1,2,0))
return result
I recently had cause to briefly look into Homomorphic Encryption , the process of carrying out computations on encrypted data. This technique allows for privacy preserving computation. Fully homomorphic encryption (FHE) allows both addition and multiplication, but is (currently) impractically slow. Partially homomorphic encryption just has to meet one of these criteria and can be much more efficient. An unintended, but well-known, malleability in the common RSA algorithm means that the multiplication of ciphertexts is equal to the multiplication of the original messages. So unpadded RSA is a partially homomorphic encryption system. RSA is beautiful in how simple it is. See wikipedia to see how to generate the public ( e , m ) and private keys ( d , m ). Given a message x it is encrypted with the public keys it to get the ciphertext C ( x ) with: C ( x ) = x e mod m To decrypt a ciphertext C ( x ) one applies the private key: m = C ( x ) d mod m The homomorphic prop...