Beispiel #1
0
def normalizeWeights(pixelExpr):
	maxSum = max(
		sum(weights)
		for expr in pixelExpr
		for weights in expr
		)
	return [
		[ scaleWeights(weights, maxSum) for weights in expr ]
		for expr in pixelExpr
		]
Beispiel #2
0
def convertExpr4to2(case, expr4):
	weights2 = [0] * 4
	for weights4 in expr4:
		for neighbour, weight in enumerate(scaleWeights(weights4, 256)):
			weights2[neighbour] += weight
	weights2 = simplifyWeights(weights2)
	if ((case >> 4) & 15) in (2, 6, 8, 12):
		assert sorted(weights2) == [0, 2, 7, 23]
		weightMap = { 0: 0, 2: 1, 7: 1, 23: 2 }
	elif ((case >> 4) & 15) in (0, 1, 4, 5):
		assert sorted(weights2) == [0, 3, 3, 10]
		weightMap = { 0: 0, 3: 1, 10: 2 }
	else:
		weightMap = None
	if weightMap:
		weights2 = tuple(weightMap[weight] for weight in weights2)
	return [weights2]
Beispiel #3
0
        for qx in range(quadrantWidth)
    ]
    for expr in [[expr[subPixel] for subPixel in quadrantMap]
                 for expr in pixelExpr]:
        for weights in expr:
            for neighbour in (2, 5, 6, 7, 8):
                assert weights[neighbour] == 0, weights
    return [[
        extractTopLeftWeights(expr[subPixel]) for subPixel in quadrantMap
    ] for expr in pixelExpr]


def convertExpr4to2(case, expr4):
    weights2 = [0] * 4
    for weights4 in expr4:
        for neighbour, weight in enumerate(scaleWeights(weights4, 256)):
            weights2[neighbour] += weight
    weights2 = simplifyWeights(weights2)
    if ((case >> 4) & 15) in (2, 6, 8, 12):
        assert sorted(weights2) == [0, 2, 7, 23]
        weightMap = {0: 0, 2: 1, 7: 1, 23: 2}
    elif ((case >> 4) & 15) in (0, 1, 4, 5):
        assert sorted(weights2) == [0, 3, 3, 10]
        weightMap = {0: 0, 3: 1, 10: 2}
    else:
        weightMap = None
    if weightMap:
        weights2 = tuple(weightMap[weight] for weight in weights2)
    return [weights2]