Git Product home page Git Product logo

pypatchmatch's Introduction

A simple implementation of the PatchMatch Algorithm [Barnes, 2009],
with its Cython and Matlab wrapper by Gabriele Facciolo ([email protected])

PatchMatch is a randomized matching algorithm that allows to efficiently 
compute correspondece (offset) maps between two images. 


build standalone program
========================
> mkdir build; cd build
> cmake ../; make

quick test
> ./patchmatch -t SSD -w 5 ../{a,b}.png -R 300 offs.tif cost.tif backproj.png

usage: ./patchmatch [-i iter(5)] [-w patchsz(7)] [-d init_off]
        [-t patchdist={SSD(default)|SAD|ZSSD|ZSAD|NCC}]
        [-r min_off(0)] [-R max_off(10)] u v offsets [cost [backflow]]


build cython module
===================
> python setup.py build

copy module to the place where test-patchmatch.py is
> ln -s build/<lib.XXXXXXXXX-2.7>/patchmatch.so patchmatch.so

run test program
> python test-patchmatch.py


call patchmatch from python
===========================
the patchmatch interface inside patchmatch.pyx is
   def pm(np.ndarray[np.float32_t, ndim=3, mode='c'] u1,
          np.ndarray[np.float32_t, ndim=3, mode='c'] u2,
          np.ndarray[np.float32_t, ndim=3, mode='c'] nnf,
          np.ndarray[np.float32_t, ndim=2, mode='c'] cost,
          patchsz,         # patch size
          minoff,          # minimum offset
          maxoff,          # maximum offset
          n_iter=5,        # iterations
          n_rand=5,        # random trials per iteration
          method='SAD'):   # patch distance: SAD, SSD, ZSSD, ZSAD, NCC
      '''
      returns the NNF field and the COST
      '''

usage example
        import patchmatch as pm

        # read images img0,img1 as np.arrays
        ...

        # parameters
        patchSize = 7
        maxoff, minoff = 100, 30
        
        # fix input types
        img0 = img0.astype(numpy.float32)
        img1 = img1.astype(numpy.float32)

        # create output arrays (with the correct type)
        sz   = img0.shape;
        nnf  = numpy.ndarray((sz[0],sz[1],2)).astype(numpy.float32);
        cost = numpy.ndarray((sz[0],sz[1]  )).astype(numpy.float32);

        # call patchmatch
        pm.pm(img0, img1, nnf, cost, patchSize, minoff, maxoff)

        # here are the offsets
        dx = nnf[:,:,0] 
        dy = nnf[:,:,1] 


build matlab mex
================
> compileMex

run test
> a = double(imread('a.png'));
> b = double(imread('b.png'));
> [n,c] = patchmatchMex(a,b);

pypatchmatch's People

Contributors

gfacciol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.