Пример #1
0
def process(fPts, fImgs, train, method, maxPx, fSize):
    params = {
        "nIters": 7,
        "nTrain": 500,
        "filterPts": fPts,
        "filterImgs": fImgs,
        "trainASM": train,
        "writePCA": False,
        "maxPx": maxPx,
        "fSize": fSize,
        "method": method
    }

    params = OrderedDict(sorted(params.items(), key=lambda t: len(t[0])))
    ##Methods: "SSD", "NCorr", or "grad"
    ASMout = getASMfolder(params)
    appASMout = getMethodSubFolder(params, ASMout)

    fh = FileHelper(params["nIters"], params["nTrain"], ASMout,
                    params["filterPts"], params["filterImgs"])

    if params["filterPts"]:
        asm = ActiveShapeModel([43, 35])
    else:
        asm = ActiveShapeModel([36, 31])

    if params["trainASM"]:
        asm = fh.readInPoints(asm)
        asm = ShapeAligner(asm, params["nIters"], ASMout).alignTrainingSet()
        fh.writeOutASM(asm)  #write out to read in later
    else:
        asm = fh.readInASM(asm)

    ### Calculate Principal components

    asm.PCA()

    if params["trainASM"] or params["writePCA"]:
        ### Draw PCA stuffs
        if not os.path.exists(os.path.join(ASMout, "PCA")):
            os.mkdir(os.path.join(ASMout, "PCA"))
        wu = WriteUp(asm, fh)
        wu.PCAresults()

    if not params["trainASM"]:
        ### Apply ASM to image
        img = cv2.imread(
            "C:\Users\Valerie\Desktop\MicroExpress\CASME2\CASME2_RAW\CASME2-RAW\sub01\EP02_01f\img1.jpg"
        )
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        appASM = ApplyASM(asm, params["nIters"], params["nTrain"], appASMout,
                          img, params['method'], params['maxPx'],
                          params['fSize'], params["filterPts"])
        appASM.applyASM()
def process( fPts, fImgs, train, method, maxPx, fSize ):
    params ={ "nIters" : 7, 
              "nTrain" : 500,
              "filterPts" : fPts,
              "filterImgs" : fImgs,
              "trainASM" : train, 
              "writePCA" : False,
              "maxPx" : maxPx,
              "fSize" : fSize,
              "method" : method
              }


    params = OrderedDict( sorted( params.items(), key = lambda t : len(t[0]) ) )
    ##Methods: "SSD", "NCorr", or "grad"
    ASMout = getASMfolder( params )
    appASMout = getMethodSubFolder( params, ASMout )

    fh = FileHelper( params["nIters"], params["nTrain"], ASMout, params["filterPts"], params["filterImgs"] )

    if params["filterPts"]:
        asm = ActiveShapeModel( [43,35] ) 
    else: 
        asm = ActiveShapeModel( [36,31] )    

    if params["trainASM"]:
        asm = fh.readInPoints( asm )
        asm = ShapeAligner( asm, params["nIters"], ASMout ).alignTrainingSet( )
        fh.writeOutASM( asm ) #write out to read in later
    else: 
        asm = fh.readInASM( asm )

    ### Calculate Principal components

    asm.PCA()

    if params["trainASM"] or params["writePCA"]:
        ### Draw PCA stuffs
        if not os.path.exists( os.path.join( ASMout, "PCA" ) ) :
            os.mkdir( os.path.join( ASMout, "PCA" ) )
        wu = WriteUp( asm, fh )
        wu.PCAresults()

    if not params["trainASM"] :
        ### Apply ASM to image
        img = cv2.imread( "C:\Users\Valerie\Desktop\MicroExpress\CASME2\CASME2_RAW\CASME2-RAW\sub01\EP02_01f\img1.jpg")
        img =  cv2.cvtColor( img, cv2.COLOR_BGR2GRAY)
        appASM = ApplyASM( asm, params["nIters"], params["nTrain"],
                          appASMout, img, params['method'], 
                          params['maxPx'], params['fSize'], params["filterPts"]  )
        appASM.applyASM()
    while os.path.exists( os.path.join( output, study )):
        i += 1
        study = "%d-%d-%d" % ( iters, training, i )
        if train or align:
            os.mkdir( os.path.join( output, study ) )
        else: 
            study = "%d-%d-%d" % ( iters, training, i )
        output =  os.path.join( output, study )



fh = FileHelper( iters, training , output )

if train:
    asm = ActiveShapeModel( [36,31] )
    asm = fh.readInPoints( asm )

### Align Shapes
if align:
    asm = ShapeAligner( asm, iters, output ).alignTrainingSet( )
    fh.writeOutASM( asm ) #write out to read in later


d = map( lambda x: x.shapeDist( asm.normMeanShape ), asm.allShapes )
d1 = np.mean( d, 1 )

min = np.min( d1 )
mn = np.mean( d1 )
q1 = np.percentile( d1, 0.25)
sd = np.std( d1 )
max = np.max( d1 )
    output = os.path.join(output, study)
else:
    while os.path.exists(os.path.join(output, study)):
        i += 1
        study = "%d-%d-%d" % (iters, training, i)
        if train or align:
            os.mkdir(os.path.join(output, study))
        else:
            study = "%d-%d-%d" % (iters, training, i)
        output = os.path.join(output, study)

fh = FileHelper(iters, training, output)

if train:
    asm = ActiveShapeModel([36, 31])
    asm = fh.readInPoints(asm)

### Align Shapes
if align:
    asm = ShapeAligner(asm, iters, output).alignTrainingSet()
    fh.writeOutASM(asm)  #write out to read in later

d = map(lambda x: x.shapeDist(asm.normMeanShape), asm.allShapes)
d1 = np.mean(d, 1)

min = np.min(d1)
mn = np.mean(d1)
q1 = np.percentile(d1, 0.25)
sd = np.std(d1)
max = np.max(d1)
q3 = np.percentile(d1, 0.75)