Esempio n. 1
0
        private void Interp(Graphics g, PointF[] pta, float[] cData, int npoints)
        {
            PointC[,] pts = new PointC[npoints + 1, npoints + 1];
            float x0  = pta[0].X;
            float x1  = pta[3].X;
            float y0  = pta[0].Y;
            float y1  = pta[1].Y;
            float dx  = (x1 - x0) / npoints;
            float dy  = (y1 - y0) / npoints;
            float C00 = cData[0];
            float C10 = cData[1];
            float C11 = cData[2];
            float C01 = cData[3];

            for (int i = 0; i <= npoints; i++)
            {
                float x = x0 + i * dx;
                for (int j = 0; j <= npoints; j++)
                {
                    float y = y0 + j * dy;
                    float C = (y1 - y) * ((x1 - x) * C00 +
                                          (x - x0) * C10) / (x1 - x0) / (y1 - y0) +
                              (y - y0) * ((x1 - x) * C01 +
                                          (x - x0) * C11) / (x1 - x0) / (y1 - y0);
                    pts[j, i] = new PointC(new PointF(x, y), C);
                }
            }

            //Create a new colour mapping
            ColorMap cm = new ColorMap();

            int[,] cmap = cm.Jet();
            float cmin = 0;           float cmax = 255;
            int   colorLength = cmap.GetLength(0);

            for (int i = 0; i <= npoints; i++)
            {
                for (int j = 0; j <= npoints; j++)
                {
                    int cindex = (int)Math.Round((colorLength * (pts[i, j].C - cmin) +
                                                  (cmax - pts[i, j].C)) / (cmax - cmin));
                    if (cindex < 1)
                    {
                        cindex = 1;
                    }
                    if (cindex > colorLength)
                    {
                        cindex = colorLength;
                    }
                    for (int k = 0; k < 4; k++)
                    {
                        pts[j, i].ARGBArray[k] = cmap[cindex - 1, k];
                    }
                }
            }

            //Draw the points
            for (int i = 0; i < npoints; i++)
            {
                for (int j = 0; j < npoints; j++)
                {
                    SolidBrush aBrush = new SolidBrush(Color.FromArgb(pts[i, j].ARGBArray[0],
                                                                      pts[i, j].ARGBArray[1], pts[i, j].ARGBArray[2], pts[i, j].ARGBArray[3]));
                    PointF[] points = new PointF[4] {
                        pts[i, j].pointf, pts[i + 1, j].pointf,
                        pts[i + 1, j + 1].pointf, pts[i, j + 1].pointf
                    };
                    g.FillPolygon(aBrush, points);
                    aBrush.Dispose();
                }
            }
        }
Esempio n. 2
0
        private void CreateThermalImage(Graphics g)
        {
            ColorMap cm   = new ColorMap();
            Random   rand = new Random();

            int[,] cmap = cm.Jet();
            int x0 = 10, y0 = 10;
            int width = 30, height = 30;

            PointC[,] pts = new PointC[8, 8];
            int   p       = 0;
            float minTemp = pixelValues.Min();
            float maxTemp = pixelValues.Max();

            pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
            pictureBox1.Location = new System.Drawing.Point(0, 0);

            //Remap float values to uint8 range 0-255
            for (int i = 0; i < 64; i++)
            {
                pixelValues[i] = RemapFloatToInt(pixelValues[i], minTemp, maxTemp, 0, 255);
            }

            //Create new points used for interpolation
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    pts[i, j] = new PointC(new PointF(x0 + width * j, y0 + height * i), pixelValues[p]);
                    p        += 1;
                }
            }

            float cmin        = 0;
            float cmax        = 255;
            int   colorLength = cmap.GetLength(0);

            // Create original pixelated color image using colour mapping in cmap
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int cindex = (int)Math.Round((colorLength * (pts[i, j].C - cmin) +
                                                  (cmax - pts[i, j].C)) / (cmax - cmin));
                    if (cindex < 1)
                    {
                        cindex = 1;
                    }
                    if (cindex > colorLength)
                    {
                        cindex = colorLength;
                    }
                    for (int k = 0; k < 4; k++)
                    {
                        pts[i, j].ARGBArray[k] = cmap[cindex - 1, k];
                    }
                }
            }

            //Create points used for drawing image
            p = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    pts[i, j] = new PointC(new PointF(x0 + width * j, y0 + height * i), pixelValues[p]);
                    p        += 1;
                }
            }

            //Draw new interpolated image using the pixelated colour image create above
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    PointF[] pta = new PointF[4] {
                        pts[i, j].pointf, pts[i + 1, j].pointf,
                        pts[i + 1, j + 1].pointf, pts[i, j + 1].pointf
                    };
                    float[] cdata = new float[4] {
                        pts[i, j].C, pts[i + 1, j].C,
                        pts[i + 1, j + 1].C, pts[i, j + 1].C
                    };
                    Interp(g, pta, cdata, 50);
                }
            }
        }