Commit aa4e1195 authored by jansen31's avatar jansen31
Browse files

Merge remote-tracking branch 'origin/dornheim' into dornheim

parents 6cbdf264 1e878b78
""" Flip.py
written on 10. May 2019 by
Constantin Höing
Inst. Fuer Numerische und Angewandte Mathematik
Universität Göttingen
DESCRIPTION: Flips a 2x2 image
INPUT: A, an image to be flipped
OUTPUT: B, the flipped image
USAGE: B=Flip(A)
NONSTANDARD FUNCTION CALLS: Reorder.py
!!!!!!!!!!! Not sure if it does the job correctly !!!!!!!!!!
"""
from Reorder import Reorder
from numpy import arange
def Flip(A):
return Reorder(Reorder(A))
if __name__ == "__main__":
A = arange(1, 19).reshape(2,3,3)
print(A)
print(Flip(A))
\ No newline at end of file
""" Mgen.py
written on 10. May 2019 by
Constantin Höing
Inst. Fuer Numerische und Angewandte Mathematik
Universität Göttingen
Usage: A = Mgen(k,n,s,c)
Inputs: rows, k; columns, n; scaling, s; center, c; seed, seed.
Output: Random matrix with elements uniformly distributed on [c-s, c+s].
"""
#from random import seed as ran_seed
from numpy.random import seed as ran_seed, rand
from numpy import ones
def Mgen(k, n, s, c, seed):
# rand('state',sum(100*clock))
ran_seed(seed) # set the seed for the random generator to "seed"
# not quite like rand('state', seed); in the .m file
return s * (rand(k, n) - 0.5 * ones((k,n)))+c
if __name__ == "__main__":
print(Mgen(2,2,1,0,3036))
""" Reorder.py
written on 10. May 2019 by
Constantin Höing
Inst. Fuer Numerische und Angewandte Mathematik
Universität Göttingen
DESCRIPTION: Reorders a 2x2 image
INPUT: A, an image to be reordered
OUTPUT: B, the reordered image
USAGE: B=Reorder(A)
"""
from numpy import shape, zeros, arange, concatenate, size
def Reorder(B):
# Reorders a matrix
n1 = shape(B)[-2] -1
n2 = shape(B)[-1]
# if it is a nxmxk matix
try:
#A = zeros((n1+1, n2))
A = zeros((size(B[:, 0]), n2))
#print(B[1,:])
for j in range(n1+1):
#A[n1-j, :] = B[j, :]
A[:, n1-j] = concatenate(B[:, j])
return A.T
#if it is a n x m matrix
except:
A = zeros((n1+1, n2))
#A = zeros((size(B[:, 0]), n2))
#print(B[1,:])
for j in range(n1+1):
A[n1-j, :] = B[j, :]
#A[:, n1-j] = concatenate(B[:, j])
return A
if __name__ == "__main__":
# does the Reorder.m file miss a "end" statemant at the end of the function ??
A = arange(1,19).reshape(2,3,3)
print(Reorder(A))
A = arange(1,10).reshape(3,3)
print(Reorder(A))
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment