Пример #1
0
def addZW(inmats, weights):
    mats = inmats.items()
    outmat = sameMat(mats[0][1])
    for key, mat in mats:
        tmp = sameMat(mat)
        cv.Scale(zscale(mat), tmp, weights[key])
        cv.Add(outmat, tmp, outmat)
    return outmat
Пример #2
0
def addW(inmats, weights):
    mats = inmats.items()
    outmat = sameMat(mats[0][1])
    for key, mat in mats:
        if not key in weights:
            continue
        tmp = sameMat(mat)
        cv.Scale(mat, tmp, weights[key])
        cv.Add(outmat, tmp, outmat)
    return outmat
Пример #3
0
def sobel(inmat, ws = 7):
    h = sameMat(inmat)
    v = sameMat(inmat)
    outmat = sameMat(inmat)
    cv.Sobel(inmat, h, 1, 0, ws)
    cv.Sobel(inmat, v, 0, 1, ws)
    cv.Mul(h, h, h)
    cv.Mul(v, v, v)
    cv.Add(h, v, outmat)
    cv.Pow(outmat, outmat, 0.5)
    return outmat
Пример #4
0
def contrast(inmat, ws = 51):
    sq = sameMat(inmat)
    smth = sameMat(inmat)
    outmat = sameMat(inmat)
    cv.Mul(inmat, inmat, sq)
    cv.Smooth(sq, sq, cv.CV_GAUSSIAN, ws, ws)
    cv.Smooth(inmat, smth, cv.CV_GAUSSIAN, ws, ws)
    cv.Mul(smth, smth, smth)
    cv.Sub(sq, smth, outmat)
    cv.Normalize(outmat, outmat, 0, 1, cv.CV_MINMAX)
    cv.Pow(outmat, outmat, 0.5)
    cv.Threshold(outmat, outmat, 0, 0, cv.CV_THRESH_TOZERO)
    del smth, sq
    return outmat
Пример #5
0
def contrast(inmat, ws = 41):  # Former: 51, pixels per degree?
    constrastLogger.debug("Kernel size for normal contrast: %s" % ws)

    sq = sameMat(inmat)
    smth = sameMat(inmat)
    outmat = sameMat(inmat)
    cv.Mul(inmat, inmat, sq)
    cv.Smooth(sq, sq, cv.CV_GAUSSIAN, ws, ws)
    cv.Smooth(inmat, smth, cv.CV_GAUSSIAN, ws, ws)
    cv.Mul(smth, smth, smth)
    cv.Sub(sq, smth, outmat)
    cv.Normalize(outmat, outmat, 0, 1, cv.CV_MINMAX)
    cv.Pow(outmat, outmat, 0.5)
    cv.Threshold(outmat, outmat, 0, 0, cv.CV_THRESH_TOZERO)
    del smth, sq
    return outmat
Пример #6
0
def multiply(inmat, value):
    outmat = sameMat(inmat)
    cv.Scale(inmat, outmat, value)
    return outmat
Пример #7
0
def smooth(inmat, ws = 51):
    outmat = sameMat(inmat)
    cv.Smooth(inmat, outmat, cv.CV_GAUSSIAN, ws, ws)
    return outmat
Пример #8
0
        cv.Scale(mat, tmp, weights[key])
        cv.Add(outmat, tmp, outmat)
    return outmat


def equalize(inmat):
    mat = cv.CreateMat(inmat.rows, inmat.cols, cv.CV_8UC1)
    cv.Normalize(inmat, inmat, 0, 255, cv.CV_MINMAX)
    cv.Convert(inmat, mat)
    cv.EqualizeHist(mat, mat)
    return mat


def spatialbias(inmat, biasmat, (x, y), base=1.0, gain=1.0, bias_zero=None):

    outmat = sameMat(inmat)
    if bias_zero is not None:
        ZPX, ZPY = bias_zero
    else:
        ZPX, ZPY = biasmat.cols / 2, biasmat.rows / 2

    # extract bias source subrect
    srcX = max(ZPX - x, 0)
    srcY = max(ZPY - y, 0)
    srcW = min(min(ZPX - x, 0) + inmat.cols, biasmat.cols - srcX)
    srcH = min(min(ZPY - y, 0) + inmat.rows, biasmat.rows - srcY)
    srcRect = cv.GetSubRect(biasmat, (srcX, srcY, srcW, srcH))

    # bias in size and coordinates of target matrix
    tarbias = sameMat(inmat)
    cv.Set(tarbias, 0)
Пример #9
0
def smooth(inmat, ws = 41):  # Former 51
    smoothLogger.debug("Kernel size for smooth: %s" % ws)
    outmat = sameMat(inmat)
    cv.Smooth(inmat, outmat, cv.CV_GAUSSIAN, ws, ws)  # a third parameter could adjust the SD of the gaussian!
    # otherwise sigma is automatically calculated by 0.3 * (ws/2-1) + 0.8
    return outmat