【问题标题】:Get values 1 or 0 of binary images获取二进制图像的值 1 或 0
【发布时间】:2014-03-01 06:39:47
【问题描述】:

我的代码包括:我打开要上传的图像,然后将其转换为灰度图像,然后再转换为二进制图像。但我有一个问题。如何获取二进制图像的值 (0,1) 以便使用 emgucv c# 创建具有该值的矩阵??

      OpenFileDialog Openfile = new OpenFileDialog();
      if (Openfile.ShowDialog() == DialogResult.OK)
      {
          Image<Gray, Byte> My_Image = new Image<Gray, byte>(Openfile.FileName);
          pictureBox1.Image = My_Image.ToBitmap();

          My_Image = My_Image.ThresholdBinary(new Gray(69), new Gray(255));
          pictureBox2.Image = My_Image.ToBitmap();


      }
  }

【问题讨论】:

    标签: visual-studio-2010 emgucv


    【解决方案1】:

    第二次发帖

    我想我误解了这个问题,很抱歉提供了错误的信息。但我想你可能会从这篇文章中得到一些理解? Work with matrix in emgu cv


    第一篇文章

    通过将 ThresholdBinary() 之后的结果 My_Image 传递给以下函数,您可以拥有关于二进制图像的 0 和 1 数组

    public int[] ZeroOneArray(Image<Gray, byte> binaryImage)
    {
        //get the bytes value after Image.ThresholdBinary() 
        //either 0 or 255
        byte[] imageBytes = binaryImage.Bytes;
        //change 255 to 1 and remain 0
        var binary_0_Or_255 = from byteInt in imageBytes select byteInt / 255;
        //convert to array
        int[] arrayOnlyOneOrZero = binary_0_Or_255.ToArray();
        //checking the array content
        foreach (var bin in arrayOnlyOneOrZero)
        {
            Console.WriteLine(bin);
        }
        return arrayOnlyOneOrZero;
    }
    

    这是你想要的吗?谢谢


    第三篇文章

    通过了解这一点,chris answer in error copying image to array,我为您编写了一个函数,用于将您的 灰度二值图像 转换为 灰度 矩阵图像

    public Image<Gray, double> GrayBinaryImageToMatrixImage(Image<Gray, byte> binaryImage)
    {
        byte[] imageBytes = binaryImage.Bytes;
        Image<Gray, double> gray_image_div = new Image<Gray, double>(binaryImage.Size);//empty image method one
        //or
        Image<Gray, double> gray_image_div_II = binaryImage.Convert<Gray, double>().CopyBlank();//empty image method two
    
        //transfer binaryImage array to gray image matrix
        for (int i = 0; i < binaryImage.Width; i++)
        {
                for (int j = 0; j < binaryImage.Height; j++)
                {
                    if (imageBytes[i*binaryImage.Width+j] == 0)
                    {
                        //grey image only one channel
                        gray_image_div.Data[i, j, 0] = 0;
                    }
                    else if (imageBytes[i*binaryImage.Width+j] == 255)
                    {
                        gray_image_div.Data[i, j, 0] = 255;
                    }
    
                }
            }
            return gray_image_div;
    }
    

    【讨论】:

    • 我会读你的答案。我想我想使用像像素一样的神经网络输入。出于这个原因,我读到将 NN 1 或 0 作为输入,我想从二进制图像中获取该值!
    • 那么我认为你可以从我的第一篇文章中获得 1 或 0 值。它将 binaryImage 字节更改为 1 或 0
    猜你喜欢
    • 1970-01-01
    • 2013-11-05
    • 2015-12-07
    • 2013-01-09
    • 2011-02-02
    • 1970-01-01
    • 2017-04-25
    • 2021-12-28
    • 1970-01-01
    相关资源
    最近更新 更多