示例#1
0
def segmentImage(*args):
    id = args[0]

    print "Start id: " + str(id)

    image = loadImage(id, "../sampleimages\\")
    if not image == None:
        segmented, labels = cl.slic(image)
        io.imsave("segmented/" + str(id) + ".jpg", image)
        io.imsave("segmented/" + str(id) + "_segmented.jpg", segmented)

    print "Finish id: " + str(id)
示例#2
0
def getTaggedSegments(id, taggedPoints, possibleTags):

    li = ['tag1c', 'tag2c', 'tag3c', 'tag4c', 'tag5c', 'tag6c', 'tag7c', 'tag8c', 'tag9c', 'tag10c']
    li2 = ['tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6', 'tag7', 'tag8', 'tag9', 'tag10']

    possibleTagsDict = {}
    possibleTagsDictSobel = {}
    for tag in possibleTags:
        possibleTagsDict[tag[0]] = []
        possibleTagsDictSobel[tag[0]] = []

    print "Processing id: " + id
    for i in range(len(li)):
        newPoints = []
        for point in taggedPoints[id][li[i]]:
            newPoints.append(point.split(':'))

        taggedPoints[id][li[i]] = newPoints

    image = loadImage(id, "../sampleimages\\")
    sobelImage = filt.sobel(skcol.rgb2gray(image))
    if not image == None:
        segmented, labels = cl.slic(image)
        labelledSegments = labels[0]
        labels = labels[1]
        n_clusters = labels[2]

    for i in range(len(li)):
        for point in taggedPoints[id][li[i]]:
            for segment in labelledSegments:
                #add list of pixels to corresponding tag
                try:
                    if len(point) == 2:
                        if point[0] != '' and point[1] != '':
                            if segment[int(point[1])][int(point[0])] and taggedPoints[id][li2[i]] != 'None':
                                possibleTagsDict[taggedPoints[id][li2[i]].replace('"', '')].append(image[segment])
                                possibleTagsDictSobel[taggedPoints[id][li2[i]].replace('"', '')].append(np.nanmean(sobelImage[segment]))
                except:
                    continue
                    
    return [possibleTagsDict, possibleTagsDictSobel]
示例#3
0
def getImageFeatures(imageId, targetDir = "../sampleimages\\"):
    image = loadImage(imageId, targetDir)
    sobelImage = filt.sobel(skcol.rgb2gray(image))
    fig = plt.figure()
    ax1 = fig.add_subplot(1,1,1)
    ax1.imshow(image)
    plt.show()
    if not image == None:
        segmented, labels = cl.slic(image)
        labelledSegments = labels[0]
        labels = labels[1]
        n_clusters = labels[2]

    imageSegments = []
    for segment in labelledSegments:
        imageSegments.append(image[segment])

    sobelSegments = []
    for segment in labelledSegments:
        sobelSegments.append(np.nanmean(sobelImage[segment]))

    return getImageFeatureVectors(imageSegments, sobelSegments)