如何计算C#中图像的渐变? [英] How to calculate Gradient of an image in C# ?

查看:92
本文介绍了如何计算C#中图像的渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii ..





我想知道如何使用任何过滤器计算c#中图像的渐变。请帮助我。

Hii..


I want to know how to calculate gradient of an image in c# using any filter. Please help me.

推荐答案

这可以通过使用Sobel功能的OpenCV来完成。



http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/ sobel_derivatives / sobel_derivatives.html #sobel-derivatives [ ^ ]



OpenCV有一些C#包装器,例如:



http://www.emgu.com/wiki/index.php/Main_Page [ ^ ]



我采取SA的观点并加上:



http://en.wiki pedia.org/wiki/Image_gradient [ ^ ]
This can be done with OpenCV using the Sobel function.

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html#sobel-derivatives[^]

OpenCV has a number C# wrappers available for example:

http://www.emgu.com/wiki/index.php/Main_Page[^]

I take SA's point and add this:

http://en.wikipedia.org/wiki/Image_gradient[^]


请看我对这个问题的评论。



这是问题:即使你可以用任何预定义的渐变创建一个图像,很容易,你通常不会问一个问题给定图像的梯度是什么?。需要一些了解,梯度是什么。渐变不能是图像的属性。它是函数域的某个给定点的某类函数(可微分至少在某些点上)的属性。在图像的情况下,这是一个给定位置的属性。而且,这种财产可能存在也可能不存在。首先,位图图像是离散,它们只能被视为某些平滑函数的近似,并且仅在图像的某些点附近,而不是在任意位置。


要定义这样的近似梯度,你需要一些平滑的颜色变化功能是某些点(比如不是一个像素)的一些相当大的附近。在此附近,您可以通过像素颜色的插值来构建一些平滑函数。此功能可以在两个方向上具有颜色的一些偏导数。你应该找出导数最大的方向。获得的矢量将是点中的梯度。当然,在某些其他方面,渐变会有所不同。在对比鲜明的点上,渐变的概念应该被视为没有真正的意义。



这里有很好的解释,对于图像也是如此: http://en.wikipedia.org/wiki/Gradient [ ^ ]。



从显示的等式中,它不是开发用于计算给定点中的梯度的算法太困难了。它基本上简化为某些点附近离散点的偏导数的简单任务。



注意这个首先,特别是本文中的第三张图片。它们说明了无法定义图像渐变的情况,因为它对于图像的每个点都是不同的。你可以谈论图像的渐变的情况只是第二张图片,它恰好在整个图像上都有均匀的渐变。



- SA
Please see my comment to the question.

Here is the problem: even though you can create an image with any predefined gradient, easily, you cannot generally ask a question "what is a gradient of a given image?". It takes some understanding, what a gradient is. A gradient cannot be a property of an image. It is a property of some class of functions (differentiable at least in some points) at some given point of the function domain. In case of images, this is a property of one given location. Moreover, such property may or may not exist. First of all, the bitmap images are discrete, they can be considered only as approximation of some smooth functions, and only in the vicinities of some points of the image, not at any arbitrary location.

To have such approximate gradient defined, you need some smooth function of color change is some reasonably big vicinity of some point (say, not one pixel). In this vicinity, you can build some smooth function by interpolation of pixels colors. This function can have some partial derivatives of the colors on two directions. You should find out the direction where the derivative is maximum. The obtained vector will be the gradient in the point. Naturally, in some other point the gradient will be different. And in the points of sharp contrast, the notion of gradient should be considered as not making real sense.

This is pretty well explained here, and for the images, too: http://en.wikipedia.org/wiki/Gradient[^].

From the equations shown, it's not too difficult to develop the algorithm for calculation of the gradient in a given point. It's basically reduced to the simple task of numeric computation of partial derivatives by the discrete points in some point's vicinity.

Pay attention for the very first and especially the third picture in this article. They illustrate the cases when the gradient for the image cannot be defined, as it is different for every point of the image. The case when you could talk about "gradient of the image" is only the second picture, which happens to have uniform gradient оver the whole image.

—SA


我对解决方案1的补充:​​



在我的评论中,我解释了为什么这是不是解决方案,但这是你的错,而不是普瓦瑟的错。



要了解Sobel运营商,请参阅: http:// en .wikipedia.org / wiki / Sobel_operator [ ^ ] 。



请参阅我对解决方案2中问题的解释。



实际上,问题是如何使用OpenCV与.NET。一个明显的解决方案是:使用名为Emgu CV的.NET包装器:

http:// www.emgu.com/wiki/index.php/Main_Page [ ^ ]。



-SA
My addition to the Solution 1:

In my comment to it, I explain why this is not the solution, but this is rather your fault than the fault of pwasser.

To understand the Sobel operator, please see: http://en.wikipedia.org/wiki/Sobel_operator[^].

Refer to my explanations of the problem in Solution 2.

Practically, the issue is how to use the OpenCV with .NET. One apparent solution is: use the .NET wrapper called Emgu CV:
http://www.emgu.com/wiki/index.php/Main_Page[^].

—SA


这篇关于如何计算C#中图像的渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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