Changeset 23

Show
Ignore:
Timestamp:
09/24/07 15:52:23 (1 year ago)
Author:
steve
Message:

Will not die if opening a non-image.
Q now exits.
New baseline imaegs which work.
New baseline image selection.
Clustering code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • config.py

    r21 r23  
    2020trash_dir = ".mactorii-trash" 
    2121text_yoffset = 3 
    22 baselines=("baseline/b1.jpg", "baseline/b2.jpg") 
     22baselines=(     #"baseline/b1.jpg", "baseline/b2.jpg", "baseline/b5.jpg", 
     23                        "baseline/b3.jpg", "baseline/b4.jpg", "baseline/b6.jpg","baseline/b7.jpg") 
    2324 
    2425def main(): 
  • mactorii.py

    r21 r23  
    2828win = None 
    2929images = dict() 
     30baselines = [] 
     31 
    3032renderables = None 
    3133 
    3234yoffset = 0 
    3335xoffset = 0 
     36xmotion = 0 
     37 
    3438rows = 1 
    35 xmotion = 0 
     39cols = 1 
    3640         
    3741clickx = 0 
     
    9397        global last_deleted 
    9498        global fps_display 
    95          
     99 
    96100        if symbol == key.LEFT: 
    97101                xmotion = 10 
     
    123127                else: 
    124128                        fps_display = clock.ClockDisplay()               
     129                         
     130        if symbol == key.C: 
     131                cluster_renderables() 
     132                 
     133        if symbol == key.Q: 
     134                exit(0) 
     135                 
    125136def strip_width(): 
    126137        """returns the width of the strip in pixels""" 
     
    133144        global xoffset 
    134145        global rows 
    135          
     146        global cols      
     147 
    136148        p = xoffset/strip_width() 
    137149         
    138150        rows = int(height/config.crop_size)  
     151        cols = math.floor(len(files)/rows)+1 
    139152         
    140153        yoffset = (height - rows * config.crop_size)/2 
     
    143156        # compute the new xoffset 
    144157        xoffset = p * strip_width() 
     158 
     159def signature_compare(sig1, sig2): 
     160        score=[] 
     161        for b in xrange(3): 
     162                score.append(config.weights[b]*len(sig1[b].intersection(sig2[b]))) 
     163                 
     164        return sum(score) 
     165         
     166def cluster_func(item): 
     167        global cols 
     168        global rows 
     169         
     170        item_sig = item[1][2] 
     171         
     172        mul = 113 
     173        score = 0 
     174        for sig in baselines: 
     175                score += signature_compare(sig, item_sig) 
     176                score*=mul 
     177                 
     178        return score 
     179         
     180def cluster_renderables(): 
     181        """cluster renderables by their score against the 2 base lines""" 
     182        global images 
     183        global renderables 
     184         
     185        renderables = images.items() 
     186         
     187        # sort the renderables 
     188        renderables.sort(key=cluster_func) 
     189         
     190        #for i, r in enumerate(renderables): 
     191                 
    145192         
    146193def update_renderables(): 
     
    153200        if selected != None: 
    154201                renderables.sort(key=sort_func) 
    155                  
    156         return renderables 
    157          
     202 
    158203def sort_func(item): 
    159204        assert selected != None 
     
    162207        item_sig = item[1][2] 
    163208         
    164         score = [] 
    165         for b in xrange(3): 
    166                 score.append(config.weights[b]*len(selected_sig[b].intersection(item_sig[b]))) 
    167         return -sum(score) 
    168  
     209        return -signature_compare(selected_sig, item_sig) 
     210 
     211def load_baseline(file): 
     212        """loads baseline pictures""" 
     213        global baselines 
     214         
     215        print "processing baseline: %s"%(file) 
     216        wi = wavelet.open(file) 
     217        sig = wi.signature() 
     218        baselines.append(sig) 
     219         
    169220def load_file(file): 
    170221        """loads the files given in the command line""" 
     
    252303        global yoffset 
    253304        global rows 
     305        global cols 
    254306        global files 
    255307        global win 
     
    264316        global fps_display 
    265317         
     318        for baseline in config.baselines: 
     319                load_baseline(baseline) 
     320                 
    266321        files = sys.argv[1:] 
    267322        for file in files: 
    268323                load_file(file) 
    269324         
    270         for baseline in config.baselines 
     325        update_renderables() 
     326                         
    271327        win = window_setup() 
    272328        ft = font_setup() 
     329        trash_setup()    
    273330         
    274331        assert win != None 
    275332        assert ft != None 
    276333         
    277         trash_setup() 
    278          
    279334        image_pattern = pyglet_image.SolidColorImagePattern((0,0,0,1)) 
    280335         
    281336        clock.set_fps_limit(30) 
    282337         
    283         renderables = update_renderables() 
    284338         
    285339        while not win.has_exit: 
  • wavelet.py

    r8 r23  
    8282                        # sort the values to determine upper and lower cut offs for significance 
    8383                        tmp.sort() 
    84                         lower = tmp[config.taps/2] 
    85                         upper = tmp[length-config.taps/2] 
     84                         
     85                        if length > config.taps: 
     86                                lower = tmp[config.taps/2] 
     87                                upper = tmp[length-config.taps/2] 
     88                        else: 
     89                                lower = tmp[length/4] 
     90                                upper = tmp[length-length/4] 
    8691                 
    8792                        # keep up to config.taps number of significant values, storing only their