本文整理汇总了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)))
//.........这里部分代码省略.........
示例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);
}
}