当前位置: 首页>>代码示例>>C#>>正文


C# IImage.MinMax方法代码示例

本文整理汇总了C#中IImage.MinMax方法的典型用法代码示例。如果您正苦于以下问题:C# IImage.MinMax方法的具体用法?C# IImage.MinMax怎么用?C# IImage.MinMax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IImage的用法示例。


在下文中一共展示了IImage.MinMax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateHistograms

      /// <summary>
      /// Generate histograms for the image. One histogram is generated for each color channel.
      /// You will need to call the Refresh function to do the painting afterward.
      /// </summary>
      /// <param name="image">The image to generate histogram from</param>
      /// <param name="numberOfBins">The number of bins for each histogram</param>
      public void GenerateHistograms(IImage image, int numberOfBins)
      {
         Mat[] channels = new Mat[image.NumberOfChannels];
         Type imageType; 
         if ((imageType = Toolbox.GetBaseType(image.GetType(), "Image`2")) != null 
            || (imageType = Toolbox.GetBaseType(image.GetType(), "Mat")) != null)
         {
            for (int i = 0; i < image.NumberOfChannels; i++)
            {
               Mat channel = new Mat();
               CvInvoke.ExtractChannel(image, channel, i);
               channels[i] = channel;
            }
             
         }
         else if ((imageType = Toolbox.GetBaseType(image.GetType(), "CudaImage`2")) != null)
         {
            IImage img = imageType.GetMethod("ToImage").Invoke(image, null) as IImage;
            for (int i = 0; i < img.NumberOfChannels; i++)
            {
               Mat channel = new Mat();
               CvInvoke.ExtractChannel(img, channel, i);
               channels[i] = channel;
            }
         }
         else
         {
            throw new ArgumentException(String.Format("The input image type of {0} is not supported", image.GetType().ToString()));
         }

         Type[] genericArguments = imageType.GetGenericArguments();
         String[] channelNames;
         Color[] colors;
         Type typeOfDepth;
         if (genericArguments.Length > 0)
         {
            IColor typeOfColor = Activator.CreateInstance(genericArguments[0]) as IColor;
            channelNames = Reflection.ReflectColorType.GetNamesOfChannels(typeOfColor);
            colors = Reflection.ReflectColorType.GetDisplayColorOfChannels(typeOfColor);
            typeOfDepth = imageType.GetGenericArguments()[1];
         }
         else
         {
            channelNames = new String[image.NumberOfChannels];
            colors = new Color[image.NumberOfChannels];
            for (int i = 0; i < image.NumberOfChannels; i++)
            {
               channelNames[i] = String.Format("Channel {0}", i);
               colors[i] = Color.Red;
            }

            if (image is Mat)
            {
               typeOfDepth = CvInvoke.GetDepthType(((Mat)image).Depth);
            }
            else
            {
               throw new ArgumentException(String.Format("Unable to get the type of depth from image of type {0}", image.GetType().ToString()));
            }
            
         }
         
         float minVal, maxVal;
         #region Get the maximum and minimum color intensity values
         
         if (typeOfDepth == typeof(Byte))
         {
            minVal = 0.0f;
            maxVal = 256.0f;
         }
         else
         {
            #region obtain the maximum and minimum color value
            double[] minValues, maxValues;
            Point[] minLocations, maxLocations;
            image.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

            double min = minValues[0], max = maxValues[0];
            for (int i = 1; i < minValues.Length; i++)
            {
               if (minValues[i] < min) min = minValues[i];
               if (maxValues[i] > max) max = maxValues[i];
            }
            #endregion

            minVal = (float)min;
            maxVal = (float)max;
         }
         #endregion

         for (int i = 0; i < channels.Length; i++)
         {
            
            //using (DenseHistogram hist = new DenseHistogram(numberOfBins, new RangeF(minVal, maxVal)))
//.........这里部分代码省略.........
开发者ID:reidblomquist,项目名称:emgucv,代码行数:101,代码来源:HistogramBox.cs

示例2: GenerateHistograms

        /// <summary>
        /// Generate histograms for the image. One histogram is generated for each color channel.
        /// You will need to call the Refresh function to do the painting afterward.
        /// </summary>
        /// <param name="image">The image to generate histogram from</param>
        /// <param name="numberOfBins">The number of bins for each histogram</param>
        public void GenerateHistograms(IImage image, int numberOfBins)
        {
            IImage[] channels = image.Split();
             Type imageType = Toolbox.GetBaseType(image.GetType(), "Image`2");
             IColor typeOfColor = Activator.CreateInstance(imageType.GetGenericArguments()[0]) as IColor;
             String[] channelNames = Reflection.ReflectColorType.GetNamesOfChannels(typeOfColor);
             Color[] colors = Reflection.ReflectColorType.GetDisplayColorOfChannels(typeOfColor);

             float minVal, maxVal;
             #region Get the maximum and minimum color intensity values
             Type typeOfDepth = imageType.GetGenericArguments()[1];
             if (typeOfDepth == typeof(Byte))
             {
            minVal = 0.0f;
            maxVal = 256.0f;
             }
             else
             {
            #region obtain the maximum and minimum color value
            double[] minValues, maxValues;
            Point[] minLocations, maxLocations;
            image.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

            double min = minValues[0], max = maxValues[0];
            for (int i = 1; i < minValues.Length; i++)
            {
               if (minValues[i] < min) min = minValues[i];
               if (maxValues[i] > max) max = maxValues[i];
            }
            #endregion

            minVal = (float)min;
            maxVal = (float)max;
             }
             #endregion

             for (int i = 0; i < channels.Length; i++)
            using (DenseHistogram hist = new DenseHistogram(numberOfBins, new RangeF(minVal, maxVal)))
            {
               hist.Calculate(new IImage[1] { channels[i] }, true, null);
               AddHistogram(channelNames[i], colors[i], hist);
            }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:49,代码来源:HistogramBox.cs


注:本文中的IImage.MinMax方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。