如何使用EmguCV和C#绘制直方图 [英] How to draw histogram using EmguCV and C#

查看:2625
本文介绍了如何使用EmguCV和C#绘制直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画两种直方图,即单维和立体。
我是一个新手,EMGU和所有我在网上找到的样品是用C ++或C是否有使用C#和Emgucv?



<任何样本p >感谢您的帮助。


解决方案

将下面的代码段中的红,绿,蓝直方图数据,并把它们放在float数组不管什么用你想要的。

 浮动[] BlueHist; 
浮法[] GreenHist;
浮法[] RedHist;

形象和LT; BGR,字节> IMG =新的图像< BGR,字节>(映像文件名称);

DenseHistogram组织相容=新DenseHistogram(255,新RangeF(0,255));

形象和LT;灰色,字节> img2Blue = IMG [0];
形象和LT;灰色,字节> img2Green = IMG [1];
形象和LT;灰色,字节> img2Red = IMG [2];


Histo.Calculate(新图片<灰色,字节> [] {} img2Blue,真实,NULL);
//数据是在这里
//Histo.MatND.ManagedArray
BlueHist =新的浮动[256];
Histo.MatND.ManagedArray.CopyTo(BlueHist,0);

Histo.Clear();

Histo.Calculate(新图片<灰色,字节> [] {} img2Green,真实,NULL);
GreenHist =新的浮动[256];
Histo.MatND.ManagedArray.CopyTo(GreenHist,0);

Histo.Clear();

Histo.Calculate(新图片<灰色,字节> [] {} img2Red,真实,NULL);
RedHist =新的浮动[256];
Histo.MatND.ManagedArray.CopyTo(RedHist,0);

和这会做的灰度直方图:

 浮动[] GrayHist; 

形象和LT;灰色,字节> img_gray =新的图像<灰色,字节>(映像文件名称);

Histo.Calculate(新图片<灰色,字节> [] {} img_gray,真实,NULL);
//数据是在这里
//Histo.MatND.ManagedArray
GrayHist =新的浮动[256];
Histo.MatND.ManagedArray.CopyTo(GrayHist,0);



希望这有助于



干杯,



克里斯





要绘制柱状图,你将需要使用要么你自己或设计的控制,如Zedgraph(这是提供与EMGU)这里是CodeProject上的一篇很好的文章,显示它的使用。



http://www.codeproject.com/KB/graphics/zedgraph.aspx



干杯



克里斯


I need to draw two types of histogram, namely monodimensional and tridimensional. I'm a newbie to EMGU and all of the samples I found on the net are in C++ or C. Are there any samples using C# and Emgucv?

Thanks for helping.

解决方案

The following code will segment the RED GREEN and BLUE Histogram data and put them in an array of floats for whatever use you want.

float[] BlueHist;
float[] GreenHist;
float[] RedHist;

Image<Bgr, Byte> img = new Image<Bgr, byte>("ImageFileName");

DenseHistogram Histo = new DenseHistogram(255, new RangeF(0, 255));

Image<Gray, Byte> img2Blue = img[0];
Image<Gray, Byte> img2Green = img[1];
Image<Gray, Byte> img2Red = img[2];


Histo.Calculate(new Image<Gray, Byte>[] { img2Blue }, true, null);
//The data is here
//Histo.MatND.ManagedArray
BlueHist = new float[256];
Histo.MatND.ManagedArray.CopyTo(BlueHist, 0);

Histo.Clear();

Histo.Calculate(new Image<Gray, Byte>[] { img2Green }, true, null);
GreenHist = new float[256];
Histo.MatND.ManagedArray.CopyTo(GreenHist, 0);

Histo.Clear();

Histo.Calculate(new Image<Gray, Byte>[] { img2Red }, true, null);
RedHist = new float[256];
Histo.MatND.ManagedArray.CopyTo(RedHist, 0);

and this will do the greyscale histogram:

float[] GrayHist;

Image<Gray, Byte> img_gray = new Image<Gray, byte>("ImageFileName");

Histo.Calculate(new Image<Gray, Byte>[] { img_gray }, true, null);
//The data is here
//Histo.MatND.ManagedArray
GrayHist = new float[256];
Histo.MatND.ManagedArray.CopyTo(GrayHist, 0);

Hope this helps,

Cheers,

Chris

[Edit]

To draw the histogram you will need to use either you own or a designed controls such as Zedgraph (This is supplied with with EMGU) here is a very good article on codeproject that shows it's use.

http://www.codeproject.com/KB/graphics/zedgraph.aspx

Cheers

Chris

这篇关于如何使用EmguCV和C#绘制直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆