~bertrand-nouvel/pycvf-keypoints/trunk

« back to all changes in this revision

Viewing changes to nodes/harris.py

  • Committer: tranx
  • Date: 2010-10-01 16:56:14 UTC
  • Revision ID: tranx@havane-20101001165614-u938mdd1y1fgd0o5
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#########################################################################################################################################
 
3
#
 
4
# MyNode By Bertrand NOUVEL
 
5
# 2009 CNRS Postdoctorate JFLI
 
6
#
 
7
# (c) All rights reserved
 
8
# ###############################################
 
9
#
 
10
################################################################################################################################################################################
 
11
# Includes
 
12
################################################################################################################################################################################
 
13
 
 
14
 
 
15
###
 
16
###
 
17
 
 
18
 
 
19
from pycvf.core import genericnode
 
20
from pycvf.datatypes import generic
 
21
from pycvfext.image.datatypes import image
 
22
import numpy,scipy,scipy.ndimage
 
23
from pycvfext.image.nodes.harris import harris, harris_smooth
 
24
 
 
25
def showkkp(im,nb=100, *args,**kwargs):
 
26
   ags=scipy.argsort(harris(im,*args,**kwargs).ravel())[-nb:]
 
27
   im=im[:,:,numpy.newaxis].repeat(3,axis=2)
 
28
   im/=im.max()
 
29
   for p in ags:
 
30
     y,x=p//im.shape[1],p%im.shape[1]
 
31
     im[max(0,y-1):y+1,max(0,x-1):x+1,0]=1
 
32
     im[max(0,y-1):y+1,max(0,x-1):x+1,1]=0
 
33
     im[max(0,y-1):y+1,max(0,x-1):x+1,2]=0
 
34
   pyplot.imshow(im)
 
35
 
 
36
class Node(genericnode.Node):
 
37
        def input_datatype(self,x):
 
38
            assert(isinstance(x,image.Datatype()) or issubclass(x,image.Datatype()))
 
39
            return image.Datatype()
 
40
        def output_datatype(self,x):
 
41
            return generic.Datatype
 
42
        def init_model(self,nb=100,variant="",*args,**kwargs):
 
43
                 self.processline='src|harris'
 
44
                 f=eval("harris"+variant)
 
45
                 self.context['harris']=lambda x:map(lambda p:(p//x.shape[1],p%x.shape[1],2) ,scipy.argsort(numpy.abs(f(x,*args,**kwargs)).ravel())[-nb:])
 
46
 
 
47
__call__=Node