示例#1
0
def displayData(X):
    print "Visualizing"
    m, n = X.shape
    width = round(sqrt(n))
    height = width
    display_rows = int(floor(sqrt(m)))
    display_cols = int(ceil(m/display_rows))

    print "Cell width:", width
    print "Cell height:", height    
    print "Display rows:", display_rows
    print "Display columns:", display_cols
        
    display = zeros((display_rows*height,display_cols*width))

    # Iterate through the training sets, reshape each one and populate
    # the display matrix with the letter matrixes.    
    for xrow in range(0, m):
        rowindex = divide(xrow, display_cols)
        columnindex = remainder(xrow, display_cols)
        rowstart = int(rowindex*height)
        rowend = int((rowindex+1)*height)
        colstart = int(columnindex*width)
        colend = int((columnindex+1)*width)
        display[rowstart:rowend, colstart:colend] = X[xrow,:].reshape(height,width).transpose()
         
    imshow(display, cmap=get_cmap('binary'), interpolation='none')
    
    # Show plot without blocking
    draw()    
示例#2
0
 def _ichroma(self, V, **kwargs):
     """
     ::
     
         Inverse chromagram transform. Make a signal from a folded constant-Q transform.
     """
     if not (self._have_hcqft or self._have_cqft):
         return None
     a,b = self.HCQFT.shape if self._have_hcqft else self.CQFT.shape
     complete_octaves = a/self.nbpo # integer division, number of complete octaves
     if P.remainder(a,self.nbpo):
         complete_octaves += 1
     X = P.repeat(V, complete_octaves, 0)[:a,:] # truncate if necessary
     X /= X.max()
     X *= P.atleast_2d(P.linspace(1,0,X.shape[0])).T # weight the spectrum
     self.x_hat = self._icqft(X, **kwargs)
     return self.x_hat
示例#3
0
 def _ichroma(self, V, **kwargs):
     """
     ::
     
         Inverse chromagram transform. Make a signal from a folded constant-Q transform.
     """
     if not (self._have_hcqft or self._have_cqft):
         return None
     a,b = self.HCQFT.shape if self._have_hcqft else self.CQFT.shape
     complete_octaves = a/self.nbpo # integer division, number of complete octaves
     if P.remainder(a,self.nbpo):
         complete_octaves += 1
     X = P.repeat(V, complete_octaves, 0)[:a,:] # truncate if necessary
     X /= X.max()
     X *= P.atleast_2d(P.linspace(1,0,X.shape[0])).T # weight the spectrum
     self.x_hat = self._icqft(X, **kwargs)
     return self.x_hat
示例#4
0
文件: hamming.py 项目: lgarcin/TIPE
def correct(mat):
    S = remainder(H * mat, 2)
    pos = squeeze(asarray(matrix([4, 2, 1]) * S))
    cor = fromfunction(lambda i, j:i == pos - 1, mat.shape) * 1
    return mat + cor
示例#5
0
文件: hamming.py 项目: lgarcin/TIPE
# Affiche une image
def showimage(image):
    if image.ndim == 2:
        gray()
    imshow(image)

'''
Application du code de Hamming aux chaînes de caractères
'''

s = 'Ceci est un code de Hamming'
print ("Chaîne initiale :", s)
C = stringToBits(s.encode('latin-1'))  # Conversion chaîne->bits
E = addError(G * C, p)  # Codage et ajout d'une erreur
S = remainder(R * E, 2)  # Décodage sans correction
print ("Sans correction :", bitsToString(S).decode('latin-1'))
Z = remainder(R * correct(E), 2)  # Décodage avec correction
print ("Avec correction :", bitsToString(Z).decode('latin-1'))


'''
Application du code de Hamming aux images
'''

# Chargement de l'image        
image = imread("lena.jpg")

figure()

# Affichage de l'image initiale