def main():
    glassLabel = 255
    thicknessForEvaluation = 20
    objects=('bank', 'bottle', 'bucket', 'glass', 'wineglass')
    basePath = '/media/2Tb/transparentBases/fixedOnTable/base/'

    base = utils.TODBase(basePath, objects)
    patchSizes = (5, 10, 20, 40, 100, 200, 400)
    fks = (10, 20, 50, 100, 200, 400, 800, 1600)

    allSamples = base.getSamples()
    evaluator = utils.Evaluator(len(patchSizes))
#    evaluator = utils.Evaluator(len(fks))
    for sample in allSamples:
        print sample.imageFilename
 
        groundTruthMask = sample.getGlassMask()
        if (groundTruthMask == None):
            continue
        [groundTruthDT, groundTruthEdgelsCount] = utils.mask2dtAndEdgelsCount(groundTruthMask)
        glassMask = groundTruthMask.copy()
        glassContours, hierarchy = cv2.findContours(glassMask, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
        glassContoursImage = np.zeros(glassMask.shape, np.uint8)
        cv2.drawContours(glassContoursImage, glassContours, -1, (255), thicknessForEvaluation)

        image = sample.getImage()
        for idx, size in enumerate(patchSizes):
            segmentation = computeVeksler(image, size)
#        for idx, k in enumerate(fks):
#            segmentation = computeFelzenszwalb(image, k)
            minSegmentation = cv2.erode(segmentation.astype(np.float32), None)
            maxSegmentation = cv2.dilate(segmentation.astype(np.float32), None)
            boundaries = 255 * (maxSegmentation - minSegmentation != 0).astype(np.uint8)
            boundaries[glassContoursImage == 0] = 0
            boundariesEdgelsCount = len(np.nonzero(boundaries == 255)[0])
            boundariesDT = cv2.distanceTransform(~boundaries, cv2.cv.CV_DIST_L1, cv2.cv.CV_DIST_MASK_PRECISE)

            [recallEdgels, precisionEdgels] = utils.computeRecallPrecisionEdgels(groundTruthDT, boundariesDT)
            evaluator.addObservation(idx, recallEdgels, groundTruthEdgelsCount, precisionEdgels, boundariesEdgelsCount)
        evaluator.computeStatistics()
        evaluator.printStatistics()


    evaluator.plot('veksler')
#    evaluator.plot('felz')
    utils.plt.show()
Exemplo n.º 2
0
        groundTruthFilename = imageFilename.replace(
            '/image_', '/' + groundTruthPrefix + '_')
        testFolder = imageFilename.replace('/image_' + fullImageIndex + '.png',
                                           '/')

        call([
            segmentImage, testFolder, fullImageIndex, classifierFilename,
            segmentationListFilename, propagationScalingsList, algorithmName
        ])

        groundTruth = cv2.imread(groundTruthFilename,
                                 cv2.CV_LOAD_IMAGE_GRAYSCALE)
        glassLabel = 255
        groundTruthGlassMask = (groundTruth == glassLabel).astype(np.uint8)
        [groundTruthDT, groundTruthEdgelsCount
         ] = utils.mask2dtAndEdgelsCount(groundTruthGlassMask)

        for (index, temporaryFile) in enumerate(segmentationTemporaryFiles):
            segmentationImage = cv2.imread(temporaryFile[1],
                                           cv2.CV_LOAD_IMAGE_GRAYSCALE)
            [segmentationImageDT, segmentationImageEdgelsCount
             ] = utils.mask2dtAndEdgelsCount(segmentationImage)
            [recallEdgelsCount, precisionEdgelsCount
             ] = utils.computeRecallPrecisionEdgels(groundTruthDT,
                                                    segmentationImageDT)

            trueGlassArea = len(np.nonzero(groundTruth == glassLabel)[0])
            predictedGlassArea = len(
                np.nonzero(segmentationImage == glassLabel)[0])
            validPredictedGlassArea = len(
                np.nonzero(
        if (match == None):
            match = re.search('_(0000(0))\.', imageFilename)
        assert match != None, 'Cannot parse an image index'

        fullImageIndex = match.group(1)
        imageIndex = match.group(2)

        groundTruthFilename = imageFilename.replace('/image_', '/' + groundTruthPrefix + '_')
        testFolder = imageFilename.replace('/image_' + fullImageIndex + '.png', '/')

        call([segmentImage, testFolder, fullImageIndex, classifierFilename, segmentationListFilename, propagationScalingsList, algorithmName])

        groundTruth = cv2.imread(groundTruthFilename, cv2.CV_LOAD_IMAGE_GRAYSCALE)
        glassLabel = 255
        groundTruthGlassMask = (groundTruth == glassLabel).astype(np.uint8)
        [groundTruthDT, groundTruthEdgelsCount] = utils.mask2dtAndEdgelsCount(groundTruthGlassMask)

        for (index, temporaryFile) in enumerate(segmentationTemporaryFiles):
            segmentationImage = cv2.imread(temporaryFile[1], cv2.CV_LOAD_IMAGE_GRAYSCALE)
            [segmentationImageDT, segmentationImageEdgelsCount] = utils.mask2dtAndEdgelsCount(segmentationImage)
            [recallEdgelsCount, precisionEdgelsCount] = utils.computeRecallPrecisionEdgels(groundTruthDT, segmentationImageDT)

            trueGlassArea = len(np.nonzero(groundTruth == glassLabel)[0])
            predictedGlassArea = len(np.nonzero(segmentationImage == glassLabel)[0])
            validPredictedGlassArea = len(np.nonzero(np.logical_and(groundTruth == glassLabel, segmentationImage == groundTruth))[0])

            boundaryEvaluator.addObservation(index, recallEdgelsCount, groundTruthEdgelsCount, precisionEdgelsCount, segmentationImageEdgelsCount)
            areaEvaluator.addObservation(index, validPredictedGlassArea, trueGlassArea, validPredictedGlassArea, predictedGlassArea)

        areaEvaluator.computeStatistics()
        areaEvaluator.printStatistics()