[ create a new paste ] login | about

Link: http://codepad.org/Qj2A0Dm0    [ raw code | fork ]

Python, pasted on Jan 21:
import sys                                                                      
import os                                                                       
                                                                                
import numpy as np                                                              
import scipy, scipy.misc                                                        
from scipy import ndimage                                                       
import matplotlib.pyplot as plt                                                 
                                                                                
if __name__ == '__main__':                                                      
                                                                                
    #for dir in range(1,14):                                                    
    for dir in range(1,2):                                                      
        dir = str(dir)                                                          
                                                                                
        total_images = len(os.listdir(dir))+1                                   
        points_sob = []                                                         
                                                                                
        for i in range(1,total_images):                                         
            im = scipy.misc.imread(dir+'/'+str(i)+'.jpg')                       
            im = im.astype('int32')                                             
            dx = ndimage.sobel(im, 0)  # horizontal derivative                  
            dy = ndimage.sobel(im, 1)  # vertical derivative                    
            mag = np.hypot(dx, dy)     # magnitude                              
            mag *= 255.0 / np.max(mag) # normalize (Q&D)                        
                                                                                
            points_sob.append(np.sum(mag))                                      
                                                                                
        x = range(1,total_images)                                               
        res = np.argmin(points_sob)+1                                           
        print res                                                               
        plt.plot(res,points_sob[res-1], marker='o', color='r', ls='')           
        plt.plot(x, points_sob)                                                 
                                                                                
        plt.savefig(dir+'.png')                                                 
        plt.show()


Create a new paste based on this one


Comments: