Skip to content

Commit

Permalink
mask
Browse files Browse the repository at this point in the history
  • Loading branch information
Wysaat committed May 17, 2013
1 parent 79d8a1c commit 6fe111e
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions mask.py
Original file line number Diff line number Diff line change
@@ -0,0 1,108 @@
from copy import deepcopy

def mask(matrix):
# in the unmasked matrix, -2 means 0, -1 means 1
maskingscores = []
matrixes = []
size = len(matrix)
matrixes.append(domask(matrix, '(((i j) % 2) == 0)'))
matrixes.append(domask(matrix, '((i % 2) == 0)'))
matrixes.append(domask(matrix, '((j % 3) == 0)'))
matrixes.append(domask(matrix, '(((i j) % 3) == 0)'))
matrixes.append(domask(matrix, '(((int(i / 2) int(j / 3)) % 2) == 0)'))
matrixes.append(domask(matrix, '((((i * j) % 2) ((i * j) % 3)) == 0)'))
matrixes.append(domask(matrix, '(((((i * j) % 2) ((i * j) % 3)) % 2) == 0)'))
matrixes.append(domask(matrix, '(((((i * j) % 3) ((i j) % 2)) % 2) == 0)'))
scores = [scoremasking(matrix) for matrix in matrixes]


def domask(matrix, condition):
nmatrix = deepcopy(matrix)
for i in range(len(nmatrix)):
for j in range(len(nmatrix)):
if nmatrix[i][j] == -2 and eval(condition):
nmatrix[i][j] = 1
elif nmatrix[i][j] == -1 and not eval(condition):
nmatrix[i][j] = 1
elif nmatrix[i][j] < 0:
nmatrix[i][j] = 0
return nmatrix

def scoremasking(matrix):
# feature 1
def scorefeature1(matrix):
score = 0
for i in range(len(matrix)):
string = ''.join(matrix[i])
ones = [i for i in string.split('0') if len(i) > 5]
zeros = [i for i in string.split('1') if len(i) > 5]
for one in ones:
score = len(one) - 2
for zero in zeros:
score = len(zero) - 2
return score

def scorefeature2(matrix):
score = 0
for i in range(len(matrix)):
for j in range(len(matrix)):
m = n = 1
color = matrix[i, j]
while True:
if i = len(matrix) - 1:
break
for y in range(n):
if matrix[i 1][j y] != color:
break
m = 1
i = 1
while True:
if j = len(matrix) -1:
break
for x in range(m):
if matrix[i - x][j 1] != color:
break
n = 1
j = 1
score = 3 * (m - 1) * (n - 1)
return score

def scorefeature3(matrix):
score = 0
for i in range(len(matrix)):
string = ''.join(matrix[i])
if '1011101' in string:
score = 40
return score

def scorefeature4(matrix):
for i in range(len(matrix)):
for j in range(len(matrix)):
if matrix[i][j] == 1:
dark = 1
proportion = dark / (len(matrix) ** 2)
deviation = proportion - 0.5
de = int(deviation * 100)
k = int(de / 5)
score = 10 * k
return score

def scoremasking(matrix):
score = 0

# feature 1
rotmatrix = [[matrix[i][j] for i in range(len(matrix))] for j in range(len(matrix))]
score = scorefeature1(matrix)
score = scorefeature1(rotmatrix)

# feature 2
score = scorefeature2(matrix)

# feature 3
score = scorefeature3(matrix)
score = scorefeature3(rotmatrix)

# feature 4
score = scorefeature4(matrix)

return score

0 comments on commit 6fe111e

Please sign in to comment.