过滤后如何处理负像素值? [英] How do you handle negative pixel values after filtering?

查看:211
本文介绍了过滤后如何处理负像素值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个8位图像,我想用一个矩阵对其进行过滤以进行边缘检测.我的内核矩阵是

I have a 8-bit image and I want to filter it with a matrix for edge detection. My kernel matrix is

0  1  0
1 -4  1
0  1  0

对于某些索引,它给我一个负值.我应该和他们在一起吗?

For some indices it gives me a negative value. What am I supposed to with them?

推荐答案

您的内核是Laplace过滤器.将其应用于图像可得出拉普拉斯算子的有限差分近似值. 拉普拉斯算子本身并不是边缘检测器.

Your kernel is a Laplace filter. Applying it to an image yields a finite difference approximation to the Laplacian operator. The Laplace operator is not an edge detector by itself.

但是您可以将其用作边缘检测器的构建块:您需要检测零交叉点以找到边缘(这是

But you can use it as a building block for an edge detector: you need to detect the zero crossings to find edges (this is the Marr-Hildreth edge detector). To find zero crossings, you need to have negative values.

您还可以使用经过Laplace过滤的图像来锐化图像.如果从原始图像中减去图像,则结果将是边缘更锐利,感觉更清晰的图像.为此,负值也很重要.

You can also use the Laplace filtered image to sharpen your image. If you subtract it from the original image, the result will be an image with sharper edges and a much crisper feel. For this, negative values are important too.

对于这两个应用程序,如另一个答案中所建议的那样,钳制运算结果是错误的.夹紧会将所有负值都设置为0.这意味着不再有零交叉点,因此您找不到边缘,而进行锐化则意味着每个边缘的一侧都不会被锐化.

For both these applications, clamping the result of the operation, as suggested in the other answer, is wrong. That clamping sets all negative values to 0. This means there are no more zero crossings to find, so you can't find edges, and for the sharpening it means that one side of each edge will not be sharpened.

因此,处理Laplace过滤器的结果最好的做法是保留这些值.使用带符号的16位整数类型存储结果(实际上,我更喜欢使用浮点类型,这样可以简化很多事情).

So, the best thing to do with the result of the Laplace filter is preserve the values as they are. Use a signed 16-bit integer type to store your results (I actually prefer using floating-point types, it simplifies a lot of things).

另一方面,如果要将Laplace滤镜的结果显示在屏幕上,则必须对像素值做一些有意义的事情.在这种情况下,常见的做法是为每个像素添加128.这会将零值移至中间灰色值,将负值显示为较暗,将正值显示为较亮.加128后,可以裁剪大于255且小于0的值.如果要避免剪切,也可以进一步拉伸值,例如laplace / 2 + 128.

On the other hand, if you want to display the result of the Laplace filter to a screen, you will have to do something sensical with the pixel values. Common in this case is to add 128 to each pixel. This shifts the zero to a mid-grey value, shows negative values as darker, and positive values as lighter. After adding 128, values above 255 and below 0 can be clipped. You can also further stretch the values if you want to avoid clipping, for example laplace / 2 + 128.

这篇关于过滤后如何处理负像素值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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