简体   繁体   English

如何将OpenCV中的adaptiveThreshold用于大于255的值(即,类型CV_8UC1)?

[英]How to use adaptiveThreshold from OpenCV for values larger than 255 (i.e. type CV_8UC1)?

I want to use the adaptiveThreshold function from OpenCV in order to determine appropriate, local thresholds for values in a vector<double> . 我想使用OpenCV中的adaptiveThreshold函数,以便为vector<double>值确定适当的局部阈值。

adaptiveThreshold is specified in the docs as follows: adaptiveThreshold值在文档中指定如下:

void adaptiveThreshold(InputArray src, OutputArray dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C)

Note that src has to be a Source 8-bit single-channel image (so the input needs to be of type CV_8UC1 if I understand correctly, please correct me if I'm wrong here...). 请注意, src必须是一个8位源单通道图像 (因此,如果我理解正确,则输入的类型必须为CV_8UC1 ,如果在这里输入错误,请更正我...)。

Since my vector<double> is not of type CV_8UC1 , one way to approach this would be to normalize the values within a range of 0 and 255 and then feed the resulting normalized values as a vector<unsigned char> into the adaptiveThreshold function. 由于我的vector<double>的类型不是CV_8UC1 ,解决该问题的一种方法是将0255范围内的值归一化,然后将所得的归一化值作为vector<unsigned char>馈入adaptiveThreshold函数。

This might look good at first sight, but it comes with a large loss of precision as the values within my original vector<double> grow very large and get normalized down to the range of 0 to 255 . 乍一看可能看起来不错,但是由于我的原始vector<double>的值变得非常大并标准化到0255的范围时,它会带来很大的精度损失。

So, I am wondering if there isn't an option to use the adaptiveThreshold function for a wider range of values. 因此,我想知道是否没有选择将adaptiveThreshold阈值函数用于更广泛的值。 It seems so unlogical to me that it should only work with values with a max of 255 ... It feels like I oversee something quite simple but I can't figure out how to solve the issue... 对我来说似乎很不合逻辑,它只能与最多255值一起使用...感觉好像我监督了一些非常简单的事情,但是我不知道该如何解决这个问题...

I'm afraid there isn't such an option for a wider range of values. 恐怕无法提供更广泛的价值选择。 But it is fairly easy to derive a version that takes 'double' values as OpenCV is open source. 但是,由于OpenCV是开源的,因此导出带有“双”值的版本相当容易。 Just find the source code of adaptiveThreshold() and change it for your own use. 只需找到adaptiveThreshold()的源代码并更改以供您自己使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM