将双精度列表规范化为范围-1到1或0-255 [英] normalizing a list of doubles to range -1 to 1 or 0 - 255

查看:284
本文介绍了将双精度列表规范化为范围-1到1或0-255的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 -1.396655 1.74707 之间的范围内的双精度的列表甚至可以更高下,任何一种方式我会知道 Min Max 值是在规范化之前。我的问题是如何规范这些值之间的 -1 1 或更好的将它们从双值转换char值 0 255



  double range =(double)(max  -  min); 
value = 255 *(value - min)/ range


解决方案>

最简单的事情是首先通过从每个数字中减去Min来移动所有的值,使得min为0。然后乘以255 /(Max-Min),使得移位的Max将被映射到255,并且一切将会线性缩放。所以我相信你的方程如下:



newval =(unsigned char)(oldval - Min)*(255 / Min)))



在转换为char之前,您可能要更仔细一些。


I have a list of doubles in the range of anywhere between -1.396655 to 1.74707 could even be higher or lower, either way I would know what the Min and Max value is before normalizing. My question is How can I normalize these values between -1 to 1 or even better yet convert them from double values to char values of 0 to 255

Any help would be appreciated.

double range = (double)(max - min);
value = 255 * (value - min)/range

解决方案

The easiest thing is to first shift all the values so that min is 0, by subtracting Min from each number. Then multiply by 255/(Max-Min), so that the shifted Max will get mapped to 255, and everything else will scale linearly. So I believe your equation would look like this:

newval = (unsigned char) ((oldval - Min)*(255/(Max-Min)))

You may want to round a bit more carefully before casting to char.

这篇关于将双精度列表规范化为范围-1到1或0-255的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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