示例#1
0
文件: Form1.cs 项目: fulviofarina/PDI
        private void DiagonalsAndRotation2(int type)
        {
            imagen.GetChannels();

            extractArgs();


            if (type == 0)
            {
                factorDiago = 0.90;
            }



            imagen.detect = new Detector();



            Image <Rgb, byte> final = imagen.UIOne.Convert <Rgb, byte>().CopyBlank();

            int    resetvalor = 11;
            int    detectType = 2; //lines
            int    step       = 2;
            double threshold  = 220;
            int    max        = 19;
            int    xorder     = Convert.ToInt16(xorderbox.Text);
            int    yorder     = Convert.ToInt16(yorderbox.Text);

            imagen.SobelRoutine(detectType, step, threshold, max, resetvalor, xorder, yorder);

            imagen.GetDiagonalsRoutine(factorDiago);
            imagen.detect.DrawDiagonals(ref final);


            imagen.detect.GetAvgDiagonalsPosNeg(true);

            this.rgbbox.Image = final.Bitmap;

            //  MessageBox.Show("1.1");

            Rgb r = new Rgb(255, 255, 255);

            final = final.InRange(r, r).Convert <Rgb, byte>().Clone();

            this.segmentBox.Image = final.Bitmap;

            //
            final = final.CopyBlank();
            //  MessageBox.Show("1.2");

            Rgb[] color = new Rgb[3];
            imagen.detect.PickColorsAvg(type, ref color);
            Image <Rgb, byte>[] arr = imagen.detect.DrawDetectedAvg(ref final, ref color, false);


            printSteps(ref final, ref arr);

            //  MessageBox.Show("1.2");

            imagen.FindRotation(lastSum);


            this.richTextBox1.Text = imagen.detect.msgBuilder.ToString();
            this.segmentBox.Image  = rgbbox.Image;


            //factores

            Image <Rgba, byte> other = imagen.imgUtil.rotated.Clone();


            ImgDB.BasicInfoRow red   = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 0);
            ImgDB.BasicInfoRow green = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 1);
            ImgDB.BasicInfoRow blue  = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 2);
            ImgDB.BasicInfoRow alpha = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 3);



            //imagen.imgUtil.rotated._EqualizeHist() ;
            Img.ChangeColor(ref imagen.imgUtil.rotated, (float)red.Factor, (float)green.Factor, (float)blue.Factor, (float)alpha.Factor);
            //imagen.UIOne = imagen.imgUtil.rotated;
            this.rgbbox.Image = imagen.imgUtil.rotated.Bitmap;
            // this.matrixBox.Matrix = imagen.imgUtil.rotated.Mat.Data;

            imagen.imgUtil.rotated.Save(imagen.path + "\\" + imagen.curentfilename.Replace(".jpg", ".out.jpg"));
            //  originalBox.Image = imagen.escaledUI.Bitmap;


            float sum = (float)(red.Avg + green.Avg + blue.Avg);

            sum /= 3;
            float rF = 1;
            float gF = 1;
            float bF = 1;
            float AF = 1;

            rF = (float)(sum / red.Avg);
            gF = (float)(sum / green.Avg);
            bF = (float)(sum / blue.Avg);


            Img.ChangeColor(ref other, rF, gF, bF, AF);


            /*
             *
             * // CvInvoke.CLAHE(other, 1, new Size(10, 10), other);
             * double radius = Img.CalculateDiagonalLenght(other.Width, other.Height);
             * radius /= 2;
             * Point p = imagen.GetMiddlePointCanvas(radius, ref other);
             * Rectangle rec = new Rectangle(p.X , p.Y , 2, 2);
             * //  Rectangle rec = new Rectangle(p.X-(p.X*1/5), p.Y+ (p.Y * 3 / 2), 150,150);
             * //  other.ROI = rec;
             * Image<Rgba,byte> pantone  = other.GetSubRect(rec);
             * //  other.ROI = rec;
             * Point ul = new Point(rec.X, rec.Y);
             * Point bl = new Point(rec.Left, rec.Bottom);
             * Point ur = new Point(rec.Right, rec.Top);
             * Point br = new Point(rec.Right, rec.Bottom);
             * other.DrawPolyline(new Point[] { ul, bl, br, ur }, true, new Rgba(255, 0, 0, 255), 2, Emgu.CV.CvEnum.LineType.FourConnected);
             * //  source.CopyTo(destiny);
             * //   other.ROI = Rectangle.Empty;
             *
             *
             */


            // this.segmentBox.Image = pantone.Bitmap;
            this.segmentBox.Image = other.Bitmap;
        }
示例#2
0
        public BasicInfo(ref Image <Rgba, byte> input)
        {
            table = new ImgDB.BasicInfoDataTable();

            int    nBins  = 256;
            RangeF range1 = new RangeF(0, 255);

            DenseHistogram hist = new DenseHistogram(nBins, range1);

            Image <Gray, byte>[] isg = input.Split();

            histogramsRgba = new List <float[]>();
            averagesRgba   = new List <Gray>();
            sdsRgba        = new List <MCvScalar>();


            for (short i = 0; i < isg.Count(); i++)
            {
                hist.Calculate(new Image <Gray, byte>[] { isg[i] }, false, null);
                float[] values = hist.GetBinValues();
                histogramsRgba.Add(values);

                Gray      gr = new Gray();
                MCvScalar sd = new MCvScalar();
                isg[i].AvgSdv(out gr, out sd);

                averagesRgba.Add(gr);
                sdsRgba.Add(sd);


                ImgDB.BasicInfoRow row = table.NewBasicInfoRow();
                row.Avg       = gr.Intensity;
                row.Histogram = values;
                row.SD        = sd.V0;
                row.Channel   = i;
                if (i == 0)
                {
                    row.ChannelName = "Red";
                }
                else if (i == 1)
                {
                    row.ChannelName = "Green";
                }
                else if (i == 2)
                {
                    row.ChannelName = "Blue";
                }
                else if (i == 3)
                {
                    row.ChannelName = "Alpha";
                }

                table.AddBasicInfoRow(row);
            }


            //factores
            float rF = 1;
            float gF = 1;
            float bF = 1;
            float AF = 1;

            ImgDB.BasicInfoRow red   = table.FirstOrDefault(o => o.Channel == 0);
            ImgDB.BasicInfoRow green = table.FirstOrDefault(o => o.Channel == 1);
            ImgDB.BasicInfoRow blue  = table.FirstOrDefault(o => o.Channel == 2);
            ImgDB.BasicInfoRow alpha = table.FirstOrDefault(o => o.Channel == 3);
            float sum = (float)(red.Avg + green.Avg + blue.Avg + alpha.Avg);

            sum /= 4;

            rF           = (float)(sum / red.Avg);
            gF           = (float)(sum / green.Avg);
            bF           = (float)(sum / blue.Avg);
            AF           = (float)(sum / alpha.Avg);
            red.Factor   = rF;
            green.Factor = gF;
            blue.Factor  = bF;
            alpha.Factor = AF;
        }