Пример #1
0
 def test_zero_error_pix_exchange(self):
     cur_im = numpy.ones((2,3))
     next_im = numpy.ones_like(cur_im)
     flow = numpy.zeros((2,3,2))
     flow[0,0,0] = 1
     flow[0,1,0] = -1
     
     err = flux.compute_error_map(cur_im, next_im, flow)
     self.assertTrue(numpy.all(err==0.0), "expecting zero error, got %s"%err)
Пример #2
0
 def test_unity_error_no_motion(self):
     cur_im = numpy.ones((2,3))
     next_im = numpy.ones_like(cur_im)
     flow = numpy.zeros((2,3,2))
     
     next_im[1,2] = 2
     
     err = flux.compute_error_map(cur_im, next_im, flow)
     self.assertTrue(len(err[numpy.where(err!=0)].ravel())==1)
     self.assertTrue(err[1,2]==50.0)
Пример #3
0
 def test_zero_error_unity_motion(self):
     cur_im = numpy.ones((2,3))
     cur_im[0,0] = 2
     next_im = numpy.ones_like(cur_im)
     
     next_im[0,1] = 3
     next_im[0,0] = 0
     flow = numpy.zeros((2,3,2))
     flow[0,0,0] = 1
     
     err = flux.compute_error_map(cur_im, next_im, flow)
     self.assertTrue(numpy.all(err==0.0), "expecting zero error, got %s"%err)
Пример #4
0
    def test_fractional_motion(self):
        cur_im = numpy.ones((2,3))
        next_im = numpy.ones_like(cur_im)
        flow = numpy.zeros((2,3,2))
        
        next_im[0,0] = 0
        
        flow[0,0,0] = 1.5
        flow[0,0,1] = 0.5
        
        err = flux.compute_error_map(cur_im, next_im, flow)
        
        expected_err = numpy.ones_like(err) * 25.0
        expected_err[1,0] = 0.0

        self.assertTrue(numpy.all(err==expected_err))
Пример #5
0
 def test_zero_error_no_motion(self):
     cur_im = numpy.ones((2,3))
     flow = numpy.zeros((2,3,2))
     err = flux.compute_error_map(cur_im, cur_im, flow)
     self.assertTrue(numpy.all(err==0.0), "expecting zero error, got %s"%err)
    def redraw_plot(self):

        x_shifts, y_shifts, self.extent = output.resample_velocities(
            self.__cur_flow * self.config['downsizing_factor'],
            self._quiver_density)

        if self.masked_im_plot is None:
            self.masked_im_plot = self.motion_ax.imshow(self.cur_im_masked,
                                                        extent=self.extent)
        else:
            self.masked_im_plot.remove()
            self.masked_im_plot = self.motion_ax.imshow(self.cur_im_masked,
                                                        extent=self.extent)

        if self.quiver_plot is None:
            self.quiver_plot = self.motion_ax.quiver(x_shifts,
                                                     y_shifts,
                                                     width=1.6,
                                                     units='dots',
                                                     scale_units='xy',
                                                     angles='xy',
                                                     scale=self.vector_scale)
        else:
            self.quiver_plot.remove()
            self.quiver_plot = self.motion_ax.quiver(x_shifts,
                                                     y_shifts,
                                                     width=1.6,
                                                     units='dots',
                                                     scale_units='xy',
                                                     angles='xy',
                                                     scale=self.vector_scale)

        #draw integration lines
        for p in self.int_line_plots:
            p.remove()
        self.int_line_plots = []

        for l in self.config['integration_lines']:
            pts = numpy.array(l['integration_points'], dtype='float')

            pts[:, 0] *= self.extent[1] / float(self.cur_im.shape[1])
            pts[:, 1] *= self.extent[2] / float(self.cur_im.shape[0])

            p, = self.motion_ax.plot(pts[:, 0], pts[:, 1], 'w-', linewidth=2)
            self.int_line_plots.append(p)

            p.set_visible(self.controls.show_intline_chkbx.IsChecked())

        self.masked_im_plot.axes.set_xlim(self.extent[:2])
        self.masked_im_plot.axes.set_ylim(self.extent[2:])

        self.masked_im_plot.set_visible(True)
        self.quiver_plot.set_visible(True)

        #draw the error plot
        if self.show_errors:
            if self.error_plot is not None:
                self.error_plot.remove()
            if self.errors is None:
                self.errors = numpy.fabs(
                    flux.compute_error_map(self.cur_im_masked,
                                           self.next_im_masked,
                                           self.__cur_flow))
            print "error range = ", numpy.min(self.errors), numpy.max(
                self.errors)
            self.error_plot = self.error_ax.imshow(
                numpy.clip(self.errors, 0, self.cb_clip_limit))
            self.error_cb_ax.clear()
            cb = colorbar(self.error_plot, cax=self.error_cb_ax)
            cb.set_label('Error (%)')

        self.canvas.draw()