如何在c#,。net中绘制累积直方图曲线? [英] How do I draw the cumulative histogram curve in c# ,.net?
问题描述
我设法通过参考以下链接绘制直方图
http://trompelecode.com/blog/2012/04/how-to- create-a-image-histogram-using-csharp-and-wpf /
我绘制输入直方图和输出直方图,即执行图像增强操作后
现在我想绘制累积直方图曲线,显示原始图像像素的差异以及像图像增强操作后的b / b
调整后的像素变化...
我推荐以下链接
http://azzlsoft.com/tag/histogram-equalization/ link
在以下代码片段中面临问题
for(int pixelIndex = 0;
pixelIndex<灰度.Pixels.Length;
pixelIndex ++)
{
字节强度=(字节)(grayscale.Pixels [pixelIndex]&0xFF);
histogramData [烈度] ++;
}
我没有获得强度y值为writablebitmap灰度未查找。像素[pixelIndex]方法
提前感谢.... Smile | :)
Hi,
I managed to draw the histogram by referring the following link
http://trompelecode.com/blog/2012/04/how-to-create-an-image-histogram-using-csharp-and-wpf/
I drawn input histogram and output histogram i.e after performing the image enhancement operations
Now I want to plot cumulative histogram curve showing the difference in original image pixel and change in pixel after
adjustments like image enhancement operations...
I am referrring following link
http://azzlsoft.com/tag/histogram-equalization/ link
facing problem in the follow code snippet
for (int pixelIndex = 0;
pixelIndex < grayscale.Pixels.Length;
pixelIndex++)
{
byte intensity = (byte)(grayscale.Pixels[pixelIndex] & 0xFF) ;
histogramData[intensity]++;
}
I am not getting the intensity value as writablebitmap grayscale not finding .Pixels[pixelIndex] methode
thanks in advance.... Smile | :)
推荐答案
好吧,如果您正在处理图像,像素的强度值将具有一定的频率。
10像素将强度值设为0,25像素值为1等。
累积频率是先前频率的总和,包括当前强度
>
所以你会有这样一个表:
强度 频率 累积频率 计算 0 10 10 0 + 10 1 25 35 10 + 25 2 30 65 35 + 30 < td> 3 35 100 65 + 35 4 30 130 100 + 30 等。
Well, if you are working on an image the intensity values for the pixels will have a certain frequency.
10 pixels will have the intensity value of 0, 25 pixels the value of 1, etc.
The cumulative frequency is the sum of the previous frequencies including the current intensity
So you will have a table like this:
Intensity Frequency Cumulative Frequency Calculation 0 10 10 0 + 10 1 25 35 10 + 25 2 30 65 35 + 30 3 35 100 65 + 35 4 30 130 100 + 30 etc.
int [] histogramData = new int [256];
WriteableBitmap writeableBmp;
System.Drawing.Bitmap位图;
使用(MemoryStream outStream = new MemoryStream())
{
writeableBmp = new writeableBitmap(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions()));
}
int [] a = new int [img.Width * img.Height];
for(int pixelIndex = 1; pixelIndex< 256; pixelIndex ++)
{
writeableBmp.CopyPixels(a,1680,pixelIndex);
}
for(int pixelIndex = 1; pixelIndex< img.Width * img.Height; pixelIndex ++)
{
字节强度=(字节)(a.ElementAt(pixelIndex)&0xFF);
histogramData [烈度] ++;
}
< br $>
for(int intensity = 1; strength< 256; intensity ++)
{
//现在我们只需将当前概率
//添加到上一个CDF
cumulativeDistributionFunction [intensity] =((histogramData [intensity])/ img.Width * img.Height)+ cumulativeDistributionFunction [强度 - 1];
}
//曲线= cumulativeDistributionFunction;
cur ve = ConvertToPointCollection(cumulativeDistributionFunction);
int[] histogramData = new int[256];
WriteableBitmap writeableBmp;
System.Drawing.Bitmap bitmap;
using (MemoryStream outStream = new MemoryStream())
{
writeableBmp = new writeableBitmap(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions()));
}
int[] a = new int[img.Width * img.Height];
for (int pixelIndex = 1; pixelIndex < 256; pixelIndex++)
{
writeableBmp.CopyPixels(a, 1680, pixelIndex);
}
for (int pixelIndex = 1; pixelIndex < img.Width * img.Height; pixelIndex++)
{
byte intensity = (byte)(a.ElementAt(pixelIndex) & 0xFF);
histogramData[intensity]++;
}
for (int intensity = 1; intensity < 256; intensity++)
{
//now we just add the current probability
//to the previous CDF
cumulativeDistributionFunction[intensity] = ((histogramData[intensity]) / img.Width * img.Height) + cumulativeDistributionFunction[intensity - 1];
}
//curve = cumulativeDistributionFunction;
curve = ConvertToPointCollection(cumulativeDistributionFunction);
这篇关于如何在c#,。net中绘制累积直方图曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!