예제 #1
0
 public void SetNonreusableImage(SySal.Imaging.LinearMemoryImage lmi)
 {
     lock (this)
     {
         m_OriginalBmp         = new Bitmap(lmi.Info.Width, lmi.Info.Height, lmi.Info.Width, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, ImageAccessor.Scan(lmi));
         m_OriginalBmp.Palette = GrayScalePalette;
         m_Bmp = new Bitmap(pbScreen.Width, pbScreen.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
     }
     this.Invoke(new dVoid(delegate()
     {
         lock (this)
         {
             pbScreen.Image         = m_Bmp;
             m_G                    = System.Drawing.Graphics.FromImage(m_Bmp);
             m_G.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
             m_G.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
             m_G.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
             double fzoom           = m_Bmp.Width * m_Zoom / m_OriginalBmp.Width;
             m_G.DrawImage(m_OriginalBmp, new Rectangle(0, 0, m_Bmp.Width, m_Bmp.Height), new Rectangle((int)((m_OriginalBmp.Width - m_Bmp.Width / fzoom) * 0.5), (int)((m_OriginalBmp.Height - m_Bmp.Height / fzoom) * 0.5), (int)(m_Bmp.Width / fzoom), (int)(m_Bmp.Height / fzoom)), GraphicsUnit.Pixel);
         }
     }
                           ));
 }
예제 #2
0
 static public IntPtr Scan(SySal.Imaging.LinearMemoryImage lm)
 {
     return(SySal.Imaging.LinearMemoryImage.AccessMemoryAddress(lm));
 }
예제 #3
0
        private void CameraDisplayRefresh()
        {
            System.Threading.WaitHandle[] waiths = new System.Threading.WaitHandle[] { m_TerminateEvent, m_DisplayMutex };
            int waitresult = -1;

            while ((waitresult = System.Threading.WaitHandle.WaitAny(waiths)) == 1)
            {
                try
                {
                    try
                    {
                        SySal.Imaging.IImageProcessor iproc = null;
                        foreach (SImageProcessor ipr in iGPU)
                        {
                            if (ipr.IProc != null)
                            {
                                iproc = ipr.IProc;
                                break;
                            }
                        }
                        if (m_CameraDisplay.ImageProcessor != iproc)
                        {
                            m_CameraDisplay.ImageProcessor = iproc;
                        }
                    }
                    catch (Exception x)
                    {
                        Log(DisplayLog, x.ToString());
                    }
                    object seq = null;
                    SySal.Imaging.LinearMemoryImage im = null;
                    try
                    {
                        System.DateTime start = System.DateTime.Now;
                        seq = iGrab.GrabSequence();
                        im  = (SySal.Imaging.LinearMemoryImage)iGrab.MapSequenceToSingleImage(seq);
                        System.DateTime end1 = System.DateTime.Now;
                        m_CameraDisplay.ImageShown = im;
                        System.DateTime end2 = System.DateTime.Now;
                        iGrab.ClearMappedImage(im);
                        System.DateTime end3 = System.DateTime.Now;
                        iGrab.ClearGrabSequence(seq);
                        seq = null;
                        System.DateTime end4 = System.DateTime.Now;
                        //Log(DisplayLog, (end1 - start).TotalMilliseconds.ToString() + " " + (end2 - end1).TotalMilliseconds.ToString() + " " + (end3 - end2).TotalMilliseconds.ToString() + " " + (end4 - end3).TotalMilliseconds.ToString());
                        im = null;
                    }
                    catch (Exception x)
                    {
                        Log(DisplayLog, x.ToString());
                    }
                    finally
                    {
                        if (im != null)
                        {
                            try
                            {
                                iGrab.ClearMappedImage(im);
                                im = null;
                            }
                            catch (Exception x)
                            {
                                Log(DisplayLog, x.ToString());
                            }
                        }
                        if (seq != null)
                        {
                            try
                            {
                                iGrab.ClearGrabSequence(seq);
                                seq = null;
                            }
                            catch (Exception x)
                            {
                                Log(DisplayLog, x.ToString());
                            }
                        }
                    }
                }
                catch (Exception xc)
                {
                    Log("OnCameraDisplayTimer_Elapsed", xc.ToString());
                }
            }
예제 #4
0
        private void btnCompute_Click(object sender, EventArgs e)
        {
            if (m_Running)
            {
                m_Running = false;
                return;
            }
            if (S.MinimumThreshold == S.MaximumThreshold)
            {
                SySal.Imaging.DCTInterpolationImage dct = null;
                try
                {
                    SySal.Imaging.ImageInfo info = m_ImageFormat;
                    info.BitsPerPixel = 16;
                    SySal.Imaging.DCTInterpolationImage.PointValue pval = new SySal.Imaging.DCTInterpolationImage.PointValue();
                    pval.X     = (ushort)(info.Width / 2);
                    pval.Y     = (ushort)(info.Height / 2);
                    pval.Value = (int)S.MaximumThreshold;
                    dct        = new SySal.Imaging.DCTInterpolationImage(info, 1, 1, new SySal.Imaging.DCTInterpolationImage.PointValue [] { pval });
                    m_Result   = txtResult.Text = dct.ToString();
                    MessageBox.Show("Constant threshold image built.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                catch (Exception x)
                {
                    MessageBox.Show("Invalid DCT built.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (m_Files.Length <= 0)
            {
                MessageBox.Show("Please choose sample image files.", "Input missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            double[][,] densities = null;
            SySal.Imaging.Image[] thresholdimgs = null;
            int[] cellmeanx = new int[S.XCells];
            int[] cellmeany = new int[S.YCells];
            int[] cellminx  = new int[S.XCells];
            int[] cellmaxx  = new int[S.YCells];
            int[] cellminy  = new int[S.XCells];
            int[] cellmaxy  = new int[S.YCells];
            m_Running = true;
            EnableButtons();
            pbProgress.Minimum = 0.0;
            pbProgress.Maximum = (double)m_Files.Length;
            pbProgress.Value   = 0.0;
            System.Threading.Thread execthread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                thresholdimgs = new SySal.Imaging.Image[S.ThresholdSteps + 1];
                int i, j, ix, iy;
                SySal.Imaging.ImageInfo m_info = m_ImageFormat;
                m_info.BitsPerPixel            = 16;
                int bestgpu   = 0;
                int maximages = iGPU[bestgpu].MaxImages;
                for (i = 1; i < iGPU.Length; i++)
                {
                    if (iGPU[i].MaxImages > maximages)
                    {
                        bestgpu   = i;
                        maximages = iGPU[i].MaxImages;
                    }
                }
                ;
                int xstep = (int)(m_ImageFormat.Width / S.XCells);
                int ystep = (int)(m_ImageFormat.Height / S.YCells);
                for (i = 0; i < S.XCells; i++)
                {
                    cellmeanx[i] = (int)(xstep * (i + 0.5));
                    cellminx[i]  = cellmeanx[i] - (int)S.CellWidth / 2;
                    cellmaxx[i]  = cellmeanx[i] + (int)S.CellWidth / 2;
                }
                for (i = 0; i < S.YCells; i++)
                {
                    cellmeany[i] = (int)(ystep * (i + 0.5));
                    cellminy[i]  = cellmeany[i] - (int)S.CellHeight / 2;
                    cellmaxy[i]  = cellmeany[i] + (int)S.CellHeight / 2;
                }
                densities   = new double[thresholdimgs.Length][, ];
                int[] files = new int[thresholdimgs.Length];
                for (j = 0; j <= S.ThresholdSteps; j++)
                {
                    densities[j]     = new double[S.XCells, S.YCells];
                    thresholdimgs[j] = new SySal.Imaging.Image(m_info, new ConstThresholdImagePixels((short)(S.MinimumThreshold + (j * (S.MaximumThreshold - S.MinimumThreshold)) / S.ThresholdSteps)));
                }
                for (i = 0; i < m_Files.Length; i++)
                {
                    SySal.Imaging.LinearMemoryImage im = null;
                    try
                    {
                        im = iGPU[bestgpu].ImageFromFile(m_Files[i]);
                        for (j = 0; j < thresholdimgs.Length; j++)
                        {
                            iGPU[bestgpu].ThresholdImage = thresholdimgs[j];
                            iGPU[bestgpu].Input          = im;
                            if (iGPU[bestgpu].Warnings == null || iGPU[bestgpu].Warnings.Length == 0)
                            {
                                SySal.Imaging.Cluster[] clusters = iGPU[bestgpu].Clusters[0];
                                foreach (SySal.Imaging.Cluster cls in clusters)
                                {
                                    if (cls.Area >= S.MinClusterSize && cls.Area <= S.MaxClusterSize)
                                    {
                                        for (ix = 0; ix < S.XCells; ix++)
                                        {
                                            if (cls.X >= cellminx[ix] && cls.X <= cellmaxx[ix])
                                            {
                                                for (iy = 0; iy < S.YCells; iy++)
                                                {
                                                    if (cls.Y >= cellminy[iy] && cls.Y <= cellmaxy[iy])
                                                    {
                                                        densities[j][ix, iy]++;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                files[j]++;
                            }
                            if (m_Running == false)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if (im != null)
                        {
                            ((SySal.Imaging.LinearMemoryImage)im).Dispose();
                        }
                    }
                    this.Invoke(new dSetValue(SetValue), new object[] { (double)(i + 1) });
                    if (m_Running == false)
                    {
                        break;
                    }
                }
                for (j = 0; j < files.Length; j++)
                {
                    if (files[j] > 0)
                    {
                        for (ix = 0; ix < S.XCells; ix++)
                        {
                            for (iy = 0; iy < S.YCells; iy++)
                            {
                                densities[j][ix, iy] /= (files[j] * m_ImageFormat.Width * m_ImageFormat.Height);
                            }
                        }
                    }
                }
            }));
            execthread.Start();
            while (execthread.Join(100) == false)
            {
                Application.DoEvents();
            }
            System.Collections.ArrayList hidens = new System.Collections.ArrayList();
            foreach (double d in densities[densities.Length - 1])
            {
                hidens.Add(d);
            }
            hidens.Sort();
            if (hidens.Count < HiDensValues)
            {
                MessageBox.Show("Too few clusters:\r\nthe threshold was set too high, or the images were not taken in emulsion.\r\nPlease correct and retry.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                m_Running = false;
                EnableButtons();
                return;
            }
            double target = 0.0;
            int    t;

            for (t = 1; t <= HiDensValues; t++)
            {
                target += (double)hidens[hidens.Count - t];
            }
            target /= HiDensValues;
            System.Collections.ArrayList pvals = new System.Collections.ArrayList();
            {
                int ix, iy;
                for (ix = 0; ix < S.XCells; ix++)
                {
                    for (iy = 0; iy < S.YCells; iy++)
                    {
                        for (t = 1; t < densities.Length && (densities[t - 1][ix, iy] < target || densities[t][ix, iy] > target); t++)
                        {
                            ;
                        }
                        if (t < densities.Length)
                        {
                            SySal.Imaging.DCTInterpolationImage.PointValue pval = new SySal.Imaging.DCTInterpolationImage.PointValue();
                            pval.X     = (ushort)cellmeanx[ix];
                            pval.Y     = (ushort)cellmeanx[iy];
                            pval.Value = (int)((target - densities[t - 1][ix, iy]) / (densities[t][ix, iy] - densities[t - 1][ix, iy]) *
                                               (((ConstThresholdImagePixels)thresholdimgs[t].Pixels).m_Threshold - ((ConstThresholdImagePixels)thresholdimgs[t - 1].Pixels).m_Threshold) +
                                               ((ConstThresholdImagePixels)thresholdimgs[t - 1].Pixels).m_Threshold);
                            pvals.Add(pval);
                        }
                    }
                }
                SySal.Imaging.DCTInterpolationImage dct = null;
                try
                {
                    SySal.Imaging.ImageInfo info = m_ImageFormat;
                    info.BitsPerPixel = 16;
                    dct = new SySal.Imaging.DCTInterpolationImage(info, (int)S.XWaves, (int)S.YWaves,
                                                                  (SySal.Imaging.DCTInterpolationImage.PointValue [])pvals.ToArray(typeof(SySal.Imaging.DCTInterpolationImage.PointValue)));
                    m_Result = txtResult.Text = dct.ToString();
                }
                catch (Exception x)
                {
                    MessageBox.Show("Invalid DCT built.", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    m_Running = false;
                    EnableButtons();
                    return;
                }
            }
            m_Running = false;
            EnableButtons();
            {
                System.IO.StringWriter sw = new System.IO.StringWriter();
                sw.WriteLine("THRESHOLD\tX\tY\tDENSITY");
                int j, ix, iy;
                for (j = 0; j < thresholdimgs.Length; j++)
                {
                    for (ix = 0; ix < S.XCells; ix++)
                    {
                        for (iy = 0; iy < S.YCells; iy++)
                        {
                            sw.WriteLine(((ConstThresholdImagePixels)thresholdimgs[j].Pixels).m_Threshold + "\t" + cellmeanx[ix] + "\t" + cellmeany[iy] + "\t" + densities[j][ix, iy].ToString(System.Globalization.CultureInfo.InvariantCulture));
                        }
                    }
                }
                sw.Flush();
                sw.Close();
                InfoPanel panel = new InfoPanel();
                panel.TopLevel = true;
                panel.SetContent("Density vs. Threshold", sw.ToString());
                panel.ShowDialog();
            }
        }