Exemple #1
0
        private void generateTestImagesFromLUTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string basePath = settings.LUTImagePath;
                if (basePath.Length > 0)
                {
                    basePath += Path.DirectorySeparatorChar;
                }

                using (var lut = new Bitmap(ofd.FileName))
                {
                    var cfg = settings.trackerConfig;
                    var cc  = QTrkComputedConfig.FromConfig(cfg);

                    FloatImg lutf = new FloatImg(lut, 0);
                    FloatImg img  = new FloatImg(cfg.width, cfg.height);
                    for (int i = 0; i < lut.Height; i++)
                    {
                        QTrkUtil.GenerateImageFromLUT(img, lutf, cfg.ZLUT_minradius, cc.zlut_maxradius, new Vector3(cfg.width / 2, cfg.height / 2, i), false, 1);
                        string fn = basePath + string.Format("lut{0:000}.png", i);
                        Trace.WriteLine("Writing " + fn);
                        using (var planeimg = img.ToImage())
                            planeimg.Save(fn);
                    }

                    lutf.Dispose();
                    img.Dispose();
                }
            }
        }
Exemple #2
0
        private void buttonSelectBeads_Click(object sender, EventArgs e)
        {
            if (frameViewImage == null)
            {
                MessageBox.Show("First select image dataset");
                return;
            }
            using (var fimg = new FloatImg(frameViewImage, 0))
            {
                var dlg = new TrackerDlgUtils.BeadSelectorDlg(fimg, settings.ROI, beadCenterPosList.ToArray());

                dlg.AutoFindMinDist    = settings.autoFindMinDist;
                dlg.AutoFindAcceptance = settings.autoFindAcceptance;

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    beadCenterPosList           = dlg.ROIPositions.ToList();
                    settings.ROI                = dlg.ROISize;
                    settings.autoFindAcceptance = dlg.AutoFindAcceptance;
                    settings.autoFindMinDist    = dlg.AutoFindMinDist;
                    UpdateConfigurationUIComponents();
                    CheckBeadPos();
                    UpdateExpBaseDir();
                }
            }
        }
Exemple #3
0
        private void buttonBuildLUT_Click(object sender, EventArgs e)
        {
            if (beadCenterPosList.Count == 0)
            {
                MessageBox.Show("No beads selected");
                return;
            }

            CheckBeadPos();

            var dlg = new ProgressBarDlg();

            dlg.Show(new Action(delegate
            {
                using (QTrkInstance inst = new QTrkInstance(settings.trackerConfig))
                {
                    inst.SetRadialZLUTSize(beadCenterPosList.Count, numLUTSteps);
                    inst.BeginLUT(true);

                    int roi = settings.ROI;
                    using (FloatImg tmp = new FloatImg(roi, roi * beadCenterPosList.Count))
                    {
                        for (int i = 0; i < numLUTSteps; i++)
                        {
                            string path = lutFiles[i];
                            if (!File.Exists(path))
                            {
                                MessageBox.Show("File " + path + " missing");
                                break;
                            }
                            dlg.Update(i / (float)numLUTSteps, path, string.Format("Processing LUT Frame {0}/{1}", i, numLUTSteps));
                            using (Bitmap bmp = new Bitmap(path))
                            {
                                if (bmp.Size != imageSize)
                                {
                                    MessageBox.Show(string.Format("{0} has invalid size {1},{2}", path, bmp.Width, bmp.Height));
                                    break;
                                }
                                using (var fi = new FloatImg(bmp, 0))
                                {
                                    // build one image with all beads
                                    for (int b = 0; b < beadCenterPosList.Count; b++)
                                    {
                                        fi.CopySubimage(tmp, beadCenterPosList[b].x - roi / 2, beadCenterPosList[b].y - roi / 2, 0, roi * b, roi, roi);
                                    }
                                    inst.BuildLUT(tmp, i);
                                }
                            }
                        }
                    }
                    inst.FinalizeLUT();
                    lut = inst.GetRadialZLUT();
                }
            }));
            UpdateFileLists();
            tabControl.SelectedTab = tabPageTrack;
        }
Exemple #4
0
        public void SetLUT(FloatImg lutimg, int zplanes)
        {
            lutImage     = lutimg;
            this.zplanes = zplanes;

            if (lutimg != null)
            {
                int lutcount = lutimg.h / zplanes;
                trackBarBeadIndex.Maximum = Math.Max(0, lutcount - 1);
            }
            UpdateImage();
        }
Exemple #5
0
        public BeadSelectorDlg(FloatImg image, int ROI, Int2[] beadCenterPos)
        {
            InitializeComponent();

            if (!DesignMode)
            {
                dispImage        = image.ToImage();
                this.image       = image;
                pictureBox.Image = dispImage;
                roiPositions     = beadCenterPos.ToList();
            }
            DialogResult    = System.Windows.Forms.DialogResult.Cancel;
            textBoxROI.Text = ROI.ToString();
        }
Exemple #6
0
        private void GenerateImageFromLUT()
        {
            QTrkConfig cfg = QTrkConfig;

            using (var dst = new FloatImg(100, 100))
            {
                QTrkUtil.GenerateImageFromLUT(dst, zlut, 3, 40, new Vector3(dst.w / 2, dst.h / 2, zpos), false, 1);
                if (trackBarNoise.Value > 0)
                {
                    QTrkUtil.ApplyPoissonNoise(dst, trackBarNoise.Value, 255);
                }
                pictureBoxFrameView.Image = dst.ToImage();
            }
        }
Exemple #7
0
        private void buttonOpenLUT_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Title = "Select LUT image"
            };

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Bitmap img = new Bitmap(ofd.FileName);
//				pictureBoxLUT.Image = img;
                zlut = new FloatImg(img, 0);
                pictureBoxLUT.Image = zlut.ToImage();
            }
        }
Exemple #8
0
        public void UpdateExpBaseDir()
        {
            string cursel = null;

            if (checkedListExp.SelectedItem != null)
            {
                cursel = checkedListExp.SelectedItem.ToString();
            }

            // scan the experiment base path for tmp_* directories
            string[] expPaths = settings.GetExperimentDataPaths();
            checkedListExp.Items.Clear();
            checkedListExp.Items.AddRange(expPaths);

            if (cursel != null)
            {
                checkedListExp.SelectedIndex = Array.FindIndex(expPaths, str => cursel == str);
            }

            if (settings.selectedExpDirs != null)
            {
                foreach (string sel in settings.selectedExpDirs)
                {
                    int i = Array.FindIndex(expPaths, str => sel == str);
                    if (i >= 0)
                    {
                        checkedListExp.SetItemCheckState(i, CheckState.Checked);
                    }
                }
            }

            comboLutDir.Items.Clear();
            comboLutDir.Items.AddRange(expPaths);
            comboLutDir.SelectedItem = expPaths.FirstOrDefault(str => settings.lutSubdir == str);

            if (lut != null)
            {
                lut.Dispose();
                lut = null;
            }

            labelBeadPosFileLoc.Text = settings.BeadListXMLPath;
            UpdateFileLists();
        }
Exemple #9
0
        private unsafe void buttonSpeedTest_Click(object sender, EventArgs e)
        {
            // get lut
            // rescale lut
//			var lut = new Bitmap("lut000.jpg");

            var dlg = new ProgressBarDlg();

            dlg.Show(new Action(delegate
            {
                Bitmap lut = TrackerDlgUtils.Properties.Resources.lut000;
                using (QTrkInstance inst = new QTrkInstance(TrackerConfiguration))
                {
                    int total = Math.Max(100000, inst.GetMaxQueueLength() * 4);

                    Trace.WriteLine(string.Format("Max queue len: {1}, running benchmark with {0} images...", total, inst.GetMaxQueueLength()));

                    dlg.Update(0.0f, "Generating lookup table...", "Benchmark in progress");

                    GetTimestamp();
                    // use LUT to generate images for new rescaled lut table
                    var lutf = new FloatImg(lut, 0);
                    using (FloatImg img = QTrkUtil.RescaleAndSetLUT(inst, lutf, lut.Height)) { }
                    // make sample image

                    var cfg    = inst.Config;
                    var sample = new FloatImg(cfg.config.width, cfg.config.height);
                    QTrkUtil.GenerateImageFromLUT(sample, lutf, cfg.config.ZLUT_minradius, cfg.zlut_maxradius, new Vector3(cfg.config.width / 2, cfg.config.height / 2, lutf.h / 2), false, 1);

                    dlg.Update(0.0f, "Running speed test...", "Benchmark in progress");

                    // measure tracking speed
                    double st           = GetTimestamp();
                    ImageData imgd      = sample.ImageData;
                    LocalizationJob job = new LocalizationJob();
                    LocalizationJob *pj = &job;
                    int lastUpdate      = 0;

                    for (uint i = 0; i < total; i++)
                    {
                        pj->frame     = i;
                        pj->zlutIndex = 0;

                        inst.ScheduleLocalization(ref imgd, pj);

                        int rc = inst.GetResultCount();
                        if (rc - lastUpdate > total / 20)
                        {
                            dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress");
                            lastUpdate = rc;
                        }
                    }
                    double st0 = GetTimestamp();
                    inst.Flush();

                    // wait for results
                    while (true)
                    {
                        System.Threading.Thread.Sleep(20);
                        int rc = inst.GetResultCount();

                        if (rc - lastUpdate > total / 20)
                        {
                            dlg.Update(rc / (float)total, "Running speed test...", "Benchmark in progress");
                            lastUpdate = rc;
                        }

                        if (rc == total)
                        {
                            break;
                        }
                    }

                    double end = GetTimestamp();
                    double fps = total / (end - st);

                    double scheduleTime = (st0 - st) * 1000;
                    Trace.WriteLine(string.Format("Scheduling time: {0} ms. Per frame: {1} us. Scheduling FPS={2}. Processing FPS={3}",
                                                  (int)scheduleTime, (int)(scheduleTime / total * 1000), (int)(total / (st0 - st)), (int)fps));

                    Invoke(new Action(delegate { labelSpeedResults.Text = string.Format("{0} frames processed in {1} ms. \nFPS={2}",
                                                                                        total, (int)((end - st) * 1000), (int)fps); }));

                    var results = new LocalizationResult[total];
                    inst.GetResults(results);

                    for (int i = 0; i < 10; i++)
                    {
                        Vector3 p = results[i].pos;
                        Trace.WriteLine(string.Format("x={0}, y={1}, z={2}", p.x, p.y, p.z));
                    }

                    sample.Dispose();
                }
                lut.Dispose();
            }));
        }