コード例 #1
0
ファイル: FormColor.cs プロジェクト: zhangzheng12/EmguCVTool
        private void button3_Click(object sender, EventArgs e)
        {
            VectorOfMat channels = new VectorOfMat();                      //创建vectorOfmat类型存储分离后的图像

            CvInvoke.Split(src, channels);                                 //通道分离
            InputOutputArray mix_channel = channels.GetInputOutputArray(); //获得数组

            Mat B_channel = mix_channel.GetMat(0);                         //获得第一通道
            Mat G_channel = mix_channel.GetMat(1);                         //获得第二通道
            Mat R_channel = mix_channel.GetMat(2);                         //获得第一通道

            imageBox2.Image = B_channel;                                   //显示第一通道
            imageBox3.Image = G_channel;                                   //显示第二通道
            imageBox4.Image = R_channel;                                   //显示第三通道
        }
コード例 #2
0
        /// <summary>
        /// Add salt-and-pepper noise to the given image.
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private IplImage Noise(IplImage source)
        {
            IplImage         result     = source.Clone();
            Mat              noise      = new Mat(source.Height, source.Width, MatType.CV_32F);
            InputOutputArray noiseArray = (InputOutputArray)noise;

            Cv2.Randu(noiseArray, (Scalar)0, (Scalar)255);
            noise = noiseArray.GetMat();

            int bound = 5;

            int   upperBound = 255 - bound;
            int   lowerBound = 0 + bound;
            float noiseValue;

            for (int y = 0; y < source.Height; y++)
            {
                for (int x = 0; x < source.Width; x++)
                {
                    noiseValue = noise.At <float>(y, x);

                    if (noiseValue >= upperBound)
                    {
                        result[y, x] = new CvScalar(255);
                    }
                    else if (noiseValue <= lowerBound)
                    {
                        result[y, x] = new CvScalar(0);
                    }
                }
            }

            return(result);
        }
コード例 #3
0
ファイル: FormColor.cs プロジェクト: zhangzheng12/EmguCVTool
        private void button1_Click(object sender, EventArgs e)
        {
            Image <Hsv, byte> hsvImage = src.Convert <Hsv, byte>();

            imageBox1.Image = hsvImage;

            VectorOfMat channels = new VectorOfMat();                      //创建vectorOfmat类型存储分离后的图像

            CvInvoke.Split(hsvImage, channels);                            //通道分离
            InputOutputArray mix_channel = channels.GetInputOutputArray(); //获得数组

            Mat H_channel = mix_channel.GetMat(0);                         //获得第一通道
            Mat S_channel = mix_channel.GetMat(1);                         //获得第二通道
            Mat V_channel = mix_channel.GetMat(2);                         //获得第一通道

            imageBox2.Image = H_channel;                                   //显示第一通道
            imageBox3.Image = S_channel;                                   //显示第二通道
            imageBox4.Image = V_channel;                                   //显示第三通道
        }