예제 #1
0
파일: main.py 프로젝트: hagisgit/SLIC
class SlicApp(App):

    slic = ObjectProperty(None)
    img_loaded = ObjectProperty(False)
    img_segmented = ObjectProperty(False)
    title = 'Image SLIC 0.1'
    

    def open_click(self):
        self.root.ids.display.clear_widgets()
        self.root.ids.display.add_widget(LoadDialog())

    def save_click(self):
        self.root.ids.display.clear_widgets()
        self.root.ids.display.add_widget(SaveDialog())

    def cancel(self):
        self.root.ids.display.clear_widgets()
        if not (self.slic == None):
            img = Image(source=self.slic.filename)
            img.id = 'disp_img'
            self.root.ids.display.add_widget(img)
            self.img_loaded = True

    def load(self, path, selection):
        if not selection[0] == '':
            self.slic = Slic(selection[0])
            self.root.ids.display.clear_widgets()
            img = Image(source=selection[0])
            img.id = 'disp_img'
            self.root.ids.display.add_widget(img)
            self.img_loaded = True

    def save(self, path, filename):
        self.slic.save(fn=path + '/' + filename)
    
    def segment(self, num_seg, comp):
        if self.slic == None:
            print 'No image loaded.'
            return
        self.slic.reload_orig()
        self.t = Thread(target=self.do_seg, args=(int(num_seg), int(comp)))
        self.t.start()
    
    def do_seg(self, num_seg, comp):        
        self.slic.reload_orig()
        self.slic.segment(int(num_seg), int(comp))
        self.img_segmented = True
        Clock.schedule_once(self.update_canvas)
    
    @mainthread
    def update_canvas(self, *args):
        self.root.ids.display.children[0].texture.blit_buffer(pbuffer=self.slic.rgb.flatten())
        self.root.ids.display.children[0].canvas.ask_update()        

    def mark_borders(self):
        if self.t.is_alive():
            print 'not done yet'
            return
        if self.slic == None:
            print 'No image loaded.'
            return
        elif self.img_segmented == False:
            print 'Image not segmented yet.'
            return
        self.slic.mark_border()
        self.root.ids.display.children[0].texture.blit_buffer(pbuffer=self.slic.rgb.flatten())
        self.root.ids.display.children[0].canvas.ask_update()

    def make_mean(self):
        if self.slic == None:
            print 'No image loaded.'
            return
        elif self.img_segmented == False:
            print 'Image not segmented yet.'
            return
        self.slic.reload_orig()
        self.slic.make_mean()
        self.root.ids.display.children[0].texture.blit_buffer(pbuffer=self.slic.rgb.flatten())
        self.root.ids.display.children[0].canvas.ask_update()
예제 #2
0
파일: slic_test.py 프로젝트: hagisgit/SLIC
"""
Created on Sun Jan 31 20:24:44 2016

@author: Hagen
"""
from numcl import _ctrl

#_ctrl.device_cpu()
from slic import Slic
import timeit

segruns = 1

colors = ((210,210,255), (230,230,255), (230,230,255), (200,200,200), (10,10,10), (250,250,250), (50,50,50), (100,100,150))

fn = '/Users/Hagen/Desktop/Blumen.png'              
test = Slic(fn)
t = 0.
for i in range(segruns):
    t0 = timeit.default_timer()
    test.segment(1000, 1)
    t1 = timeit.default_timer()
    t += t1 - t0
    print t1 - t0
print t/segruns   

#test.mark_border()
test.make_mean() 
test.colorize(colors) 
#test.show()
test.save()