Beispiel #1
0
def setup_tracking(moviefile, pre4):
    """Create all tracking objects."""
    # open movie
    testmovie = test_movie_for_known_movie(moviefile)
    movie = movies.Movie(testmovie, interactive=False)

    # create background model calculator
    if pre4:
        bg_model = bg_pre4.BackgroundCalculator(movie)
    else:
        bg_model = bg.BackgroundCalculator(movie)
    bg_img_shape = (movie.get_height(), movie.get_width())
    bg_model.set_buffer_maxnframes()

    # open annotation file
    ann_file = ann.AnnotationFile(annname(moviefile, pre4))
    ann_file.InitializeData()

    # calculate bg
    bg_model.OnCalculate()

    # estimate fly shapes
    havevalue = (not params.maxshape.area == 9999.)
    haveshape = (not num.isinf(params.maxshape.area))
    if (not haveshape) or (not havevalue):
        if pre4:
            params.movie = movie
            ell_pre4.est_shape(bg_model)
            params.movie = None
        else:
            ell.est_shape(bg_model)

    hindsight = hs.Hindsight(ann_file, bg_model)

    return movie, bg_model, ann_file, hindsight
    def DoAllPreprocessing(self):

        # estimate the background
        if (not self.IsBGModel()) or params.batch_autodetect_bg_model:
            print "Estimating background model"
            if params.interactive:
                self.bg_imgs.est_bg(self.frame)
            else:
                self.bg_imgs.est_bg()
        else:
            print "Not estimating background model"

        # detect arena if it has not been set yet
        if params.do_set_circular_arena and params.batch_autodetect_arena:
            print "Auto-detecting circular arena"
            setarena.doall(self.bg_imgs.center)
        else:
            print "Not detecting arena"

        self.bg_imgs.UpdateIsArena()

        # estimate the shape
        if params.batch_autodetect_shape:
            print "Estimating shape model"
            if params.interactive:
                ell.est_shape(self.bg_imgs,self.frame)
            else:
                ell.est_shape(self.bg_imgs)
        else:
            print "Not estimating shape model"
Beispiel #3
0
    def OnComputeShape(self,evt):

        start_color = self.status.GetBackgroundColour()

        if not hasattr( self.bg_imgs, 'center' ) and params.interactive:
            if params.use_median:
                algtxt = 'Median'
            else:
                algtxt = 'Mean'
            msgtxt = 'Background model has not been calculated.\nCalculate now using the following parameters?\n\nAlgorithm: %s\nNumber of Frames: %d' %(algtxt,params.n_bg_frames)
            if wx.MessageBox( msgtxt, "Calculate?", wx.OK|wx.CANCEL ) == wx.CANCEL:
                return
            else:
                # set up for running background calculation
                bg_calc = True
                self.status.SetBackgroundColour( params.status_green )
                self.status.SetStatusText( "calculating background", params.status_box )
                wx.Yield()
                self.bg_imgs.est_bg(self.frame)

        self.status.SetBackgroundColour( params.status_red )
        self.status.SetStatusText( "calculating shape", params.status_box )
        wx.BeginBusyCursor()
        wx.Yield()
        ell.est_shape( self.bg_imgs, self.frame )
        wx.EndBusyCursor()
        self.status.SetBackgroundColour( start_color )
        self.status.SetStatusText( "", params.status_box )
    def ComputeShapeNow(self,evt):

        # estimate shape now
        wx.BeginBusyCursor()
        wx.Yield()
        succeeded = ell.est_shape( self.bg_imgs,self.frame )
        wx.EndBusyCursor()
        
        if not succeeded:
          return

        # copy to temporary variable
        self.automatic_minshape = params.params.minshape.copy()
        self.automatic_maxshape = params.params.maxshape.copy()
        self.automatic_meanshape = params.params.meanshape.copy()

        # show shape
        self.PrintShape()

        # set up to date
        self.shape_uptodate = True
        self.automatic_shape_text.SetLabel('')
        self.RegisterParamChange()

        self.ShowImage()
Beispiel #5
0
    def ComputeShapeNow(self, evt):

        # estimate shape now
        wx.BeginBusyCursor()
        wx.Yield()
        succeeded = ell.est_shape(self.bg_imgs, self.frame)
        wx.EndBusyCursor()

        if not succeeded:
            return

        # copy to temporary variable
        self.automatic_minshape = params.params.minshape.copy()
        self.automatic_maxshape = params.params.maxshape.copy()
        self.automatic_meanshape = params.params.meanshape.copy()

        # show shape
        self.PrintShape()

        # set up to date
        self.shape_uptodate = True
        self.automatic_shape_text.SetLabel('')
        self.RegisterParamChange()

        self.ShowImage()
Beispiel #6
0
    def CheckForShapeModel(self):

        # already have computed the shape model
        if params.have_computed_shape:
            return True

        haveshape = num.isinf(params.maxshape.area) == False

        # have read in the shape model
        if (params.movie_name == params.annotation_movie_name) and haveshape:
            return True

        # in non-interactive mode, automatically do the computation
        if params.interactive == False:
            # do the calculation
            ell.est_shape( self.bg_imgs )
            return True

        # ask what to do
        if haveshape:
            msgtxt = 'Shape model has not been automatically computed for this movie. Currently:\n\nMin Area = %.2f\nMax Area = %.2f\n\nDo you want to automatically compute now with the following parameters?\n\nNumber of Frames: %d\nNumber of Standard Deviations: %.2f'%(params.minshape.area,params.maxshape.area,params.n_frames_size,params.n_std_thresh)
        else:
            msgtxt = 'Shape is currently unbounded. Do you want to automatically compute now with the following parameters?\n\nNumber of Frames: %d\nNumber of Standard Deviations: %.2f'%(params.n_frames_size,params.n_std_thresh)
        resp = wx.MessageBox( msgtxt, "Calculate?", wx.YES_NO|wx.CANCEL )
        if resp == wx.NO:
            return True
        elif resp == wx.CANCEL:
            return False

        # set up for running shape calculation
        if self.status is not None:
            start_color = self.status.GetBackgroundColour()
            self.status.SetBackgroundColour( params.status_blue )
            self.status.SetStatusText( "calculating shape", params.status_box )
        wx.BeginBusyCursor()
        wx.Yield()

        # do the calculation
        ell.est_shape(self.bg_imgs)

        # return to normal
        if self.status is not None:
            self.status.SetBackgroundColour( start_color )
            self.status.SetStatusText('',params.status_box)
        wx.EndBusyCursor()

        return True
    def set_shape_method( self ):
        """A shape-computation method was selected. Take action."""
        params.enforce_minmax_shape = True
        selection = self.get_radio_control_selection()
        if selection == 0:
            # don't use shape bounds
            params.enforce_minmax_shape = False
            self.show_shape_results()

        elif selection == 1:
            # auto-compute shape
            wx.BeginBusyCursor()
            wx.Yield()
            self.remember_button_states()
            success = est_shape( self.bg, self.frame )
            self.reset_button_states()
            wx.EndBusyCursor()

            if success:
                self.show_shape_results()
            else:
                self.OnPrevButton( None )

        elif selection == 2:
            # launch settings for manual shape setting
            self.prev_button.Enable( False )
            self.next_button.Enable( False )

            self.tracking_settings = TrackingSettings( self.frame, self.bg, 0 )
            self.tracking_settings.frame.Bind( wx.EVT_CLOSE, self.OnQuitTrackingSettings )
            self.tracking_settings.frame.Bind( wx.EVT_BUTTON, self.OnQuitTrackingSettings, id=xrc.XRCID("done") )
            self.tracking_settings.frame.Show()

            # hack to switch dialog to manual settings
            self.tracking_settings.automatic_shape_input.SetValue( False )
            self.tracking_settings.manual_shape_input.SetValue( True )
            self.tracking_settings.OnAutomatic( None )