コード例 #1
0
        private void initBColorbar()
        {
            int  len = BpicBox.Width * BpicBox.Height;
            int  index;
            byte r = 0;
            byte g = 0;
            byte b = 0;

            byte[] dataForColor  = new byte[len * 3];
            Bitmap imageForColor = new Bitmap(BpicBox.Width, BpicBox.Height);

            for (int i = 0; i < BpicBox.Height; i++)
            {
                if (RGBImage.getRGB(((double)i) / BpicBox.Height, ref r, ref g, ref b))
                {
                    for (int j = 0; j < BpicBox.Width; j++)
                    {
                        index = 3 * (i * BpicBox.Width + j);
                        dataForColor[index]     = b;
                        dataForColor[index + 1] = g;
                        dataForColor[index + 2] = r;
                    }
                }
            }
            BpicBox.Image = RGBImage.CreateBitmap(dataForColor, imageForColor);
        }
コード例 #2
0
        /// <summary>
        /// Returns a color image with the same dimensions
        /// The R, G, B values of the result image at (i, j) are determined by using the value of image
        /// at (i, j) to index three lookup tables. These lookup tables implement a false coloring scheme
        /// which maps small values to black, large values to white, and intermediate values to shades of red, orange, and yellow (in that order).
        /// </summary>
        /// <param name="image">Greyscale IImage<Double></param>
        /// <returns>Color IImage<Double> with a false coloring scheme</returns>
        public static IImage <RGB> MakeHotImage(this IImage <double> image)
        {
            RGBImage sp2 = new RGBImage(image.Width, image.Height);

            double maximum = double.MinValue;
            double minimum = double.MaxValue;

            int n = image.Length;

            for (int i = 0; i < n; i++)
            {
                double value = image[i];
                if (value > maximum)
                {
                    maximum = value;
                }
                if (value < minimum)
                {
                    minimum = value;
                }
            }

            for (int i = 0; i < n; i++)
            {
                double value = image[i];
                double r     = rhot(minimum, maximum, value);
                double g     = ghot(minimum, maximum, value);
                double b     = bhot(minimum, maximum, value);
                sp2.Data[i] = new RGB(r, g, b);
            }

            return(sp2);
        }
コード例 #3
0
        private void btnLoadImage_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                img = new RGBImage(openFileDialog1.FileName, ColorPlane.eGreen);

                AdvColor[,] new_pixels = img.MedianFilter(img.MirrorByKernel(3, 3, img.HistogramStretch(.1, .9, ColorPlane.eGreen)), 3);

                //RGBImage blurred = new RGBImage(img.GaussianBlur2D(15, 15, 1.5));
                RGBImage blurred = new RGBImage(img.GaussianBlur1D(1, 15, 1.5, img.GaussianBlur1D(15, 1, 1.5, new_pixels)));

                blurred.CalcSobel("sobel_mag.png", "sobel_dir.png");

                RGBImage mag_image = new RGBImage("sobel_mag.png", ColorPlane.eGreen);
                RGBImage dir_image = new RGBImage("sobel_dir.png", ColorPlane.eGreen);

                double threshold = mag_image.CalcOtsuThreshold();

                AdvColor[,] mag_image_prime = mag_image.Binarization(threshold, ColorPlane.eGreen);
                AdvColor[,] dir_image_prime = dir_image.Binzarization(255, ColorPlane.eGreen, mag_image_prime);

                mag_image.SaveToImage(mag_image_prime, "mag_image_prime.png");
                dir_image.SaveToImage(dir_image_prime, "dir_image_prime.png");

                RGBImage new_mag_image = new RGBImage(mag_image_prime);
                RGBImage new_dir_image = new RGBImage(dir_image_prime);

                mean = new_mag_image.Mean(ColorPlane.eGreen);

                textBox1.Text = "Mean: " + mean.ToString() + Environment.NewLine + "Mean - Dir: " + new_dir_image.Mean(ColorPlane.eGreen).ToString();
            }
        }
コード例 #4
0
ファイル: Controller.cs プロジェクト: togores/Vitruvius
        /// <summary>
        /// Construtor padrão.
        /// </summary>
        private Controller()
        {
            context = new Context();
            while (true)              // espera que o Kinect esteja corretamente conectado
            {
                try {
                    userManager = new UserManager(context);
                    depthSensor = new DepthSensor(context);
                    rgbCamera   = new RGBCamera(context);
                }
                catch (Exception) {
                    if (MessageBox.Show("Kinect is not connected. Connect and retry.", "Error", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        continue;
                    }
                    Application.Current.Shutdown();
                }
                break;
            }

            depthImage     = new DepthImage();
            rgbImage       = new RGBImage();
            drawDepthImage = false;
            drawRGBImage   = false;

            time          = DateTime.Now;
            windowManager = new WindowManager();

            observer = new Observer(new GestureManager(), Parameterization.Extractor, Parameterization.Filter);
            recorder = new Recorder();
            realtime = true;
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: zer09/tesseractdotnet
        private void OpenFile(string fileName)
        {
            ClearRenderingData();

            IImage rgbImage = new RGBImage();

            string sCommand = SupportedImageActions.Load;

            object[] inputs  = new object[] { fileName };
            object[] outputs = null;

            rgbImage.DoCommand(sCommand, inputs, ref outputs);

            Image image = ToImage(rgbImage);

            // update currnt grey image
            FileName = fileName;
            _image   = rgbImage;

            // update image for image viewer
            UpdateImageViewer(image);

            List <Word> wordList = null;

            this.UpdateImageViewer(wordList);
        }
コード例 #6
0
 /// <summary>
 /// 拷贝
 /// </summary>
 /// <param name="imageData"></param>
 public void Copy(RGBImage imageData)
 {
     Array.Copy(imageData.ImageData, ImageData, imageData.ImageData.Length);
     Timestamp = imageData.Timestamp;
     width     = imageData.width;
     height    = imageData.height;
 }
コード例 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Histogram histogram = img.BuildHistogram();

            //low bins to 0 out
            int      low_bins  = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .10));
            AdvColor low_color = histogram.GetBinColor(low_bins);

            int high_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(img.GetHeight() * img.GetWidth() * .90));

            AdvColor high_color = histogram.GetBinColor(high_bins);

            AdvColor[,] pixels = img.HistogramStretch(low_color, high_color, histogram, ColorPlane.eGreen);

            SortedDictionary <AdvColor, int> bins = histogram.GetHistogram();

            foreach (KeyValuePair <AdvColor, int> bin in bins)
            {
                chart1.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value);
            }

            RGBImage img2 = new RGBImage(pixels);

            img.SaveToImage(pixels, "histo_stretch.png");

            Histogram histogram2 = img2.BuildHistogram();

            SortedDictionary <AdvColor, int> bins2 = histogram2.GetHistogram();

            foreach (KeyValuePair <AdvColor, int> bin in bins2)
            {
                chart2.Series["Series1"].Points.AddXY(bin.Key.GetColor(ColorPlane.eGreen), bin.Value);
            }
        }
コード例 #8
0
 public MatrixFilterData(RGBImage image, int startI, int endI, int startJ, int endJ)
 {
     this.RGBImage = image;
     this.StartIndexI = startI;
     this.EndIndexI = endI;
     this.StartIndexJ = startJ;
     this.EndIndexJ = endJ;
     this.GreyImage = null;
 }
コード例 #9
0
        public void Setup()
        {
            var fileName = @"TestImages\TestImage.jpg";

            using (var fileStream = File.OpenRead(fileName))
            {
                image = RGBImage.FromStream(fileStream);
            }
        }
コード例 #10
0
        public void Run()
        {
            var fileName = @"TestImages\TestImage.jpg";

            using (var fileStream = File.OpenRead(fileName))
            {
                var image = RGBImage.FromStream(fileStream);
                image.EdgePreservingSmoothing().SaveToFile(Path.Combine(Directory.GetCurrentDirectory(), "TestImages",
                                                                        $"{Path.GetFileNameWithoutExtension(fileName)}_Processed.jpg"));
            }
        }
コード例 #11
0
        private void btnOutputImage_Click(object sender, EventArgs e)
        {
            AdvColor[,] new_pixels   = img.GaussianBlur1D(1, 15, 1.6, null);
            AdvColor[,] newer_pixels = img.GaussianBlur1D(15, 1, 1.6, new_pixels);

            img.SaveToImage(newer_pixels, "1DGaussianBlur.png");

            RGBImage img_1D = new RGBImage("1DGaussianBlur.png", ColorPlane.eGreen);
            double   mean   = img_1D.Mean(ColorPlane.eGreen);

            textBox1.Text += "1D Gaussian Image Mean: " + mean + System.Environment.NewLine;
        }
コード例 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            AdvColor[,] new_pixels = img.GaussianBlur2D(15, 15, 1.6);

            img.SaveToImage(new_pixels, "2DGaussianBlur.png");

            RGBImage img_2D = new RGBImage("2DGaussianBlur.png", ColorPlane.eGreen);

            double mean = img_2D.Mean(ColorPlane.eGreen);

            textBox1.Text += "2D Gaussian Image Mean: " + mean + System.Environment.NewLine;
        }
コード例 #13
0
ファイル: LabelImage.cs プロジェクト: qianc123/visionnet
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="image">Color image in label image format</param>
        /// <param name="dictionary">Color dictionary lookup for interpreting the colors in the source image into labels</param>
        public unsafe LabelImage(RGBImage image, LabelDictionary dictionary)
        {
            _handler = new ShortArrayHandler(image.Rows, image.Columns, 1);
            short index = 1;

            short[, ,] lookup = new short[256, 256, 256];
            if (dictionary != null)
            {
                Dictionary <Color, short> labelLookup = dictionary.LabelLookup;
                foreach (Color c in labelLookup.Keys)
                {
                    lookup[c.R, c.G, c.B] = labelLookup[c];
                }
            }
            else
            {
                for (int R = 0; R < 256; R++)
                {
                    for (int G = 0; G < 256; G++)
                    {
                        for (int B = 0; B < 256; B++)
                        {
                            lookup[R, G, B] = -1;
                        }
                    }
                }
            }

            fixed(byte *imageSrc = image.RawArray)
            {
                fixed(short *labelsSrc = RawArray)
                {
                    byte * imagePtr  = imageSrc;
                    short *labelsPtr = labelsSrc;

                    int count = image.Rows * image.Columns;

                    while (count-- > 0)
                    {
                        byte  R     = *imagePtr++;
                        byte  G     = *imagePtr++;
                        byte  B     = *imagePtr++;
                        short label = lookup[R, G, B];
                        if (label < 0)
                        {
                            label           = index;
                            lookup[R, G, B] = index++;
                        }
                        *labelsPtr++ = label;
                    }
                }
            }
        }
コード例 #14
0
        private void button2_Click(object sender, EventArgs e)
        {
            img.CalcSobel("mag_image.png", "dir_image.png");

            RGBImage mag = new RGBImage("mag_image.png", ColorPlane.eGreen);
            RGBImage dir = new RGBImage("mag_image.png", ColorPlane.eGreen);

            double mean_mag = mag.Mean(ColorPlane.eGreen);
            double mean_dir = dir.Mean(ColorPlane.eGreen);

            textBox1.Text += "Mag Image Mean: " + mean_mag + System.Environment.NewLine;
            textBox1.Text += "Dir Image Mean: " + mean_dir + System.Environment.NewLine;
        }
コード例 #15
0
        private void btnLoadImage_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                img     = new RGBImage(openFileDialog1.FileName, ColorPlane.eGreen);
                mean    = img.Mean(ColorPlane.eGreen);
                max     = img.Max(ColorPlane.eGreen);
                min     = img.Min(ColorPlane.eGreen);
                std_dev = img.StdDev(ColorPlane.eGreen);

                textBox1.Text = "Mean: " + mean.ToString() + Environment.NewLine + "Std. Dev.: " + std_dev.ToString() + Environment.NewLine + "Min: " + min.ToString()
                                + Environment.NewLine + "Max: " + max.ToString();
            }
        }
コード例 #16
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="imageData">数据</param>
 /// <param name="IsCompress">是否压缩,压缩了的数据直接传进c++有可能会报错</param>
 public RGBImage(RGBImage imageData, bool IsCompress)
 {
     if (!IsCompress)
     {
         ImageData = new byte[RGBDATALENGTH];
     }
     else
     {
         ImageData = new byte[RGBDATALENGTH];
     }
     Array.Copy(imageData.ImageData, ImageData, imageData.ImageData.Length);
     Timestamp = imageData.Timestamp;
     width     = imageData.width;
     height    = imageData.height;
 }
コード例 #17
0
ファイル: LabelImage.cs プロジェクト: qianc123/visionnet
        /// <summary>
        /// Converts the label image to an RGB Image using <paramref name="dictionary"/>.
        /// </summary>
        /// <param name="dictionary">The label lookup dictionary</param>
        /// <returns>An RGB Image</returns>
        public unsafe RGBImage ToRGBImage(LabelDictionary dictionary)
        {
            updateLabelCounts();
            int labelCount = _labelCounts.Keys.Max() + 1;

            Color[] colors = new Color[labelCount];
            colors[0] = Colors.Black;
            for (short i = 1; i < labelCount; i++)
            {
                colors[i] = LabelDictionary.LabelToColor(i);
            }
            if (dictionary != null)
            {
                colors = new Color[dictionary.Count];
                Dictionary <Color, short> lookupTable = dictionary.LabelLookup;
                foreach (Color key in lookupTable.Keys)
                {
                    colors[lookupTable[key]] = key;
                }
            }
            RGBImage rgb = new RGBImage(Rows, Columns);

            fixed(short *labelsSrc = RawArray)
            {
                fixed(byte *rgbSrc = rgb.RawArray)
                {
                    short *labelsPtr = labelsSrc;
                    byte * rgbPtr    = rgbSrc;

                    int count = Rows * Columns;

                    while (count-- > 0)
                    {
                        short label = *labelsPtr++;
                        if (label < 0)
                        {
                            label = 0;
                        }
                        Color c        = colors[label];
                        *     rgbPtr++ = c.R;
                        *     rgbPtr++ = c.G;
                        *     rgbPtr++ = c.B;
                    }
                }
            }

            return(rgb);
        }
コード例 #18
0
        public static JpegEncoder WithImageFromFile(string filename)
        {
            FileStream   fileStream   = new FileStream(filename, FileMode.Open);
            MemoryStream memoryStream = new MemoryStream();

            fileStream.CopyTo(memoryStream);

            fileStream.Close();

            memoryStream.Seek(0, SeekOrigin.Begin);

            RGBImage   rgbImage   = RGBImage.RGBImageBuilder.From(memoryStream).Build();
            YCbCrImage yCbCrImage = ColorChannels.RgbToYCbCr(rgbImage);

            return(new JpegEncoder(yCbCrImage));
        }
コード例 #19
0
        public static IImage <RGB> ToRgb(IImage <double> red, IImage <double> green, IImage <double> blue)
        {
            if (red.Width != green.Width || blue.Width != green.Width)
            {
                throw new ArgumentException("Images must have the same width");
            }

            if (red.Height != green.Height || blue.Height != green.Height)
            {
                throw new ArgumentException("Images must have the same height");
            }

            var result = new RGBImage(red.Width, red.Height);

            RGB[] resultData = result.Data;
            for (int i = 0; i < resultData.Length; i++)
            {
                resultData[i] = new RGB(red[i], green[i], blue[i]);
            }

            return(result);
        }
コード例 #20
0
        public static YCbCrImage RgbToYCbCr(RGBImage rgbImage)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            ColorChannel luminance = new ColorChannel(rgbImage.GetWidth(), rgbImage.GetHeight());
            ColorChannel cbChannel = new ColorChannel(rgbImage.GetWidth(), rgbImage.GetHeight());
            ColorChannel crChannel = new ColorChannel(rgbImage.GetWidth(), rgbImage.GetHeight());

            int height = rgbImage.GetHeight();

            if (height < 192)
            {
                for (int y = 0; y < rgbImage.GetHeight(); y++)
                {
                    for (int x = 0; x < rgbImage.GetWidth(); x++)
                    {
                        YCbCr converted = ConvertRgbtoYCbCr(rgbImage.GetRGBAt(x, y));
                        luminance.SetPixel(x, y, converted.GetLuminanceChannel());
                        cbChannel.SetPixel(x, y, converted.GetCbChannel());
                        crChannel.SetPixel(x, y, converted.GetCrChannel());
                    }
                }
            }
            else
            {
                int threadCount = 16;

                if (height < 500)
                {
                    threadCount = 4;
                }
                else if (height < 1000)
                {
                    threadCount = 8;
                }

                CountdownEvent e = new CountdownEvent(1);

                for (int i = 0; i < height; i += height / threadCount)
                {
                    e.AddCount();
                    ThreadPool.QueueUserWorkItem(
                        state =>
                    {
                        object[] inp = state as object[];

                        //Console.WriteLine($"Thread with row {(int) inp[0]} to row {(int) inp[1]} started...");

                        int upper = (int)inp[1];

                        for (int row = (int)inp[0]; row < upper; row++)
                        {
                            for (int x = 0; x < rgbImage.GetWidth(); x++)
                            {
                                YCbCr converted = ConvertRgbtoYCbCr(rgbImage.GetRGBAt(x, row));
                                luminance.SetPixel(x, row, converted.GetLuminanceChannel());
                                cbChannel.SetPixel(x, row, converted.GetCbChannel());
                                crChannel.SetPixel(x, row, converted.GetCrChannel());
                            }
                        }

                        e.Signal();
                    }, new object[] { i, i + (height / threadCount) });
                }

                e.Signal();
                e.Wait();
            }

            Console.WriteLine("Finished RGB to YCbCr conversion in "
                              + stopwatch.ElapsedMilliseconds / 1000d
                              + " seconds");

            stopwatch.Stop();

            return(new YCbCrImage(luminance,
                                  cbChannel,
                                  crChannel,
                                  rgbImage.GetOriginalWidth(),
                                  rgbImage.GetOriginalHeight()));
        }
コード例 #21
0
        public PNG(string fileName)
        {
            Signature    sig        = new Signature();
            FileStream   fileStream = File.OpenRead(fileName);
            BinaryReader reader     = new BinaryReader(fileStream);

            byte[] signature = reader.ReadBytes(8);
            Console.WriteLine(sig.Compare(signature) + " - " + sig.ToString());

            DataChunks = new List <IDataChunk>();

            List <byte[]>    allDataBytes = new List <byte[]>();
            List <DataChunk> allChunks    = new List <DataChunk>();

            while ((reader.BaseStream.Position < reader.BaseStream.Length))
            {
                DataChunk chunk    = new DataChunk(reader, this);
                ulong     chunkLen = CalculateCRCPolynomial((uint)chunk.Data.Length + 4);

                if (chunk.DataChunkRepresentation is DataChunk.ImageDataChunkRepresentation)
                {
                    allDataBytes.Add(chunk.Data);
                }
                else
                {
                    Console.WriteLine($"[{chunk.Length}],[{chunk.ChunkType}],[{chunk.CRC}],[{chunk.Data.Length}]");
                    if (!string.IsNullOrEmpty(chunk.PropertyString))
                    {
                        Console.WriteLine(chunk.PropertyString);
                    }
                    DataChunks.Add(chunk);
                    allChunks.Add(chunk);
                }
            }
            reader.Close();
            fileStream.Close();
            int allBytesCount = 0;

            for (int z = 0; z < allDataBytes.Count; z++)
            {
                allBytesCount += allDataBytes[z].Length;
            }
            byte[] dataBytes = new byte[allBytesCount];
            allBytesCount = 0;
            for (int z = 0; z < allDataBytes.Count; z++)
            {
                allDataBytes[z].CopyTo(dataBytes, allBytesCount);
                allBytesCount += allDataBytes[z].Length;
            }

            MemoryStream output       = new MemoryStream();
            MemoryStream memoryStream = new MemoryStream(dataBytes);

            memoryStream.Position = 0;
            byte[] zlibHeaderBytes = new byte[2];
            memoryStream.Read(zlibHeaderBytes, 0, 2);
            DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress);

            deflateStream.CopyTo(output);
            deflateStream.Flush();
            output.Position = 0;
            byte[] outputBytes = new byte[output.Length];
            int    arrLength   = (int)output.Length;

            output.Read(outputBytes, 0, arrLength);

            MemoryStream streamReader = new MemoryStream(outputBytes);
            DataChunk    header       = allChunks.Where(x => x.ChunkType.ToLower() == "ihdr").FirstOrDefault();
            Dictionary <string, DataChunk.DataObject> headerProperties = header.DataChunkRepresentation.ToProperties(header.Data);
            uint width     = (uint)headerProperties["Width"].Value;
            uint height    = (uint)headerProperties["Height"].Value;
            byte colorType = (byte)headerProperties["ColorType"].Value;
            byte bitDepth  = (byte)headerProperties["BitDepth"].Value;

            streamReader.Position = 0;

            if (bitDepth <= 8)
            {
                RGBImage <byte> image = new RGBImage <byte>(width, height);
                for (uint y = 0; y < height; y++)
                {
                    byte filterByte = (byte)streamReader.ReadByte();
                    if (filterByte == 0)
                    {
                        if (colorType == 2)
                        {
                            for (uint x = 0; x < width; x++)
                            {
                                byte             r     = (byte)streamReader.ReadByte();
                                byte             g     = (byte)streamReader.ReadByte();
                                byte             b     = (byte)streamReader.ReadByte();
                                RGBAColor <byte> color = new RGBAColor <byte>(r, g, b, 255);
                                image.Colors[x, y] = color;
                            }
                        }
                        else if (colorType == 6)
                        {
                            for (uint x = 0; x < width; x++)
                            {
                                byte             r     = (byte)streamReader.ReadByte();
                                byte             g     = (byte)streamReader.ReadByte();
                                byte             b     = (byte)streamReader.ReadByte();
                                byte             a     = (byte)streamReader.ReadByte();
                                RGBAColor <byte> color = new RGBAColor <byte>(r, g, b, a);
                                image.Colors[x, y] = color;
                            }
                        }
                    }
                }
                deflateStream.Close();
                memoryStream.Close();
                output.Close();
                streamReader.Close();
                Image = image;
            }
            else if (bitDepth == 16)
            {
                RGBImage <uint> image = new RGBImage <uint>(width, height);
                for (uint y = 0; y < height; y++)
                {
                    byte filterByte = (byte)streamReader.ReadByte();
                    if (filterByte == 0)
                    {
                        if (colorType == 2)
                        {
                            for (uint x = 0; x < width; x++)
                            {
                                uint             r     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                uint             g     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                uint             b     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                RGBAColor <uint> color = new RGBAColor <uint>(r, g, b, 255);
                                image.Colors[x, y] = color;
                            }
                        }
                        else if (colorType == 6)
                        {
                            for (uint x = 0; x < width; x++)
                            {
                                uint             r     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                uint             g     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                uint             b     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                uint             a     = (uint)streamReader.ReadByte() << 8 | (uint)streamReader.ReadByte();
                                RGBAColor <uint> color = new RGBAColor <uint>(r, g, b, a);
                                image.Colors[x, y] = color;
                            }
                        }
                    }
                }
                deflateStream.Close();
                memoryStream.Close();
                output.Close();
                streamReader.Close();
                Image16Bits = image;
            }
        }
コード例 #22
0
 public Bitmap ToBitmap(RGBImage image)
 {
     throw new NotImplementedException();
 }
コード例 #23
0
ファイル: ScanSeries.cs プロジェクト: zjyu1/ASCAN
        public void add(GatePacket gatePacket)
        {
            int    sourceID = (int)gatePacket.head.id;
            int    curXPos = (int)gatePacket.tag.stampPos[0];
            int    curYPos = (int)gatePacket.tag.stampPos[1];
            int    num = (int)gatePacket.tag.cellNum;
            byte   r = 0, g = 0, b = 0;
            double amp = 0;
            int    index;
            int    flag;

            //        if (gatePacket.tag.stampPos[0] == 0)
            //             clear();

            /*if (gatePacket.tag.stampPos[0] <= 1000 && gatePacket.tag.stampInc[0] == 1000)
             * {
             *  flag = 0;
             * }
             * else if (gatePacket.tag.stampPos[0] >= 98000 && gatePacket.tag.stampInc[0] == -1000)
             * {
             *  flag = 1;
             * }*/
            //int[] pos = new int[8192];

            if (this.rcdCnt < 500)
            {
                rcd_posx[this.rcdCnt] = (int)gatePacket.tag.stampPos[0];
                rcd_posy[this.rcdCnt] = (int)gatePacket.tag.stampPos[1];
                rcd_inc[this.rcdCnt]  = (int)gatePacket.tag.stampInc[0];

                rcd_cell[this.rcdCnt] = (int)gatePacket.tag.cellNum;

                this.rcdCnt++;
            }
            else
            {
                flag = 1;
            }


            int X;
            int Y;

            //int X = (int)Math.Round(curXPos / cscanCofig.XResolution);//X轴坐标规整
            //int Y = (int)Math.Round(curYPos / cscanCofig.YResolution);//Y轴坐标规整
            //view(gatePacket);
            for (int k = 0; k < num; k++)
            {
                amp = gatePacket.measureDate[k];
                if (cscanCofig.ScanAxisIndex == (int)ScanAxis.X)//扫描轴为X轴
                {
                    int inc = (int)((gatePacket.tag.stampInc[0] / (cscanCofig.XResolution * 1000)) * cscanCofig.XResolution * 1000);
                    X = (int)Math.Round((double)(curXPos + inc * k) / (cscanCofig.XResolution * 1000)) - 1;
                    Y = (int)Math.Round((double)curYPos / (cscanCofig.YResolution * 1000));
                }
                else //扫描轴为Y轴
                {
                    int inc = (int)(gatePacket.tag.stampInc[1] / (cscanCofig.YResolution * 1000) * cscanCofig.YResolution * 1000);
                    X = (int)Math.Round((double)curXPos / (cscanCofig.XResolution * 1000)) - 1;
                    Y = (int)Math.Round((double)(curYPos + inc * k) / (cscanCofig.YResolution * 1000));
                }


                if (X > (XSampleNum - 1))
                {
                    X = XSampleNum - 1;
                }

                if (Y > (YSampleNum - 1))
                {
                    Y = YSampleNum - 1;
                }

                if (this.rcdCnt < 500)
                {
                    rcd_X[this.rcdCnt] = X;
                    rcd_Y[this.rcdCnt] = Y;
                    this.rcdCnt++;
                }
                else
                {
                    flag = 1;
                }
                if (X >= 0 && X <= (XSampleNum - 1) && Y >= 0 && Y <= (YSampleNum - 1))
                {
                    if (RGBImage.getRGB((double)amp, ref r, ref g, ref b))
                    {
                        for (int i = 0; i < xScale; i++)
                        {
                            for (int j = 0; j < yScale; j++)
                            {
                                index                = 3 * ((Y * yScale + j) * bitmapWidth + X * xScale + i);
                                dateArray[index]     = b;
                                dateArray[index + 1] = g;
                                dateArray[index + 2] = r;
                            }
                        }
                    }
                }
            }
        }
コード例 #24
0
 public void FindComponents(RGBImage image)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
ファイル: ScanSeries.cs プロジェクト: zjyu1/ASCAN
        public void addNoSamplingDates(GatePacket gatePacket)
        {
            int constNum = ConstParameter.BscanPointNumPrePacket;
            int sourceID = (int)gatePacket.head.id;
            int curPos;
            int inc;

            if (bscanCofig.AscanIndex == (int)ScanAxis.X)
            {
                curPos = (int)gatePacket.tag.stampPos[0];
                inc    = (int)((gatePacket.tag.stampInc[0] / (bscanCofig.Resolution * 1000)) * bscanCofig.Resolution * 1000);
            }
            else
            {
                curPos = (int)gatePacket.tag.stampPos[1];
                inc    = (int)((gatePacket.tag.stampInc[1] / (bscanCofig.Resolution * 1000)) * bscanCofig.Resolution * 1000);
            }
            int    num = (int)gatePacket.tag.cellNum;
            int    pktNum = num / constNum;
            byte   r = 0, g = 0, b = 0;
            double amp = 0;
            int    index;

            for (int k = 0; k < pktNum; k++)
            {
                int start = k * constNum;
                int pos   = (int)Math.Round((curPos + inc * k) / (bscanCofig.Resolution * 1000)) - 2;
                //int pos = curPos + inc * k;

                //if (pos > bscanCofig.ScanLength)
                //    return;


                position = pos;

                for (int i = 0; i < pictureHeight; i++)
                {
                    index = i * constNum / pictureHeight;
                    if (index < num)
                    {
                        amp = gatePacket.measureDate[start + index];
                    }
                    else
                    {
                        amp = 0;
                    }

                    if (RGBImage.getRGB((double)amp, ref r, ref g, ref b))
                    {
                        if (bitmapWidth > sampleNum)    //画布的高度大于采样个数
                        {
                            if (pos >= 0 && pos <= (sampleNum - 1))
                            {
                                for (int j = (int)(pos * bitmapWidth / bscanCofig.ScanLength); j < (pos + bscanCofig.Resolution) * bitmapWidth / bscanCofig.ScanLength; j++)
                                {
                                    index                = i * stride + 3 * j;
                                    dateArray[index]     = b;
                                    dateArray[index + 1] = g;
                                    dateArray[index + 2] = r;
                                }
                            }
                        }
                        else
                        {
                            int j = (int)Math.Round(curPos / bscanCofig.Resolution);    //坐标规整
                            index                = i * stride + 3 * (j - 1);
                            dateArray[index]     = b;
                            dateArray[index + 1] = g;
                            dateArray[index + 2] = r;
                        }
                    }
                }
            }
        }
コード例 #26
0
ファイル: ScanSeries.cs プロジェクト: zjyu1/ASCAN
        public void addSamplingDates(GatePacket gatePacket, int realNum)
        {
            int constNum = ConstParameter.BscanPointNumPrePacket;
            int sourceID = (int)gatePacket.head.id;

            int curPos;
            int inc;

            if (bscanCofig.AscanIndex == (int)ScanAxis.X)
            {
                curPos = (int)gatePacket.tag.stampPos[0];
                inc    = (int)((gatePacket.tag.stampInc[0] / (bscanCofig.Resolution * 1000)) * bscanCofig.Resolution * 1000);
            }
            else
            {
                curPos = (int)gatePacket.tag.stampPos[1];
                inc    = (int)((gatePacket.tag.stampInc[1] / (bscanCofig.Resolution * 1000)) * bscanCofig.Resolution * 1000);
            }
            //int inc = (int)gatePacket.tag.stampInc[0];
            int    num = (int)gatePacket.tag.cellNum;
            int    pktNum = num / constNum;
            byte   r = 0, g = 0, b = 0;
            double amp        = 0;
            int    index      = 0;
            int    preUnit    = realNum / constNum;
            int    postUnit   = preUnit + 1;
            int    preNum     = constNum - realNum % constNum;
            int    changPoint = preNum * preUnit;


            //X = (int)Math.Round((curXPos + inc * k) / (cscanCofig.XResolution * 1000));
            //Y = (int)Math.Round(curYPos / (cscanCofig.YResolution * 1000));

            for (int k = 0; k < pktNum; k++)
            {
                int start = k * constNum;
                //int pos = curPos + inc * k;
                int pos = (int)Math.Round((curPos + inc * k) / (bscanCofig.Resolution * 1000));

                if (pos > bscanCofig.ScanLength)
                {
                    return;
                }

                for (int i = 0; i < pictureWidth; i++)
                {
                    index = (int)(i * realNum / pictureWidth);
                    if (index < changPoint)
                    {
                        amp = gatePacket.measureDate[start + index / preUnit];
                    }
                    else
                    {
                        int count = preNum + (index - changPoint) / postUnit;
                        amp = gatePacket.measureDate[start + count];
                    }

                    if (RGBImage.getRGB((double)amp, ref r, ref g, ref b))
                    {
                        if (bitmapHeight > sampleNum)//画布的高度大于采样个数
                        {
                            for (int j = (int)(pos * bitmapHeight / bscanCofig.ScanLength); j < (pos + bscanCofig.Resolution) * bitmapHeight / bscanCofig.ScanLength; j++)
                            {
                                index                = j * stride + 3 * i;
                                dateArray[index]     = b;
                                dateArray[index + 1] = g;
                                dateArray[index + 2] = r;
                            }
                        }
                        else
                        {
                            int j = (int)Math.Round(pos / bscanCofig.Resolution);//坐标规整
                            index                = j * stride + 3 * i;
                            dateArray[index]     = b;
                            dateArray[index + 1] = g;
                            dateArray[index + 2] = r;
                        }
                    }
                }
            }
        }
コード例 #27
0
        public BMP(string fileName)
        {
            FileStream   stream = File.OpenRead(fileName);
            BinaryReader reader = new BinaryReader(stream);

            byte[] header     = reader.ReadBytes(14);
            string headerType = "" + (char)header[0] + (char)header[1];
            ulong  fileSize   = GetULongFromBytesLE(header, 2);
            uint   reserved1  = GetUIntFromBytesLE(header, 6);
            uint   reserved2  = GetUIntFromBytesLE(header, 8);
            ulong  dataOffset = GetULongFromBytesLE(header, 10);

            this.BMPHeader = new BMP.Header(headerType, fileSize, reserved1, reserved2, dataOffset);

            byte[] dibHeaderSizeBytes = reader.ReadBytes(4);
            ulong  dibHeaderSize      = GetULongFromBytesLE(dibHeaderSizeBytes, 0);

            int[] windowsDIBSizes = { 40, 52, 56, 108, 124 };
            if (windowsDIBSizes.Contains((int)dibHeaderSize))
            {
                byte[] dibBytes          = reader.ReadBytes(36);
                ulong  width             = GetULongFromBytesLE(dibBytes, 0);
                ulong  height            = GetULongFromBytesLE(dibBytes, 4);
                uint   colorPlanes       = GetUIntFromBytesLE(dibBytes, 8);
                uint   bpp               = GetUIntFromBytesLE(dibBytes, 10);
                ulong  compressionMethod = GetULongFromBytesLE(dibBytes, 12);
                ulong  imageSize         = GetULongFromBytesLE(dibBytes, 16);
                ulong  horizontalPPM     = GetULongFromBytesLE(dibBytes, 20);
                ulong  verticalPPM       = GetULongFromBytesLE(dibBytes, 24);
                ulong  numberColors      = GetULongFromBytesLE(dibBytes, 28);
                ulong  importantColors   = GetULongFromBytesLE(dibBytes, 32);

                this.BMPHeader.WindowsHeader = new Header.DIBHeaderWindows()
                {
                    Bpp          = bpp, ColorPlanes = colorPlanes, CompressionMethod = compressionMethod,
                    Height       = height, HorizontalPPM = horizontalPPM, ImageSize = imageSize, ImportantColors = importantColors,
                    NumberColors = numberColors, VerticalPPM = verticalPPM, Width = width
                };
            }

            ulong extraBytesLength = dataOffset - (14 + dibHeaderSize);

            byte[] extraBytes = reader.ReadBytes((int)extraBytesLength);

            if (this.BMPHeader.WindowsHeader.Bpp == 8 && extraBytes.Length == 1024)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 256; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }
            else if (this.BMPHeader.WindowsHeader.Bpp == 4 && extraBytes.Length == 64)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 16; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }
            else if (this.BMPHeader.WindowsHeader.Bpp == 1 && extraBytes.Length == 8)
            {
                this.BMPHeader.Palette = new List <RGBAColor <byte> >();
                int p = 0;
                for (int z = 0; z < 2; z++)
                {
                    RGBAColor <byte> color = new RGBAColor <byte>(extraBytes[p], extraBytes[p + 1], extraBytes[p + 2], 255);
                    this.BMPHeader.Palette.Add(color);
                    p += 4;
                }
            }

            if (reader.BaseStream.Position == (long)dataOffset)
            {
                if (this.BMPHeader.WindowsHeader != null)
                {
                    if (this.BMPHeader.WindowsHeader.CompressionMethod == 0)
                    {
                        uint width   = (uint)this.BMPHeader.WindowsHeader.Width;
                        uint height  = (uint)this.BMPHeader.WindowsHeader.Height;
                        int  bpp     = (int)this.BMPHeader.WindowsHeader.Bpp;
                        int  rowSize = (int)((this.BMPHeader.WindowsHeader.Bpp * width + 31) / 32 * 4);
                        int  stride  = (int)((((width * bpp) + 31) & ~31) >> 3);

                        //int rowNumber = (int)height - 1;
                        int             rowNumber  = 0;
                        byte[]          pixelBytes = reader.ReadBytes((int)(this.BMPHeader.WindowsHeader.ImageSize));
                        RGBImage <byte> image      = new RGBImage <byte>((uint)width, (uint)height);

                        if (this.BMPHeader.WindowsHeader.Bpp >= 8)
                        {
                            uint bytesPerPixel = this.BMPHeader.WindowsHeader.Bpp / 8;
                            int  p             = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x++)
                                {
                                    RGBAColor <byte> color = null;
                                    if (bytesPerPixel == 1)
                                    {
                                        byte r = pixelBytes[p];
                                        color = this.BMPHeader.Palette[r];
                                        p++;
                                    }
                                    else if (bytesPerPixel == 3)
                                    {
                                        byte r = pixelBytes[p];
                                        byte g = pixelBytes[p + 1];
                                        byte b = pixelBytes[p + 2];
                                        color = new RGBAColor <byte>(r, g, b, 255);
                                        p    += 3;
                                    }
                                    else if (bytesPerPixel == 4)
                                    {
                                        byte r = pixelBytes[p];
                                        byte g = pixelBytes[p + 1];
                                        byte b = pixelBytes[p + 2];
                                        byte a = pixelBytes[p + 3];
                                        color = new RGBAColor <byte>(r, g, b, a);
                                        p    += 4;
                                    }
                                    else
                                    {
                                        color = new RGBAColor <byte>(0, 0, 0, 0);
                                    }
                                    image.Colors[x, rowNumber] = color;
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else if (this.BMPHeader.WindowsHeader.Bpp == 4)
                        {
                            int p = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x += 2)
                                {
                                    byte             r      = (byte)(pixelBytes[p] & 0xF);
                                    byte             r2     = (byte)(pixelBytes[p] >> 4);
                                    RGBAColor <byte> color  = null;
                                    RGBAColor <byte> color2 = null;
                                    color  = this.BMPHeader.Palette[r];
                                    color2 = this.BMPHeader.Palette[r2];
                                    p++;
                                    image.Colors[x, rowNumber] = color;
                                    if (x + 1 < width)
                                    {
                                        image.Colors[x + 1, rowNumber] = color2;
                                    }
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else if (this.BMPHeader.WindowsHeader.Bpp == 1)
                        {
                            int p = 0;
                            for (uint y = 0; y < height; y++)
                            {
                                for (uint x = 0; x < width; x += 8)
                                {
                                    byte[]             pixels = new byte[8];
                                    RGBAColor <byte>[] color  = new RGBAColor <byte> [8];
                                    for (int c = 0; c < 8; c++)
                                    {
                                        pixels[c] = (byte)((pixelBytes[p] >> c) & 0x1);
                                        if (x + c < width)
                                        {
                                            color[c] = this.BMPHeader.Palette[pixels[c]];
                                            image.Colors[x + c, rowNumber] = color[c];
                                        }
                                    }
                                    p++;
                                }
                                rowNumber++;
                                p = (int)y * stride;
                            }
                        }
                        else
                        {
                        }
                        this.Image = image;
                    }
                }
            }

            reader.Close();
            stream.Close();
        }
コード例 #28
0
        public static RGBImage EdgePreservingSmoothing(this RGBImage image)
        {
            var imageData     = image.ImageData;
            var height        = image.Height;
            var bytesPerLine  = image.BytesPerLine;
            var bitesPerPixel = RGBImage.BytesPerPixel;
            var filteringData = new byte[imageData.Length];

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < bytesPerLine; x += bitesPerPixel)
                {
                    var i = y * bytesPerLine + x;

                    if (x == 0 || y == 0 || x == bytesPerLine - bitesPerPixel || y == height - 1)
                    {
                        filteringData[i]     = imageData[i];
                        filteringData[i + 1] = imageData[i + 1];
                        filteringData[i + 2] = imageData[i + 2];

                        continue;
                    }

                    //Center pixel of convolution mask
                    var centerRed   = imageData[i + 2];
                    var centerGreen = imageData[i + 1];
                    var centerBlue  = imageData[i];

                    // Indexes of neighbor pixels of convolution mask
                    var id1 = (y - 1) * bytesPerLine + (x - bitesPerPixel);
                    var id2 = (y - 1) * bytesPerLine + x;
                    var id3 = (y - 1) * bytesPerLine + x + bitesPerPixel;
                    var id4 = y * bytesPerLine + (x - bitesPerPixel);
                    var id5 = y * bytesPerLine + x + bitesPerPixel;
                    var id6 = (y + 1) * bytesPerLine + (x - bitesPerPixel);
                    var id7 = (y + 1) * bytesPerLine + x;
                    var id8 = (y + 1) * bytesPerLine + x + bitesPerPixel;

                    var c1 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id1 + 2], imageData[id1 + 1],
                                            imageData[id1]);
                    var c2 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id2 + 2], imageData[id2 + 1],
                                            imageData[id2]);
                    var c3 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id3 + 2], imageData[id3 + 1],
                                            imageData[id3]);
                    var c4 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id4 + 2], imageData[id4 + 1],
                                            imageData[id4]);
                    var c5 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id5 + 2], imageData[id5 + 1],
                                            imageData[id5]);
                    var c6 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id6 + 2], imageData[id6 + 1],
                                            imageData[id6]);
                    var c7 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id7 + 2], imageData[id7 + 1],
                                            imageData[id7]);
                    var c8 = GetCoefficient(centerRed, centerGreen, centerBlue, imageData[id8 + 2], imageData[id8 + 1],
                                            imageData[id8]);

                    var csum = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8;

                    var resultRed = (imageData[id1 + 2] * c8 +
                                     imageData[id2 + 2] * c7 +
                                     imageData[id3 + 2] * c6 +
                                     imageData[id4 + 2] * c5 +
                                     imageData[id5 + 2] * c4 +
                                     imageData[id6 + 2] * c3 +
                                     imageData[id7 + 2] * c2 +
                                     imageData[id8 + 2] * c1) / csum;

                    var resultGreen = (imageData[id1 + 1] * c8 +
                                       imageData[id2 + 1] * c7 +
                                       imageData[id3 + 1] * c6 +
                                       imageData[id4 + 1] * c5 +
                                       imageData[id5 + 1] * c4 +
                                       imageData[id6 + 1] * c3 +
                                       imageData[id7 + 1] * c2 +
                                       imageData[id8 + 1] * c1) / csum;

                    var resultBlue = (imageData[id1] * c8 +
                                      imageData[id2] * c7 +
                                      imageData[id3] * c6 +
                                      imageData[id4] * c5 +
                                      imageData[id5] * c4 +
                                      imageData[id6] * c3 +
                                      imageData[id7] * c2 +
                                      imageData[id8] * c1) / csum;


                    filteringData[i + 2] = (byte)resultRed;
                    filteringData[i + 1] = (byte)resultGreen;
                    filteringData[i]     = (byte)resultBlue;
                }
            }

            return(new RGBImage(image.Width, height, bytesPerLine, filteringData));
        }
コード例 #29
0
        ShapeMap Test()
        {
            var rgbimage = new RGBImage(currentbtmp);

            var red   = new ColorChannelImage(rgbimage, ColorChannel.R);
            var green = new ColorChannelImage(rgbimage, ColorChannel.G);
            var blue  = new ColorChannelImage(rgbimage, ColorChannel.B);

            //GrayImage donegreen = null;
            //GrayImage donered = null;
            //GrayImage doneblue = null;
#if PARALLEL
            var task1 = Task.Factory.StartNew(() => ApplyEdgeDetection(green));
            var task2 = Task.Factory.StartNew(() => ApplyEdgeDetection(red));
            var task3 = Task.Factory.StartNew(() => ApplyEdgeDetection(blue));

            Task.WaitAll(task1, task2, task3);
#else
            ApplyEdgeDetection(green);
            ApplyEdgeDetection(red);
            ApplyEdgeDetection(blue);
#endif
            green = null;
            blue  = null;
            red   = null;

            var CombinedEdgeImage = rgbimage.GetBinaryImage();

            Stage1.Image = CombinedEdgeImage.GetBitmap();

            var blobs = CombinedEdgeImage.FindShapes();

            Stage2.Image = blobs.GetBitmap();
            var shapes = Shape.ShapeFromBinary(blobs);

            var bitmp2 = new Bitmap(300, 300, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            for (int i = 0; i < shapes.Count; i++)
            {
                for (int j = 0; j < shapes[i].Length; j++)
                {
                    var point = shapes[i].GetPoint(j);
                    bitmp2.SetPixel(point.X, point.Y, Color.White);
                }
            }

            Stage3.Image = bitmp2;

            for (int i = 0; i < shapes.Count; i++)
            {
                shapes[i].Reduce(5);
            }

            var bitmp = new Bitmap(300, 300, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            for (int i = 0; i < shapes.Count; i++)
            {
                for (int j = 0; j < shapes[i].Length; j++)
                {
                    var point = shapes[i].GetPoint(j);
                    bitmp.SetPixel(point.X, point.Y, Color.White);
                }
            }

            Stage4.Image = bitmp;

            //var targetShapes = shapes;
            Shape.OrderShapes(shapes);

            //Shape targetShapes = null;
            //for (int i = 0; i < shapes.Count; i++)
            //{
            //    if (shapes[i].Length >= (int)Shape.form.Circle)
            //    {
            //        targetShapes = shapes[i];
            //    }
            //}

            var targetTriangle = Shape.FindFormInForm(shapes, Shape.form.Circle, Shape.form.Triangle);
            var targetSquare   = Shape.FindFormInForm(shapes, Shape.form.Circle, Shape.form.Square);
            var targetCircle   = Shape.FindFormInForm(shapes, Shape.form.Circle, Shape.form.Circle);

            var targetShapes = new List <Shape> {
                targetTriangle, targetSquare, targetCircle
            };

            var map = new ShapeMap(targetShapes);

            return(map);
        }
コード例 #30
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="imageData">数据</param>
 public RGBImage(RGBImage imageData)
     : this(imageData, false)
 {
 }
コード例 #31
0
        private void btnLoadImage_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                img = new RGBImage(openFileDialog1.FileName, ColorPlane.eGreen);

                List <int> shapes = img.FindShapes();

                List <List <BoundaryMove> > shape_boundaries = new List <List <BoundaryMove> >();
                List <List <double> >       moments          = new List <List <double> >();
                List <List <BoundaryMove> > hull_bounadaries = new List <List <BoundaryMove> >();

                ConvexHull hull = new ConvexHull();
                for (int i = 0; i < shapes.Count; i++)
                {
                    List <BoundaryMove> boundary = img.GetBoundaryPixels(shapes[i]);
                    shape_boundaries.Add(boundary);
                    moments.Add(img.CalcMoments(shapes[i]));
                    hull_bounadaries.Add(hull.CalcQuickHull(boundary));
                }


                for (int i = 0; i < shapes.Count; i++)
                {
                    String       filename = String.Format("boundary{0}.txt", i + 1);
                    StreamWriter writer   = new StreamWriter(filename);

                    List <double> boundary_moments = moments[i];
                    for (int ii = 0; ii < boundary_moments.Count; ii++)
                    {
                        writer.Write(boundary_moments[ii]);
                        if (ii < boundary_moments.Count)
                        {
                            writer.Write(", ");
                        }
                    }

                    writer.Write(System.Environment.NewLine);

                    List <BoundaryMove> convexHull = hull_bounadaries[i];

                    for (int ii = 0; ii < convexHull.Count; ii++)
                    {
                        writer.WriteLine("" + convexHull[ii].X + ", " + convexHull[ii].Y);
                    }

                    List <BoundaryMove> boundary = shape_boundaries[i];
                    for (int ii = 0; ii < boundary.Count; ii++)
                    {
                        if (ii == 0)
                        {
                            writer.Write(boundary[ii].X + ", " + boundary[ii].Y);
                        }

                        writer.Write(boundary[ii].GetDirectionString() + " ");
                    }

                    writer.Flush();
                    writer.Close();
                }


                AdvColor[,] black_img = new AdvColor[256, 256];
                for (int i = 0; i < black_img.GetLength(0); i++)
                {
                    for (int j = 0; j < black_img.GetLength(1); j++)
                    {
                        black_img[i, j] = new AdvColor(0, 0, 0, ColorPlane.eGreen);
                    }
                }

                /*foreach (List<BoundaryMove> shape in shape_boundaries)
                 * {
                 *  img.OutlineShape(shape, black_img);
                 * }*/

                foreach (List <BoundaryMove> _hull in hull_bounadaries)
                {
                    img.OutlineHull(_hull, black_img);
                }

                img.SaveToImage(black_img, "TestConvexHullOutput.png");
            }
        }
コード例 #32
0
 public abstract void Apply(RGBImage image);
コード例 #33
0
 public void DetectText(RGBImage image)
 {
     throw new NotImplementedException();
 }
コード例 #34
0
        //For Tracking Object From Camera
        private void objectTrackingCam(Bitmap srcImage)
        {
            //Copy detected image to the new one
            if (radioButton1.Checked)
            {
                Bitmap newImage = (Bitmap)RGBImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }

            else if (radioButton2.Checked)
            {
                Bitmap newImage = (Bitmap)HSLImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }

            else if (radioButton3.Checked)
            {
                Bitmap newImage = (Bitmap)YCbCrImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }
        }
コード例 #35
0
 public override void Apply(RGBImage image)
 {
     throw new NotImplementedException();
 }