'm_scale' : 1,
                          'total_runs' : 10,
                          'max_itters' : 1000,
                          'min_cluster_size': 25,
                          'sigma' : 3
                         },            

}
m_regular_SLIC = 1

if __name__ == '__main__':
    multiprocessing.freeze_support()
    #data_management.tee_out()
    
    import os
    ctx = opencl_tools.get_a_context()

    
    #From http://stackoverflow.com/questions/3579568/choosing-a-file-in-python-simple-gui
    from Tkinter import Tk
    from tkFileDialog import askopenfilename, asksaveasfilename
    
    Tk().withdraw()
    file_name = askopenfilename(filetypes=[('image file','*.jpg *.png *.bmp *.tif')])

    if(file_name is None or len(file_name) == 0 ):
        import sys;
        print("Uses quit without selecting a file");
        sys.exit(0);
        
コード例 #2
0
    def __init__(self, image, queue=None):
        self._image = image

        if (queue is None):
            self._queue = cl.CommandQueue(
                opencl_tools.get_a_context(),
                properties=opencl_tools.profile_properties)
        else:
            self._queue = queue

        self._blocksize = 128

        preamble = """
            #define IMAGE_ROWS %d
            #define IMAGE_COLS %d
            #define NUMBER_COLORS %d
            #define recalculate_centers_blocksize %d
            #define count_center_table_locations_blocksize %d
        """ % (image.shape + (self._blocksize, self._blocksize))

        preamble = opencl_tools.build_preamble_for_context\
                                        (self._queue.context,preamble)

        prg = cl.Program(self._queue.context,
                         preamble + _SLIC_kernal_code).build()

        self._find_best_center = prg.find_best_center
        self._find_best_center.set_scalar_arg_dtypes([
            None,  #float* image_data, 
            None,  #float* location_center,
            None,  #float* color_center, 
            None,  #__global int* center_table_locations,
            None,  #__global int* center_table,
            np.int32,  #int number_of_centers, 
            np.float32,  #float S, 
            np.float32,  #float m,
            None,  #int* cluster_index,
            None,  #float* cluaster_distance
        ])

        self._recalculate_centers = prg.recalculate_centers
        self._recalculate_centers.set_scalar_arg_dtypes([
            None,  #float* image_data,
            None,  #int* cluster_index,
            np.float32,  #float S, 
            np.float32,  #float m, 
            np.int32,  #int number_of_clusters,
            None,  #float* location_center, 
            None,  #float* color_center,
            None
        ])

        self._count_center_table_locations = prg.count_center_table_locations
        self._count_center_table_locations.set_scalar_arg_dtypes([
            None,  #__global float* location_center,
            np.float32,  #float S,
            np.int32,  #int number_of_clusters,
            None,  #__global int* center_table_locations
        ])
        self._center_table_placement = cl_scan.InclusiveScanKernel(
            self._queue.context, np.int32, 'a+b', neutral='0')

        self._create_center_table = prg.create_center_table
        self._create_center_table.set_scalar_arg_dtypes([
            None,  #__global float* location_center,
            None,  #__global int* center_table_locations
            np.float32,  #float S,
            np.int32,  #int number_of_clusters,
            None  #__global float* center_table
        ])

        self._remove_points = prg.remove_points
コード例 #3
0
        'total_runs': 1,
        'max_itters': 1000,
        'min_cluster_size': 25,
        'sigma': 3
    },
}

m_regular_SLIC = 1

if __name__ == '__main__':
    multiprocessing.freeze_support()

    import time
    import glob
    import os
    ctx = opencl_tools.get_a_context()

    #    #Create an experiment
    #    data_management.create_experiment("eage_aware_editing");
    #
    #    #add the source files
    #    source_files = glob.glob(os.path.join(os.path.dirname(__file__),'*.py'))
    #    dest_files = [os.path.join('source_files',os.path.basename(fi))
    #                                                    for fi in source_files ]
    #    data_management.current_experiment().add_files(zip(source_files,dest_files))
    #
    #    source_files = glob.glob(os.path.join(os.path.dirname(__file__),'diffution_system','*.py'))
    #    dest_files = [os.path.join('source_files','diffution_system',os.path.basename(fi))
    #                                                     for fi in source_files ]
    #    data_management.current_experiment().add_files(zip(source_files,dest_files))
コード例 #4
0
    def __init__(self,image,queue=None):
        self._image = image

        if(queue is None):
            self._queue = cl.CommandQueue(opencl_tools.get_a_context(),properties=opencl_tools.profile_properties)
        else:
            self._queue =  queue
            
        self._blocksize = 128;
        
        
        
        preamble = """
            #define IMAGE_ROWS %d
            #define IMAGE_COLS %d
            #define NUMBER_COLORS %d
            #define recalculate_centers_blocksize %d
            #define count_center_table_locations_blocksize %d
        """ % (image.shape + (self._blocksize,self._blocksize))
        
        preamble = opencl_tools.build_preamble_for_context\
                                        (self._queue.context,preamble)
        
        prg = cl.Program(self._queue.context,preamble + _SLIC_kernal_code).build();
        
        self._find_best_center = prg.find_best_center
        self._find_best_center.set_scalar_arg_dtypes([
                                                None, #float* image_data, 
                                                None, #float* location_center,
                                                None, #float* color_center, 
                                                None, #__global int* center_table_locations,
                                                None, #__global int* center_table,
                                                np.int32, #int number_of_centers, 
                                                np.float32, #float S, 
                                                np.float32, #float m,
                                                None, #int* cluster_index,
                                                None, #float* cluaster_distance
                                            ])
                                

        self._recalculate_centers = prg.recalculate_centers
        self._recalculate_centers.set_scalar_arg_dtypes([
                                                None, #float* image_data,
                                                None, #int* cluster_index,
                                                np.float32, #float S, 
                                                np.float32, #float m, 
                                                np.int32, #int number_of_clusters,
                                                None, #float* location_center, 
                                                None, #float* color_center,
                                                None
                                            ]) 

        self._count_center_table_locations = prg.count_center_table_locations
        self._count_center_table_locations.set_scalar_arg_dtypes([
                                               None,#__global float* location_center,
                                               np.float32,#float S,
                                               np.int32,#int number_of_clusters,
                                               None,#__global int* center_table_locations
                                            ])  
        self._center_table_placement = cl_scan.InclusiveScanKernel(self._queue.context,
                                                                   np.int32,
                                                                   'a+b',
                                                                   neutral='0')
          

        self._create_center_table = prg.create_center_table
        self._create_center_table.set_scalar_arg_dtypes([
                                                None,#__global float* location_center,
                                                None,#__global int* center_table_locations
                                                np.float32,#float S,
                                                np.int32,#int number_of_clusters,
                                                None#__global float* center_table
                                            ])  
                                            
        self._remove_points = prg.remove_points