Beispiel #1
0
def derajat2(gray, type):
    result = np.zeros(gray.shape, dtype=np.float)
    
    if type == 'kirsch':
        kernel = [
            [5, 5, 5],
            [-3, 0, -3],
            [-3, -3, -3],
        ]
    
    elif type == 'prewitt':
        kernel = [
            [-1, 0, 1],
            [-1, 0, 1],
            [-1, 0, 1],
        ]
    
    results = []
    for i in range(0, 8):
        results.append(convolve(gray, kernel))
        kernel[:] = nph.rot45(np.array(kernel))
    
    for i in range(0, 8):
        result[:] = np.maximum(result, results[i])
    
    result[:] = normalize(result)
    return result.round().astype(np.uint8)
Beispiel #2
0
def kirsch(gray):
    dummy = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
    kernel = np.array([[5, 5, 5,],
                       [-3, 0, -3],
                       [-3, -3, -3]])
    
    results = []
    for i in range(0, 8):
        results.append(operate(gray, kernel, dummy))
        kernel[:] = nph.rot45(kernel)
    
    result = results[0]
    for i in range(1, 8):
        result[:] = np.maximum(result, results[i])
    
    return normalize(result).round().astype(np.uint8)