Ejemplo n.º 1
0
def getDistanceTest():
    from algorithm import getDistance
    
    m,n=20,10
    ma = np.zeros((m,n)).astype(int)
    ma[:5,5:]=1
    ma[5:,:5]=2
    ma[5:,5:]=3
    
    dis = getDistance(ma)
    print ma
    print dis[0][2]
    print dis[0][1]
Ejemplo n.º 2
0
def getWeightSumTest():
    from algorithm import getLbp ,getVectors,getWeightSum
    labelMap = getSlic(img,200) 
    maxLabel = labelMap.max() + 1
    im = sk.color.rgb2lab(img)
    degreeVectors, Ws = getVectors(im, labelMap)
    vectors = getWeightSum(labelMap, degreeVectors, Ws)
    m,n = labelMap.shape
    imgg = np.zeros((m,n))
    imgg2 = np.zeros((m,n))
    order = ['lab','l','a','b','lab-texture','l-texture','a-texture','b-texture']
    labs = [im]+ [im[:,:,i] for i in range(3)]
    lbps = map(lambda c: getLbp(c,labelMap,1)[1],labs)
    labLbp = labs + lbps
    for color in range(vectors.shape[1]):
        for k in range(maxLabel):
            imgg[labelMap==k]=vectors[k][color]
            imgg2[labelMap==k]=degreeVectors[k][color]
        print order[color],'raw | scatter | weight sum'
#        show(sk.exposure.equalize_hist(imgg))
        show([labLbp[color],imgg2,imgg],1)
    loga(degreeVectors)
    loga(vectors)
    g()
Ejemplo n.º 3
0
def getEdgeImg(img, labelMap=None, width=0.0):
    '''
    width(float):how width of edge
    return a list of label: edge of labelMap
    '''
    labelMap = getSlic(img, 300) if labelMap is None else labelMap
    width = int(min(*labelMap.shape) * width)
    u, d, l, r = (labelMap[0:width + 1].ravel(), labelMap[-1 - width:].ravel(),
                  labelMap[:,
                           0:width + 1].ravel(), labelMap[:,
                                                          -1 - width:].ravel())
    edge = np.unique(np.c_[[u], [d], [l], [r]])
    new = np.zeros(img.shape)
    for i in edge:
        new[labelMap == i] = 1

    show(new)
    return new
Ejemplo n.º 4
0
IMG_DIR = r'C:\D\dataset\saliency\ECSSD-small\images/'
COARSE_DIR =r'C:\D\dataset\saliency\ECSSD-small\ground_truth_mas/'

IMG_DIR = r'test/'
COARSE_DIR ='test/'


IMG_NAME_LIST = filter(lambda x:x[-3:]=='jpg',listdir(IMG_DIR))

setModuleConstant(alg)

imgName = IMG_NAME_LIST[0]
img,imgGt = readImg(imgName)
rgbImg = img

rgbImg = np.zeros((100,100,3))
rgbImg[25:75,25:75,1:]=1.
#show(rgbImg)

def integratImgsBy3wayTest():
    from algorithm import getSlic,getCoarseDic,integratImgsBy3way,buildMethodDic
    labelMap = getSlic(rgbImg,300)
    img = rgbImg
    m, n = labelMap.shape 
    
    coarseMethods = ['GT']
    coarseDic = getCoarseDic(imgName,coarseMethods)
#    show(coarseDic)   
    coarseImgs=coarseDic.values()       
    
    g()