Beispiel #1
0
def annotate_image(ellipses=None,
                   old_pts=None,
                   thickness=params.ellipse_thickness):
    """Return points corresponding to drawn ellipses."""

    # draw ellipses
    if ellipses is None:
        linesegs = []
    else:
        linesegs = draw_ellipses(ellipses)

    # draw tails
    if old_pts is not None:

        prevpts = {}
        for frame_pts in old_pts:
            for pt in frame_pts:
                if prevpts.has_key(pt[2]):
                    prevpt = prevpts[pt[2]]
                    color = params.colors[pt[2] % len(params.colors)]
                    linesegs.append([
                        prevpt[0] + 1, prevpt[1] + 1, pt[0] + 1, pt[1] + 1,
                        color
                    ])
                prevpts[pt[2]] = pt[0:2]

    return linesegs
Beispiel #2
0
def annotate_image( ellipses=None, old_pts=None, thickness=params.ellipse_thickness ):
    """Return points corresponding to drawn ellipses."""

    # draw ellipses
    if ellipses is None:
        linesegs = []
    else:
        linesegs = draw_ellipses( ellipses )

    # draw tails
    if old_pts is not None:

        prevpts = {}
        for frame_pts in old_pts:
            for pt in frame_pts:
                if prevpts.has_key(pt[2]):
                    prevpt = prevpts[pt[2]]
                    color = params.colors[pt[2]%len(params.colors)]
                    linesegs.append([prevpt[0]+1,prevpt[1]+1,
                                     pt[0]+1,pt[1]+1,color])
                prevpts[pt[2]] = pt[0:2]

    return linesegs
    def get_sub_image( self, sub_type, framenumber ):
        """Do background subtraction and return a particular image type."""
        wx.BeginBusyCursor()
        try: wx.Yield()
        except: pass # sometimes complains about recursive Yield()
        
        # do background subtraction if necessary
        if sub_type in [params.SHOW_DISTANCE,params.SHOW_THRESH,
                        params.SHOW_CC,params.SHOW_ELLIPSES,
                        params.SHOW_BACKGROUND,params.SHOW_DEV,
                        params.SHOW_BG_AND_DIST]:
            (dfore,bw,cc,ncc) = self.sub_bg( framenumber )   # sets self.on, etc.
        else:
            if hasattr( self, 'dfore' ):
                dfore = self.dfore
                bw = self.bw
                cc = self.cc
                ncc = self.ncc
            else:
                dfore = None
                bw = None
                cc = None
                ncc = None

        line_segs = []
        line_clrs = []
        img_format = None

        # format image in "subtraction type"
        if sub_type == params.SHOW_BACKGROUND:
            cntr = self.centers[self.on] if self.varying_bg else self.center
            img_8 = imagesk.double2mono8(cntr,donormalize=False)
            img_format = 'MONO8'
            preview_range = (0,255)
        elif sub_type == params.SHOW_DISTANCE:
            img_8 = imagesk.double2mono8(dfore)
            img_format = 'MONO8'
            preview_range = (dfore.min(), dfore.max())
        elif sub_type == params.SHOW_THRESH:
            img_8 = imagesk.double2mono8(bw.astype(float))
            img_format = 'MONO8'
            preview_range = (0,1)
        elif sub_type == params.SHOW_NONFORE:
            isnotarena = (self.isarena == False)
            img_8 = imagesk.double2mono8(isnotarena.astype(float))
            img_format = 'MONO8'
            preview_range = (0,1)
        elif sub_type == params.SHOW_DEV:
            dev = self.devs[self.on] if self.varying_bg else self.dev
            mu = num.mean(dev)
            sig = num.std(dev)
            if sig == 0:
                img_8 = imagesk.double2mono8(dev)
                n1 = mu
                n2 = mu
            else:
                n1 = max(0,mu - 3.*sig)
                n2 = mu + 3.*sig
                img_8 = imagesk.double2mono8(dev.clip(n1,n2))
            img_format = 'MONO8'
            preview_range = (n1,n2)
        elif sub_type == params.SHOW_CC:
            img_8,clim = colormap_image(cc)
            img_format = 'RGB8'
            preview_range = clim
        elif sub_type == params.SHOW_ELLIPSES:
            # find ellipse observations
            obs = find_ellipses(dfore,cc,ncc,False)
            im, stamp = params.movie.get_frame( int(framenumber) )
            img_8 = imagesk.double2mono8(im,donormalize=False)
            plot_linesegs = draw_ellipses(obs)
            (linesegs,linecolors) = \
                imagesk.separate_linesegs_colors(plot_linesegs)
            img_8 = imagesk.double2mono8(im,donormalize=False)
            img_format = 'MONO8'
            preview_range = (0,255)
            line_segs.extend( linesegs )
            line_clrs.extend( linecolors )
        elif sub_type == params.SHOW_BG_AND_DIST:
            cntr = self.centers[self.on] if self.varying_bg else self.center
            img = Image.fromarray(imagesk.double2mono8(cntr,donormalize=False)).convert('RGB')
            img.paste((0,255,0), None, Image.fromarray(imagesk.double2mono8(dfore)))
            img_8 = num.array(img)
            img_format = 'RGB8'
            preview_range = (0,255)
        elif sub_type in params.SHOW_EXPBGFGMODEL: 
            # check for expbgfgmodel
            if not params.use_expbgfgmodel or not hasattr(self,'expbgfgmodel') or \
            self.expbgfgmodel is None:
                resp = wx.MessageBox("No prior model loaded.","No prior model loaded",wx.OK)
            else:
                if sub_type == params.SHOW_EXPBGFGMODEL_LLR:
                    # read the current image, classify pixels
                    im, stamp = params.movie.get_frame( int(framenumber) )
                    llr = self.expbgfgmodel_llr(im)
                    img_8,clim = colormap_image(llr)
                    img_format = 'RGB'
                    preview_range = clim
                elif sub_type == params.SHOW_EXPBGFGMODEL_ISBACK:
                    im, stamp = params.movie.get_frame( int(framenumber) )
                    isback = self.thresh_expbgfgmodel_llr(im)
                    img_8 = imagesk.double2mono8(isback.astype(float))
                    img_format = 'MONO8'
                    preview_range = (0,1)
                elif sub_type == params.SHOW_EXPBGFGMODEL_BGMU:
                    img_8 = imagesk.double2mono8(self.expbgfgmodel.bg_mu,donormalize=False)
                    img_format = 'MONO8'
                    preview_range = (0,255)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FGMU:
                    img_8 = imagesk.double2mono8(self.expbgfgmodel.fg_mu,donormalize=False)
                    img_format = 'MONO8'
                    preview_range = (0,255)
                elif sub_type == params.SHOW_EXPBGFGMODEL_BGSIGMA:
                    mu = num.mean(self.expbgfgmodel.bg_sigma)
                    sig = num.std(self.expbgfgmodel.bg_sigma)
                    if sig == 0:
                        n1 = mu
                        n2 = mu
                        img_8 = imagesk.double2mono8(self.expbgfgmodel.bg_sigma)
                    else:
                        n1 = max(0,mu - 3.*sig)
                        n2 = mu + 3.*sig
                        img_8 = imagesk.double2mono8(self.expbgfgmodel.bg_sigma.clip(n1,n2))
                    img_format = 'MONO8'
                    preview_range = (n1,n2)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FGSIGMA:
                    mu = num.mean(self.expbgfgmodel.fg_sigma)
                    sig = num.std(self.expbgfgmodel.fg_sigma)
                    if sig == 0:
                        img_8 = imagesk.double2mono8(self.expbgfgmodel.fg_sigma)
                        n1 = mu
                        n2 = mu
                    else:
                        n1 = max(0,mu - 3.*sig)
                        n2 = mu + 3.*sig
                        img_8 = imagesk.double2mono8(self.expbgfgmodel.fg_sigma.clip(n1,n2))
                    img_format = 'MONO8'
                    preview_range = (n1,n2)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FRACFRAMESISBACK:
                    if not hasattr(self,'fracframesisback') or self.fracframesisback is None:
                        resp = wx.MessageBox("fracframesisback not yet computed","fracframesisback Not Computed",wx.OK)
                        return
                    img_8,clim = colormap_image(self.fracframesisback)
                    img_format = 'RGB8'
                    preview_range = clim
                elif sub_type == params.SHOW_EXPBGFGMODEL_MISSINGDATA:
                    if not hasattr(self,'fracframesisback') or self.fracframesisback is None:
                        resp = wx.MessageBox("fracframesisback not yet computed","fracframesisback Not Computed",wx.OK)
                        return
                    missingdata = self.fracframesisback <= params.min_frac_frames_isback
                    img_8 = imagesk.double2mono8(missingdata.astype(float))
                    img_format = 'MONO8'
                    preview_range = (0,1)

        wx.EndBusyCursor()

        return img_8, img_format, line_segs, line_clrs, dfore, bw, cc, ncc, preview_range
Beispiel #4
0
    def get_sub_image(self, sub_type, framenumber):
        """Do background subtraction and return a particular image type."""
        wx.BeginBusyCursor()
        try:
            wx.Yield()
        except:
            pass  # sometimes complains about recursive Yield()

        # do background subtraction if necessary
        if sub_type in [
                params.SHOW_DISTANCE, params.SHOW_THRESH, params.SHOW_CC,
                params.SHOW_ELLIPSES, params.SHOW_BACKGROUND, params.SHOW_DEV,
                params.SHOW_BG_AND_DIST
        ]:
            (dfore, bw, cc,
             ncc) = self.sub_bg(framenumber)  # sets self.on, etc.
        else:
            if hasattr(self, 'dfore'):
                dfore = self.dfore
                bw = self.bw
                cc = self.cc
                ncc = self.ncc
            else:
                dfore = None
                bw = None
                cc = None
                ncc = None

        line_segs = []
        line_clrs = []
        img_format = None

        # format image in "subtraction type"
        if sub_type == params.SHOW_BACKGROUND:
            cntr = self.centers[self.on] if self.varying_bg else self.center
            img_8 = imagesk.double2mono8(cntr, donormalize=False)
            img_format = 'MONO8'
            preview_range = (0, 255)
        elif sub_type == params.SHOW_DISTANCE:
            img_8 = imagesk.double2mono8(dfore)
            img_format = 'MONO8'
            preview_range = (dfore.min(), dfore.max())
        elif sub_type == params.SHOW_THRESH:
            img_8 = imagesk.double2mono8(bw.astype(float))
            img_format = 'MONO8'
            preview_range = (0, 1)
        elif sub_type == params.SHOW_NONFORE:
            isnotarena = (self.isarena == False)
            img_8 = imagesk.double2mono8(isnotarena.astype(float))
            img_format = 'MONO8'
            preview_range = (0, 1)
        elif sub_type == params.SHOW_DEV:
            dev = self.devs[self.on] if self.varying_bg else self.dev
            mu = num.mean(dev)
            sig = num.std(dev)
            if sig == 0:
                img_8 = imagesk.double2mono8(dev)
                n1 = mu
                n2 = mu
            else:
                n1 = max(0, mu - 3. * sig)
                n2 = mu + 3. * sig
                img_8 = imagesk.double2mono8(dev.clip(n1, n2))
            img_format = 'MONO8'
            preview_range = (n1, n2)
        elif sub_type == params.SHOW_CC:
            img_8, clim = colormap_image(cc)
            img_format = 'RGB8'
            preview_range = clim
        elif sub_type == params.SHOW_ELLIPSES:
            # find ellipse observations
            obs = find_ellipses(dfore, cc, ncc, False)
            im, stamp = params.movie.get_frame(int(framenumber))
            img_8 = imagesk.double2mono8(im, donormalize=False)
            plot_linesegs = draw_ellipses(obs)
            (linesegs,linecolors) = \
                imagesk.separate_linesegs_colors(plot_linesegs)
            img_8 = imagesk.double2mono8(im, donormalize=False)
            img_format = 'MONO8'
            preview_range = (0, 255)
            line_segs.extend(linesegs)
            line_clrs.extend(linecolors)
        elif sub_type == params.SHOW_BG_AND_DIST:
            cntr = self.centers[self.on] if self.varying_bg else self.center
            img = Image.fromarray(imagesk.double2mono8(
                cntr, donormalize=False)).convert('RGB')
            img.paste((0, 255, 0), None,
                      Image.fromarray(imagesk.double2mono8(dfore)))
            img_8 = num.array(img)
            img_format = 'RGB8'
            preview_range = (0, 255)
        elif sub_type in params.SHOW_EXPBGFGMODEL:
            # check for expbgfgmodel
            if not params.use_expbgfgmodel or not hasattr(self,'expbgfgmodel') or \
            self.expbgfgmodel is None:
                resp = wx.MessageBox("No prior model loaded.",
                                     "No prior model loaded", wx.OK)
            else:
                if sub_type == params.SHOW_EXPBGFGMODEL_LLR:
                    # read the current image, classify pixels
                    im, stamp = params.movie.get_frame(int(framenumber))
                    llr = self.expbgfgmodel_llr(im)
                    img_8, clim = colormap_image(llr)
                    img_format = 'RGB'
                    preview_range = clim
                elif sub_type == params.SHOW_EXPBGFGMODEL_ISBACK:
                    im, stamp = params.movie.get_frame(int(framenumber))
                    isback = self.thresh_expbgfgmodel_llr(im)
                    img_8 = imagesk.double2mono8(isback.astype(float))
                    img_format = 'MONO8'
                    preview_range = (0, 1)
                elif sub_type == params.SHOW_EXPBGFGMODEL_BGMU:
                    img_8 = imagesk.double2mono8(self.expbgfgmodel.bg_mu,
                                                 donormalize=False)
                    img_format = 'MONO8'
                    preview_range = (0, 255)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FGMU:
                    img_8 = imagesk.double2mono8(self.expbgfgmodel.fg_mu,
                                                 donormalize=False)
                    img_format = 'MONO8'
                    preview_range = (0, 255)
                elif sub_type == params.SHOW_EXPBGFGMODEL_BGSIGMA:
                    mu = num.mean(self.expbgfgmodel.bg_sigma)
                    sig = num.std(self.expbgfgmodel.bg_sigma)
                    if sig == 0:
                        n1 = mu
                        n2 = mu
                        img_8 = imagesk.double2mono8(
                            self.expbgfgmodel.bg_sigma)
                    else:
                        n1 = max(0, mu - 3. * sig)
                        n2 = mu + 3. * sig
                        img_8 = imagesk.double2mono8(
                            self.expbgfgmodel.bg_sigma.clip(n1, n2))
                    img_format = 'MONO8'
                    preview_range = (n1, n2)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FGSIGMA:
                    mu = num.mean(self.expbgfgmodel.fg_sigma)
                    sig = num.std(self.expbgfgmodel.fg_sigma)
                    if sig == 0:
                        img_8 = imagesk.double2mono8(
                            self.expbgfgmodel.fg_sigma)
                        n1 = mu
                        n2 = mu
                    else:
                        n1 = max(0, mu - 3. * sig)
                        n2 = mu + 3. * sig
                        img_8 = imagesk.double2mono8(
                            self.expbgfgmodel.fg_sigma.clip(n1, n2))
                    img_format = 'MONO8'
                    preview_range = (n1, n2)
                elif sub_type == params.SHOW_EXPBGFGMODEL_FRACFRAMESISBACK:
                    if not hasattr(self, 'fracframesisback'
                                   ) or self.fracframesisback is None:
                        resp = wx.MessageBox(
                            "fracframesisback not yet computed",
                            "fracframesisback Not Computed", wx.OK)
                        return
                    img_8, clim = colormap_image(self.fracframesisback)
                    img_format = 'RGB8'
                    preview_range = clim
                elif sub_type == params.SHOW_EXPBGFGMODEL_MISSINGDATA:
                    if not hasattr(self, 'fracframesisback'
                                   ) or self.fracframesisback is None:
                        resp = wx.MessageBox(
                            "fracframesisback not yet computed",
                            "fracframesisback Not Computed", wx.OK)
                        return
                    missingdata = self.fracframesisback <= params.min_frac_frames_isback
                    img_8 = imagesk.double2mono8(missingdata.astype(float))
                    img_format = 'MONO8'
                    preview_range = (0, 1)

        wx.EndBusyCursor()

        return img_8, img_format, line_segs, line_clrs, dfore, bw, cc, ncc, preview_range
Beispiel #5
0
    def ShowImage(self):

        if DEBUG_TRACKINGSETTINGS: print 'ShowImage ' + str(self.show_frame)

        try:
            wx.Yield()
        except:
            pass  # can be recursive sometimes in Windows
        wx.BeginBusyCursor()
        im, stamp = self.bg_imgs.movie.get_frame(int(self.show_frame))

        windowsize = [
            self.img_panel.GetRect().GetHeight(),
            self.img_panel.GetRect().GetWidth()
        ]

        self.GetBgImage()

        if self.img_chosen == SHOW_UNFILTERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_UNFILTERED_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            plot_linesegs = draw_ellipses(obs_unfiltered)

        elif self.img_chosen == SHOW_FILTERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_FILTERED_OBSERVATIONS'
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = draw_ellipses(obs_filtered)

        elif self.img_chosen == SHOW_SMALL_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_SMALL_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            obs_small = []
            for obs in obs_unfiltered:
                if obs.area() < params.params.minshape.area:
                    obs_small.append(obs)
            plot_linesegs = draw_ellipses(obs_small)

        elif self.img_chosen == SHOW_LARGE_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_LARGE_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            obs_large = []
            for obs in obs_unfiltered:
                if obs.area() > params.params.maxshape.area:
                    obs_large.append(obs)
            plot_linesegs = draw_ellipses(obs_large)

        elif self.img_chosen == SHOW_DELETED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_DELETED_OBSERVATIONS'
            (obs_unfiltered, obs_deleted) = self.GetObsUnfiltered('diddelete')
            plot_linesegs = draw_ellipses(obs_deleted)

        elif self.img_chosen == SHOW_SPLIT_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_SPLIT_OBSERVATIONS'
            (obs_unfiltered, obs_split) = self.GetObsUnfiltered('didsplit')
            plot_linesegs = draw_ellipses(obs_split)

        elif self.img_chosen == SHOW_MERGED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MERGED_OBSERVATIONS'
            (obs_unfiltered, obs_merge) = self.GetObsUnfiltered('didmerge')
            plot_linesegs = draw_ellipses(obs_merge)

        elif self.img_chosen == SHOW_LOWERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_LOWERED_OBSERVATIONS'
            (obs_unfiltered,
             obs_lowered) = self.GetObsUnfiltered('didlowerthresh')
            plot_linesegs = draw_ellipses(obs_lowered)

        # MAXJUMP
        elif self.img_chosen == SHOW_MAXJUMP:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MAXJUMP'

            # either grab or compute observations
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = draw_ellipses(obs_filtered)

            # draw circles
            for i, obs in enumerate(obs_filtered):
                plot_new_stuff = imagesk.draw_circle(
                    obs.center.x, obs.center.y, params.params.max_jump * 2.,
                    params.params.colors[i % len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)
                plot_new_stuff = imagesk.draw_circle(
                    obs.center.x, obs.center.y, params.params.min_jump,
                    params.params.colors[i % len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)

        elif self.img_chosen == SHOW_MOTIONMODEL:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MOTIONMODEL'

            (target_prev, target_curr, target_pred) = self.GetTargetMotion()

            # show the next frame, if there is one
            nextframe = num.minimum(int(self.show_frame + 1),
                                    params.params.n_frames - 1)
            im, stamp = self.bg_imgs.movie.get_frame(nextframe)

            # draw previous positions
            plot_linesegs = draw_ellipses(target_prev)

            # draw current positions
            plot_new_stuff = draw_ellipses(target_curr)
            plot_linesegs.extend(plot_new_stuff)

            # draw predicted positions
            plot_new_stuff = draw_ellipses(target_pred)
            plot_linesegs.extend(plot_new_stuff)

            scaleunit = params.params.max_jump / params.params.DRAW_MOTION_SCALE
            parcolor = [0, 255, 0]
            perpcolor = [0, 255, 0]
            anglecolor = [0, 0, 255]

            for i in target_pred.iterkeys():
                # compute direction of motion
                vx = target_pred[i].center.x - target_curr[i].center.x
                vy = target_pred[i].center.y - target_curr[i].center.y
                thetamotion = num.arctan2(vy, vx)

                # angle
                theta = target_pred[i].angle

                # we want to choose to add pi if that makes difference from motion direction smaller
                dtheta = abs(((theta - thetamotion + num.pi) % (2. * num.pi)) -
                             num.pi)
                if dtheta > (num.pi / 2.):
                    theta += num.pi

                # compute end points of parallel motion
                x0 = target_pred[i].center.x + scaleunit * num.cos(theta)
                x1 = target_pred[i].center.x - scaleunit * num.cos(theta)
                y0 = target_pred[i].center.y + scaleunit * num.sin(theta)
                y1 = target_pred[i].center.y - scaleunit * num.sin(theta)

                # add parallel motion annotation line
                plot_new_stuff = imagesk.draw_line(x0 + 1, y0 + 1, x1 + 1,
                                                   y1 + 1, parcolor)
                plot_linesegs.extend(plot_new_stuff)

                # compute end points of perpendicular motion
                x0 = target_pred[i].center.x + scaleunit * num.cos(num.pi /
                                                                   2. + theta)
                x1 = target_pred[i].center.x - scaleunit * num.cos(num.pi /
                                                                   2. + theta)
                y0 = target_pred[i].center.y + scaleunit * num.sin(num.pi /
                                                                   2. + theta)
                y1 = target_pred[i].center.y - scaleunit * num.sin(num.pi /
                                                                   2. + theta)

                # add perpendicular motion annotation line
                plot_new_stuff = imagesk.draw_line(x0 + 1, y0 + 1, x1 + 1,
                                                   y1 + 1, perpcolor)
                plot_linesegs.extend(plot_new_stuff)

                # compute end points of angular motion
                if params.params.ang_dist_wt > 0:

                    dtheta = scaleunit * num.sqrt(
                        1. / params.params.ang_dist_wt)
                    if dtheta >= (num.pi / 2.):
                        print 'dtheta is more than pi/2'
                    else:
                        theta0 = theta - dtheta
                        theta1 = theta + dtheta

                        # draw arc
                        plot_new_stuff = imagesk.draw_arc(
                            target_pred[i].center.x, target_pred[i].center.y,
                            scaleunit / 2, theta0, theta1, anglecolor)
                        plot_linesegs.extend(plot_new_stuff)

        im = imagesk.double2mono8(im, donormalize=False)
        linesegs, im = imagesk.zoom_linesegs_and_image(plot_linesegs, im,
                                                       self.zoomaxes)
        (linesegs, linecolors) = imagesk.separate_linesegs_colors(linesegs)

        self.img_wind.update_image_and_drawings('trackset',
                                                im,
                                                format='MONO8',
                                                linesegs=linesegs,
                                                lineseg_colors=linecolors)
        self.img_wind.Refresh(eraseBackground=False)

        self.frame_number_text.SetLabel('Frame %d' % self.show_frame)

        if self.info == True:
            self.ShowInfo(None, None)

        wx.EndBusyCursor()

        if DEBUG_TRACKINGSETTINGS: sys.stdout.flush()
    def ShowImage(self):

        if DEBUG_TRACKINGSETTINGS: print 'ShowImage ' + str(self.show_frame)

        try:
            wx.Yield()
        except: pass # can be recursive sometimes in Windows
        wx.BeginBusyCursor()
        im, stamp = params.params.movie.get_frame( int(self.show_frame) )

        windowsize = [self.img_panel.GetRect().GetHeight(),self.img_panel.GetRect().GetWidth()]

        self.GetBgImage()
        
        if self.img_chosen == SHOW_UNFILTERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_UNFILTERED_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            plot_linesegs = draw_ellipses(obs_unfiltered)
            
        elif self.img_chosen == SHOW_FILTERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_FILTERED_OBSERVATIONS'
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = draw_ellipses(obs_filtered)
            
        elif self.img_chosen == SHOW_SMALL_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_SMALL_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            obs_small = []
            for obs in obs_unfiltered:
                if obs.area < params.params.minshape.area:
                    obs_small.append(obs)
            plot_linesegs = draw_ellipses(obs_small)
            
        elif self.img_chosen == SHOW_LARGE_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_LARGE_OBSERVATIONS'
            obs_unfiltered = self.GetObsUnfiltered()
            obs_large = []
            for obs in obs_unfiltered:
                if obs.area > params.params.maxshape.area:
                    obs_large.append(obs)
            plot_linesegs = draw_ellipses(obs_large)

        elif self.img_chosen == SHOW_DELETED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_DELETED_OBSERVATIONS'
            (obs_unfiltered,obs_deleted) = self.GetObsUnfiltered('diddelete')
            plot_linesegs = draw_ellipses(obs_deleted)

        elif self.img_chosen == SHOW_SPLIT_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_SPLIT_OBSERVATIONS'
            (obs_unfiltered,obs_split) = self.GetObsUnfiltered('didsplit')
            plot_linesegs = draw_ellipses(obs_split)

        elif self.img_chosen == SHOW_MERGED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MERGED_OBSERVATIONS'
            (obs_unfiltered,obs_merge) = self.GetObsUnfiltered('didmerge')
            plot_linesegs = draw_ellipses(obs_merge)

        elif self.img_chosen == SHOW_LOWERED_OBSERVATIONS:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_LOWERED_OBSERVATIONS'
            (obs_unfiltered,obs_lowered) = self.GetObsUnfiltered('didlowerthresh')
            plot_linesegs = draw_ellipses(obs_lowered)

        # MAXJUMP
        elif self.img_chosen == SHOW_MAXJUMP:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MAXJUMP'

            # either grab or compute observations
            obs_filtered = self.GetObsFiltered()
            plot_linesegs = draw_ellipses(obs_filtered)

            # draw circles
            for i,obs in enumerate(obs_filtered):
                plot_new_stuff = imagesk.draw_circle(obs.center.x,
                                                     obs.center.y,params.params.max_jump*2.,
                                                     params.params.colors[i%len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)
                plot_new_stuff = imagesk.draw_circle(obs.center.x,
                                                     obs.center.y,params.params.min_jump,
                                                     params.params.colors[i%len(params.params.colors)])
                plot_linesegs.extend(plot_new_stuff)
                

        elif self.img_chosen == SHOW_MOTIONMODEL:
            if DEBUG_TRACKINGSETTINGS: print 'SHOW_MOTIONMODEL'

            (target_prev,target_curr,target_pred) = self.GetTargetMotion()

            # show the next frame, if there is one
            nextframe = num.minimum(int(self.show_frame+1),params.params.n_frames-1)
            im, stamp = params.params.movie.get_frame(nextframe)

            # draw previous positions
            plot_linesegs = draw_ellipses(target_prev)

            # draw current positions
            plot_new_stuff = draw_ellipses(target_curr,colors=[[255,255,0]])
            plot_linesegs.extend(plot_new_stuff)

            # draw predicted positions
            plot_new_stuff = draw_ellipses(target_pred)
            plot_linesegs.extend(plot_new_stuff)

            scaleunit = params.params.max_jump / params.params.DRAW_MOTION_SCALE
            parcolor = [0,255,0]
            perpcolor = [0,255,0]
            anglecolor = [0,0,255]

            for i in target_pred.iterkeys():
                # compute direction of motion
                vx = target_pred[i].center.x - target_curr[i].center.x
                vy = target_pred[i].center.y - target_curr[i].center.y
                thetamotion = num.arctan2(vy,vx)

                # angle
                theta = target_pred[i].angle
                
                # we want to choose to add pi if that makes difference from motion direction smaller
                dtheta = abs( ((theta - thetamotion + num.pi) % (2.*num.pi)) - num.pi )
                if dtheta > (num.pi/2.):
                    theta += num.pi

                # compute end points of parallel motion
                x0 = target_pred[i].center.x + scaleunit*num.cos(theta)
                x1 = target_pred[i].center.x - scaleunit*num.cos(theta)
                y0 = target_pred[i].center.y + scaleunit*num.sin(theta)
                y1 = target_pred[i].center.y - scaleunit*num.sin(theta)

                # add parallel motion annotation line
                plot_new_stuff = imagesk.draw_line(x0+1,y0+1,x1+1,y1+1,parcolor)
                plot_linesegs.extend(plot_new_stuff)

                # compute end points of perpendicular motion
                x0 = target_pred[i].center.x + scaleunit*num.cos(num.pi/2.+theta)
                x1 = target_pred[i].center.x - scaleunit*num.cos(num.pi/2.+theta)
                y0 = target_pred[i].center.y + scaleunit*num.sin(num.pi/2.+theta)
                y1 = target_pred[i].center.y - scaleunit*num.sin(num.pi/2.+theta)
                
                # add perpendicular motion annotation line
                plot_new_stuff = imagesk.draw_line(x0+1,y0+1,x1+1,y1+1,perpcolor)
                plot_linesegs.extend(plot_new_stuff)
                

                # compute end points of angular motion
                if params.params.ang_dist_wt > 0:
                    
                    dtheta = scaleunit*num.sqrt(1./params.params.ang_dist_wt)
                    if dtheta >= (num.pi/2.):
                        print 'dtheta is more than pi/2'
                    else:
                        theta0 = theta - dtheta
                        theta1 = theta + dtheta
                        
                        # draw arc
                        plot_new_stuff = imagesk.draw_arc(target_pred[i].center.x,
                                                          target_pred[i].center.y,
                                                          scaleunit/2,
                                                          theta0,theta1,
                                                          anglecolor)
                        plot_linesegs.extend(plot_new_stuff)
                   
        im = imagesk.double2mono8(im,donormalize=False)
        linesegs,im = imagesk.zoom_linesegs_and_image(plot_linesegs,im,self.zoomaxes)
        (linesegs,linecolors) = imagesk.separate_linesegs_colors(linesegs)

        self.img_wind.update_image_and_drawings('trackset',
                                                im,
                                                format='MONO8',
                                                linesegs=linesegs,
                                                lineseg_colors=linecolors
                                                )
        self.img_wind.Refresh(eraseBackground=False)

        self.frame_number_text.SetLabel('Frame %d'%self.show_frame)
        
        if self.info == True:
            self.ShowInfo( None, None )

        wx.EndBusyCursor()

        if DEBUG_TRACKINGSETTINGS: sys.stdout.flush()