Ejemplo n.º 1
0
def main():
    im=imageIO.imread('rgb.png')
    lumi=im[:,:,1] #I'm lazy, I'll just use green
    smallLumi=numpy.transpose(lumi[0:5, 0:5])

    # Replace if False: by if True: once you have implement the required functions.
    # Exercises:
    if False:
        outputNP, myFunc=a11.smoothGradientNormalized()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'normalizedGradient.png')
    if False:
        outputNP, myFunc=a11.wavyRGB()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'rgbWave.png')
    if False:
        outputNP, myFunc=a11.luminance(im)
        imageIO.imwrite(outputNP, 'luminance.png')
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
    if False:
        outputNP, myFunc=a11.sobel(lumi)
        imageIO.imwrite(outputNP, 'sobelMag.png')
        print ' Dimensionality of Halide Func:', myFunc.dimensions()

    if False:
        L=a11.pythonCodeForBoxSchedule5(smallLumi)
        print L
    if False:
        L=a11.pythonCodeForBoxSchedule6(smallLumi)
        print L
    if False:
        L=a11.pythonCodeForBoxSchedule7(smallLumi)
        print L

    if False:
        outputNP, myFunc=a11.localMax(lumi)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'maxi.png')
    if False:
        input=Image(Float(32), lumi)
        x, y, c = Var('x'), Var('y'), Var('c')
        clamped = Func('clamped')
        clamped[x, y] = input[clamp(x, 0, input.width()-1),
                             clamp(y, 0, input.height()-1)]
        blurX, finalBlur= a11.GaussianSingleChannel(clamped)
    if False:
        im=numpy.load('Input/hk.npy')
        scheduleIndex=0
        outputNP, myFunc=a11.harris(im, scheduleIndex)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'harris.png')
Ejemplo n.º 2
0
def main():
    im=imageIO.imread('rgb-small.png')
    lumi=im[:,:,1] #I'm lazy, I'll just use green
    smallLumi=numpy.transpose(lumi[0:6, 0:6])

    # Replace if False: by if True: once you have implement the required functions.
    # Exercises:
    if True:
        outputNP, myFunc=a11.smoothGradientNormalized()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'normalizedGradient.png')

    if True:
        outputNP, myFunc=a11.wavyRGB()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'rgbWave.png')

    if True:
        outputNP, myFunc = a11.luminance(im)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'rgbLuminance.png')
        imageIO.imwrite(tests.luminance(im), 'rgbLuminancePython.png')

    if True:
        outputNP, myFunc=a11.sobel(lumi)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'sobelMag.png')
        imageIO.imwrite(tests.sobelMagnitude(lumi), 'sobelMagPython.png')

    if False:
        L=a11.pythonCodeForBoxSchedule5(smallLumi)
        for x in L:
            print x
        print ""

    if False:
        L=a11.pythonCodeForBoxSchedule6(smallLumi)
        print "Schedule 6:"
        for x in L:
            print x
        print ""

    if False:
        L=a11.pythonCodeForBoxSchedule7(smallLumi)
        print "Schedule 7"
        for x in L:
            print x
        print ""

    if True:
        outputNP, myFunc=a11.localMax(lumi)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'maxi.png')

    if False:
        testWhite = numpy.ones((50,50))
        input = Image(Float(32), testWhite)
        x, y = Var('x'), Var('y')
        clamped = Func('clamped')
        clamped[x, y] = input[clamp(x, 0, input.width()-1),
                             clamp(y, 0, input.height()-1)]
        sigma = 2.0 # IS THIS RIGHT?!?
        blurX, finalBlur= a11.GaussianSingleChannel(clamped , sigma, trunc=3)
        blurXOutput = blurX.realize(input.width(), input.height())
        blurXNP = numpy.array(Image(blurXOutput))
        imageIO.imwrite(blurXNP, 'blurXWhite.png')

    if True:
        input=Image(Float(32), lumi)
        x, y = Var('x'), Var('y')
        clamped = Func('clamped')
        clamped[x, y] = input[clamp(x, 0, input.width()-1),
                             clamp(y, 0, input.height()-1)]
        sigma = 5.0 # IS THIS RIGHT?!?
        blurX, finalBlur= a11.GaussianSingleChannel(clamped , sigma, trunc=3)

        blurXOutput = blurX.realize(input.width(), input.height())
        blurXNP = numpy.array(Image(blurXOutput))
        imageIO.imwrite(blurXNP, 'blurX.png')

        finalBlurOutput = finalBlur.realize(input.width(), input.height())
        finalBlurNP = numpy.array(Image(finalBlurOutput))
        imageIO.imwrite(finalBlurNP, 'finalBlur.png')

    if True:
        # im=numpy.load('Input/hk.npy')
        # outputNP, myFunc=a11.harris(im, 0)
        # imageIO.imwrite(outputNP, 'harris.png')
        outputNP, myFunc=a11.harris(im, 1)
        imageIO.imwrite(outputNP, 'harris_fast.png')
        print ' Dimensionality of Halide Func:', myFunc.dimensions()

    if False:
        # Timing for Harris
        im=imageIO.imread('hk.png')
        myFunc = a11.harris(im, 0)
        runAndMeasure(myFunc, im.shape[1], im.shape[0])
        myFunc = a11.harris(im, 1)
        runAndMeasure(myFunc, im.shape[1], im.shape[0])
        imageIO.imwrite(resultNP, 'harrisFast.png')
Ejemplo n.º 3
0
def main():
    im=imageIO.imread('rgb.png')
    lumi=im[:,:,1] #I'm lazy, I'll just use green
    smallLumi=numpy.transpose(lumi[0:5, 0:5])

    im_small = imageIO.imread('rgb-small.png')
    lumi_small = im_small[:,:,1]
    smallLumi_small = numpy.transpose(lumi_small[0:5, 0:5])

    # Replace if False: by if True: once you have implement the required functions. 
    # Exercises:
    if True:
        print 'Running smoothGradientNormalized'
        outputNP, myFunc=a11.smoothGradientNormalized()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'normalizedGradient.png')
    if True:
        print 'Running wavyRGB'
        outputNP, myFunc=a11.wavyRGB()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'rgbWave.png')
    if True:
        print 'Running lumninance'
        outputNP, myFunc=a11.luminance(im)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'lumiRGB.png')
    if True: 
        outputNP, myFunc=a11.sobel(lumi)
        imageIO.imwrite(outputNP, 'sobelMag.png')
        print ' Dimensionality of Halide Func:', myFunc.dimensions()

    if True: 
        L=a11.pythonCodeForBoxSchedule5(smallLumi)
        print L
    if True: 
        L=a11.pythonCodeForBoxSchedule6(smallLumi)
        print L
    if True: 
        L=a11.pythonCodeForBoxSchedule7(smallLumi)
        print L

    if True: 
        outputNP, myFunc=a11.localMax(lumi_small)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'maxi.png')

    if True: 
        input=Image(Float(32), lumi_small)
        xp, yp = Var('xp'), Var('yp')
        clamped = Func('clamped') 
        clamped[xp, yp] = input[clamp(xp, 0, input.width()-1),
                             clamp(yp, 0, input.height()-1)]
        sigma = 1.0
        blurX, finalBlur= a11.GaussianSingleChannel(clamped , sigma, trunc=3)
        output = finalBlur.realize(input.width(), input.height())
        outputNP = numpy.array(Image(output))
        print outputNP[outputNP < 0]
        imageIO.imwriteGrey(outputNP, "gaussian_blur.png")

    if True: 
        print 'Running harris corner detector'
        readstart = time.time()
        
        filen = "hk"
        print "Reading in file ", filen + ".png"
        im=numpy.load('Input/hk.npy')
        # im = imageIO.imread( filen + ".png")
        print "Reading in file took ... ", time.time() - readstart
        print "Running harris..." 
        scheduleIndex= 1
        outputNP, myFunc=a11.harris(im, scheduleIndex)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, filen+'-harris.png')
        
    if False:
        print "Running harris autotune"
        im=numpy.load('Input/hk.npy')
        #im=imageIO.imread('hk-small.png')
        best_sched, best_params, best_time = a11.autotuneHarris(im)
        print "Best Schedule: ", best_sched
        print "Best Time: ", best_time
        print "Best Parameters: ", best_params
Ejemplo n.º 4
0
def main():
    im=imageIO.imread('rgb.png')
    lumi=im[:,:,1] #I'm lazy, I'll just use green
    smallLumi=numpy.transpose(lumi[0:5, 0:5])

    imTest1Channel = numpy.array([[1.0, 1.0, 1.0, 1.0, 1.0],
                                  [1.0, 0.0, 0.0, 0.0, 1.0],
                                  [1.0, 0.0, 0.0, 0.0, 1.0],
                                  [1.0, 0.0, 0.0, 0.0, 1.0],
                                  [1.0, 1.0, 1.0, 1.0, 1.0]])

    imTest3Channel = numpy.array([[[1.0,1.0,1.0], [1.0,1.0,1.0]  ,[1.0,1.0,1.0]  ,[1.0,1.0,1.0]  ,[1.0,1.0,1.0]],
                                  [[1.0,1.0,1.0], [0.0, 0.0, 0.0],[0.0, 0.0, 0.0],[0.0, 0.0, 0.0],[1.0,1.0,1.0]],
                                  [[0.0,0.0,0.0], [1.0, 1.0, 1.0],[0.0, 0.0, 0.0],[0.0, 0.0, 0.0],[1.0,1.0,1.0]],
                                  [[1.0,1.0,1.0], [0.0, 0.0, 0.0],[0.0, 0.0, 0.0],[0.0, 0.0, 0.0],[1.0,1.0,1.0]],
                                  [[1.0,1.0,1.0], [1.0,1.0,1.0]  ,[1.0,1.0,1.0]  ,[1.0,1.0,1.0]  ,[1.0,1.0,1.0]]])

    # Replace if False: by if True: once you have implement the required functions. 
    # Exercises:
    if True:
        outputNP, myFunc=a11.smoothGradientNormalized()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'normalizedGradient.png')
    if True:
        outputNP, myFunc=a11.wavyRGB()
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'rgbWave.png')
    if True: 
        outputNP, myFunc=a11.sobel(lumi)
        imageIO.imwrite(outputNP, 'sobelMag.png')
        print ' Dimensionality of Halide Func:', myFunc.dimensions()

    if True: 
        L=a11.pythonCodeForBoxSchedule5(smallLumi)
        print L
    if True: 
        L=a11.pythonCodeForBoxSchedule6(smallLumi)
        print L
    if True: 
        L=a11.pythonCodeForBoxSchedule7(smallLumi)
        print L
    if True: 
        outputNP, myFunc=a11.localMax(lumi)
        #outputNP, myFunc=a11.localMax(imTest)
        print ' Dimensionality of Halide Func:', myFunc.dimensions()
        imageIO.imwrite(outputNP, 'maxi.png')
    if True: 
        input=Image(Float(32), lumi)
        x, y = Var('x'), Var('y')
        clamped = Func('clamped') 
        clamped[x, y] = input[clamp(x, 0, input.width()-1),
                             clamp(y, 0, input.height()-1)]
        blurX, finalBlur= a11.GaussianSingleChannel(clamped , sigma=2, trunc=3)
        out = finalBlur.realize(input.width(), input.height())
        outNP = numpy.array(Image(out))
        imageIO.imwrite(outNP, 'gaussianSingle.png')

    if True:
        #im=imageIO.imread('hk.png')
        im=numpy.load('Input/hk.npy')
        scheduleIndex=0

        L=[]
        t=time.time()
        outputNP, myFunc=a11.harris(im, scheduleIndex)
        t0 = time.time()-t
        L.append(t0)

        print "scheduleIndex",scheduleIndex, " harris took ", t0, " seconds"
        print ' Dimensionality of Halide Func:', myFunc.dimensions()

        hIm=Image(outputNP)
        mpix=hIm.width()*hIm.height()/1e6
        print 'best: ', numpy.min(L), 'average: ', numpy.mean(L)
        print  '%.5f ms per megapixel (%.7f ms for %d megapixels)' % (numpy.mean(L)/mpix*1e3, numpy.mean(L)*1e3, mpix)

        imageIO.imwrite(outputNP, 'harrisFinal.png')