Beispiel #1
0
        public void TestColorMapping()
        {
            Log log = new Log("Test ColorMapper");

            log.EnableTrace = true;

            int         nCount = 300;
            ColorMapper clrMap = new ColorMapper(0, 1, Color.Black, Color.Red);
            double      dfVal  = 0;
            double      dfInc  = 1.0 / (double)nCount;

            for (int i = 0; i < nCount; i++)
            {
                Color  clr    = clrMap.GetColor(dfVal);
                double dfVal1 = clrMap.GetValue(clr);

                log.EXPECT_EQUAL <float>(dfVal1, dfVal, "The value at i = " + i.ToString() + " value = " + dfVal.ToString() + " does not equal value1 = " + dfVal1.ToString());

                dfVal += dfInc;
            }

            dfVal = clrMap.GetValue(Color.FromArgb(0, 130, 124));
            log.CHECK_NE(0, dfVal, "The value should not be zero.");

            dfVal = clrMap.GetValue(Color.FromArgb(255, 252, 0));
            log.CHECK_NE(0, dfVal, "The value should not be zero.");

            log.WriteLine("DONE.");
        }
Beispiel #2
0
        /// <summary>
        /// Renders the rectangle on the Graphics specified.
        /// </summary>
        /// <param name="g">Specifies the Graphics used to draw.</param>
        public override void Render(Graphics g)
        {
            prerender(g);
            PointF[]   rg = m_rgPoints.ToArray();
            RectangleF rc = new RectangleF(LeftTop(rg).X, LeftTop(rg).Y, Width(rg), Height(rg));
            Brush      br = new SolidBrush(m_clrFill);
            Pen        p  = new Pen(m_clrBorder, 1.0f);

            g.FillRectangle(br, rc);

            if (m_clrMap != null)
            {
                float fX   = 0;
                float fWid = rc.Width / 20;

                for (int i = 0; i < 20; i++)
                {
                    RectangleF rc2 = new RectangleF(fX, rc.Y, fWid, rc.Height);
                    Color      clr = m_clrMap.GetColor(fX);
                    Brush      br1 = new SolidBrush(clr);
                    g.FillRectangle(br1, rc2);
                    br1.Dispose();
                    fX += rc2.Width;
                }
            }

            g.DrawRectangle(p, rc.X, rc.Y, rc.Width, rc.Height);
            p.Dispose();
            br.Dispose();
            postrender(g);
        }
        private void overlay(Bitmap bmp, double[][] rgData)
        {
            if (bmp == null)
            {
                return;
            }

            using (Graphics g = Graphics.FromImage(bmp))
            {
                int         nBorder = 30;
                int         nWid    = bmp.Width - (nBorder * 2);
                int         nWid1   = nWid / rgData.Length;
                int         nHt1    = (int)(bmp.Height * 0.3);
                int         nX      = nBorder;
                int         nY      = bmp.Height - nHt1;
                ColorMapper clrMap  = new ColorMapper(0, rgData.Length + 1, Color.Black, Color.Red);
                float[]     rgfMin  = new float[rgData.Length];
                float[]     rgfMax  = new float[rgData.Length];
                float       fMax    = -float.MaxValue;
                float       fMaxMax = -float.MaxValue;
                int         nMaxIdx = 0;

                for (int i = 0; i < rgData.Length; i++)
                {
                    rgfMin[i] = (float)rgData[i].Min(p => p);
                    rgfMax[i] = (float)rgData[i].Max(p => p);

                    if (rgfMax[i] > fMax)
                    {
                        fMax    = rgfMax[i];
                        nMaxIdx = i;
                    }

                    fMaxMax = Math.Max(fMax, fMaxMax);
                }

                if (fMaxMax > 0.2f)
                {
                    m_bNormalizeOverlay = false;
                }

                for (int i = 0; i < rgData.Length; i++)
                {
                    drawProbabilities(g, nX, nY, nWid1, nHt1, i, rgData[i], clrMap.GetColor(i + 1), rgfMin.Min(p => p), rgfMax.Max(p => p), (i == nMaxIdx) ? true : false, m_bNormalizeOverlay);
                    nX += nWid1;
                }
            }
        }
Beispiel #4
0
        Color getColor(double dfVal, ColorMapper mapper, bool bBinary)
        {
            Color clr = Color.Black;

            if (bBinary)
            {
                if (dfVal != 0)
                {
                    clr = Color.White;
                }
            }
            else
            {
                clr = mapper.GetColor(dfVal);
            }

            return(clr);
        }
Beispiel #5
0
        /// <summary>
        /// The OnOverlay callback is called just before displaying the gym image, thus allowing for an overlay to be applied to the image.
        /// </summary>
        /// <param name="e">Specifies the arguments to the callback which contains the original display image.</param>
        public void OnOverlay(OverlayArgs e)
        {
            Blob <T> logits = m_netOutput.blob_by_name("logits");

            if (logits == null)
            {
                return;
            }

            if (logits.num == 1)
            {
                m_rgOverlay = Utility.ConvertVecF <T>(logits.mutable_cpu_data);
            }

            if (m_rgOverlay == null)
            {
                return;
            }

            using (Graphics g = Graphics.FromImage(e.DisplayImage))
            {
                int         nBorder = 30;
                int         nWid    = e.DisplayImage.Width - (nBorder * 2);
                int         nWid1   = nWid / m_rgOverlay.Length;
                int         nHt1    = (int)(e.DisplayImage.Height * 0.3);
                int         nX      = nBorder;
                int         nY      = e.DisplayImage.Height - nHt1;
                ColorMapper clrMap  = new ColorMapper(0, m_rgOverlay.Length + 1, Color.Black, Color.Red);
                float       fMax    = -float.MaxValue;
                int         nMaxIdx = 0;
                float       fMin1   = m_rgOverlay.Min(p => p);
                float       fMax1   = m_rgOverlay.Max(p => p);

                for (int i = 0; i < m_rgOverlay.Length; i++)
                {
                    if (fMin1 < 0 || fMax1 > 1)
                    {
                        m_rgOverlay[i] = (m_rgOverlay[i] - fMin1) / (fMax1 - fMin1);
                    }

                    if (m_rgOverlay[i] > fMax)
                    {
                        fMax    = m_rgOverlay[i];
                        nMaxIdx = i;
                    }
                }

                for (int i = 0; i < m_rgOverlay.Length; i++)
                {
                    drawProbabilities(g, nX, nY, nWid1, nHt1, i, m_rgOverlay[i], fMin1, fMax1, clrMap.GetColor(i + 1), (i == nMaxIdx) ? true : false);
                    nX += nWid1;
                }
            }
        }