Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def getRefindImgsTest():
    IMG_DIR = r'E:\3-experiment\SalBenchmark-master\Data\DataSet1\Imgs/'
    COARSE_DIR =r'E:\3-experiment\SalBenchmark-master\Data\DataSet1\Saliency/'
      
    IMG_DIR =  'test/'
    COARSE_DIR ='test/'
  
    IMG_NAME_LIST = filter(lambda x:x[-3:]=='jpg',listdir(IMG_DIR))
    coarseMethods = ['QCUT','DRFI']
    coarseMethods = ['GT']
    imgInd = 0
    n_segments,compactness = 200,10
    
    imgName = IMG_NAME_LIST[imgInd]
    img,imgGt = readImg(imgName)
    coarseDic = getCoarseDic(imgName,coarseMethods)
    #show(coarsesDic)   
    sumCoarseImg = getSumCoarseImg(coarseDic)
    coarseImgs=coarseDic.values()
    labelMap = getSlic(img,n_segments,compactness)
    
    rgb = img
    
    img = sk.color.rgb2lab(img)
    #show([mark_boundaries(img,labelMap),imgGt])
    # 获得4+4维  distance
    degreeVectors, Ws = getVectors(img, labelMap)
    vectors = getWeightSum(labelMap, degreeVectors, Ws)
    
    vectorsTrains = []
    coarseTrains = []
    for coarseImg in coarseImgs:
        coarseTrain, vectorsTrainTag = getCoarseTrain(coarseImg, labelMap)
        vectorsTrains += list(vectors[vectorsTrainTag])
        coarseTrains += list(coarseTrain)
    
    elm = getElm(np.array(vectorsTrains), np.array(coarseTrains))
    refined = elm.predict(vectors)[:,0]
    refinedImg = valueToLabelMap(labelMap,normalizing(refined))
    
    vectorsImg = valueToLabelMap(labelMap,normalizing(vectors.sum(1)))
    show([rgb,refinedImg])
    show([rgb,vectorsImg])
    show(vectorsImg-refinedImg)
    loga(vectorsImg-refinedImg)
    g()
Ejemplo n.º 3
0
def my4test():
#if 1:
    from algorithm import *
    labelMap = getSlic(rgbImg,200)
    maxLabel = labelMap.max()+1
    m, n = labelMap.shape 
    
    coarseMethods = ['MEAN']
    coarseDic = getCoarseDic(imgName,coarseMethods)
#    show(coarseDic)   
    sumCoarseImg = getSumCoarseImg(coarseDic)
    coarseImgs=coarseDic.values()    

    img = sk.color.rgb2lab(rgbImg)
    # 获得4+4维  distance
    degreeVectors, Ws = getVectors(img, labelMap)
    weightSumVectors = getWeightSum(labelMap, degreeVectors, Ws)
    
    diffEdges,diffNeighbors = getAllDiffEdgeAndNeighbor(labelMap,Ws)
    vectors = np.append(weightSumVectors,diffEdges,1)
    vectors = np.append(vectors,diffNeighbors,1)

    vectorsTrains = []
    coarseTrains = []
    for coarseImg in coarseImgs:
        coarseTrain, vectorsTrainTag = getCoarseTrain(coarseImg, labelMap)
        vectorsTrains += list(vectors[vectorsTrainTag])
        coarseTrains += list(coarseTrain)
    
    elm = getElm(np.array(vectorsTrains), np.array(coarseTrains))
    refined = elm.predict(vectors)[:,0]
    refinedImg = valueToLabelMap(labelMap,normalizing(refined))
    show(mark_boundaries(sk.color.lab2rgb(img),labelMap))
    print diffEdges.shape
    show(valueToLabelMap(labelMap,diffEdges.sum(1)))
    show(valueToLabelMap(labelMap,diffNeighbors[:,:4].sum(1)))
#    show(valueToLabelMap(labelMap,diffNeighbors[:,4:].sum(1)))
#    show(valueToLabelMap(labelMap,diffNeighbors.sum(1)))
    show(valueToLabelMap(labelMap,vectors[:,4:8].sum(1)))