本文介绍了为像素指定负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用某些标准,图像中有一些我不感兴趣的像素。所以,我想忽略它们。我只是想问一下我所遵循的方法是否可以接受。我已经为这些像素分配了一个负值。这可以接受吗?而且,当像素具有负值时,它意味着什么?它会在图像上有一些表示吗?

Using some criterion, there are some pixels in the image which I'm not interested in. So, I would like to neglect them. I just want to ask if the approach I have followed is acceptable. I have assigned such pixels a negative value. Would that be acceptable? And, what does it mean when a pixel has a negative value? Will it have some representation on the image?

推荐答案

如果您的数据类型允许它,如有符号整数(CV_32S)或浮点数(CV_32F或CV_64F),使用负值非常有意义,这是一种指定忽略像素的常用方法。在这种情况下,除了对它的解释之外,对负值没有特殊含义。

If your data type allows it, like signed integer (CV_32S) or floating point (CV_32F or CV_64F), it makes perfect sense to use negative values and it is a very common way to specify ignored pixels. In this case there is no special meaning to a negative value except your interpretation of it.

另一方面,如果你使用8位无符号图像(CV_8U),这可能会导致错误:它可能被截断为零或转换为[0,255] ]使用modulo-256添加,具体取决于您的opencv版本。在最坏的情况下,如果以非常糟糕的方式访问像素数据,它也可能溢出到邻居像素并修改它们的值。因此,如果使用8位图像,则应该使用掩码来指定忽略的像素,如phyrox所述。

On the other hand, if you use 8-bit unsigned images (CV_8U), this may lead to errors : it may either be truncated to zero or converted to [0,255] using modulo-256 addition, depending on your version of opencv. In the worst case, it may also overflow to neighbor pixels and modify their values, if you access pixel data in a very bad way. So if you work with 8-bit images, you should rather use a mask to specify ignored pixels, as phyrox explained.

这篇关于为像素指定负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:53