Exemple #1
0
def koponging(bw):
    bwr = bw.copy()
    
    # remove filler
    rollup, rolldown, rollleft, rollright = nph.roll_all(bwr)
    bwr -= bwr * rolldown * rollup * rollright * rollleft
    
    # remove zigzag
    rollup, rollright = nph.roll_up(bwr), nph.roll_right(bwr)
    rolldownleft = nph.roll_left(nph.roll_down(bwr))
    bwr -= bwr * rollup * rollright * (rolldownleft == False)
    
    rollright, rolldown = nph.roll_right(bwr), nph.roll_down(bwr)
    rollupleft = nph.roll_left(nph.roll_up(bwr))
    bwr -= bwr * rollright * rolldown * (rollupleft == False)
    
    rolldown, rollleft = nph.roll_down(bwr), nph.roll_left(bwr)
    rollupright = nph.roll_right(nph.roll_up(bwr))
    bwr -= bwr * rolldown * rollleft * (rollupright == False)
    
    rollleft, rollup = nph.roll_left(bwr), nph.roll_up(bwr)
    rolldownright = nph.roll_right(nph.roll_down(bwr))
    bwr -= bwr * rollleft * rollup * (rolldownright == False)
    
    return bwr
Exemple #2
0
def gaussian(img):
    # kernel = [1, 3, 5, 3, 1]
    kernel = [1, 4, 7, 9, 7, 4, 1]
    
    kernel_count = len(kernel)
    kernel_half = (kernel_count-1)/2
    rolls = range(0, len(kernel))
    result = np.zeros(img.shape, dtype=np.float)
    
    rolls[kernel_half] = img.astype(np.float)
    for i in range(1, kernel_half+1):
        rolls[kernel_half+i] = nph.roll_left(rolls[kernel_half+i-1], img[:,-1].copy())
        rolls[kernel_half-i] = nph.roll_right(rolls[kernel_half-i+1], img[:,0].copy())
    for i in range(0, kernel_count):
        result += rolls[i] * kernel[i]
    result /= sum(kernel)
    
    rolls[kernel_half] = result.copy()
    result = 0
    for i in range(1, kernel_half+1):
        rolls[kernel_half+i] = nph.roll_up(rolls[kernel_half+i-1], img[-1].copy())
        rolls[kernel_half-i] = nph.roll_down(rolls[kernel_half-i+1], img[0].copy())
    for i in range(0, kernel_count):
        result += rolls[i] * kernel[i]
    result /= sum(kernel)
    
    return result.round().astype(np.uint8)
Exemple #3
0
def create_rolls(gray, kernel):
    mid = (len(kernel)-1)/2
    
    rolls = []
    for y in kernel:
        roll = []
        for x in y:
            roll.append(gray.copy().astype(np.float))
        rolls.append(roll)
    
    for i in range(0, mid):
        for j in range(0, i+1):
            for k in range(0, len(rolls)):
                rolls[j][k][:] = nph.roll_down(rolls[j][k], rolls[mid][j][0].copy())
    
    for i in range(len(rolls)-1, mid, -1):
        for j in range(len(rolls)-1, i-1, -1):
            for k in range(0, len(rolls)):
                rolls[j][k][:] = nph.roll_up(rolls[j][k], rolls[mid][j][-1].copy())
    
    for i in range(0, mid):
        for j in range(0, i+1):
            for k in range(0, len(rolls)):
                rolls[k][j][:] = nph.roll_right(rolls[k][j], rolls[k][mid][:, 0].copy())
    
    for i in range(len(rolls)-1, mid, -1):
        for j in range(len(rolls)-1, i-1, -1):
            for k in range(0, len(rolls)):
                rolls[k][j][:] = nph.roll_left(rolls[k][j], rolls[k][mid][:, -1].copy())
    
    return rolls
Exemple #4
0
def mulsum(gray, operator_baris, operator_kolom, y, x):
    rolled = np.array(gray, dtype=np.int32)
    
    if y == 0:
        rolled[:] = nph.roll_down(rolled)
    elif y == 2:
        rolled[:] = nph.roll_up(rolled)
    
    if x == 0:
        rolled[:] = nph.roll_right(rolled)
    elif x == 2:
        rolled[:] = nph.roll_left(rolled)
    
    return rolled * (operator_baris[y][x] + operator_kolom[y][x])