duanhuihui2705 2018-09-11 09:55
浏览 1025
已采纳

golang中的math.Pow是否适合此公式?

Formula:

C1*B+C2B^2+C3*G+C4*G*B+C5*G*B^2+C6*G^2+
C7*G^2*B+C8*R+C9*R*B+C10*R*B^2+C11*R*G+
C12*R*G*B+C13*R*G^2+C14*R^2+C15*R^2*B+
C16*R^2*G+C17*1+C18*R^3+C19*G^3+C20*B^3

Go:

var C1 = -0.0343
var C2 = 0.4062
...snipped

C1*B + C2*math.Pow(B, 2) + C3*G + C4*G*B +
C5*G*math.Pow(B, 2) + C6*G*math.Pow(G, 2) +
C7*math.Pow(G, 2)*B + C8*R + C9*R*B +
C10*R*math.Pow(B, 2) + C11*R*G + C12*R*G*B +
C13*R*math.Pow(G, 2) + C14*math.Pow(R, 2) +
C15*math.Pow(R, 2)*B + C16*math.Pow(R, 2)*G +
C17*1 + C18*math.Pow(R, 3) + C19*math.Pow(G, 3) +
C20*math.Pow(B, 3)

All my code works, but I'm seeing values greater than 1 and I should be expecting values in the range of 0 to 1, so I'm assuming that math.Pow isn't what I should be using. New to Go, any help greatly appreciated.

  • 写回答

1条回答 默认 最新

  • duanpu1963 2018-09-11 10:10
    关注

    Your RGB values are not in the same range as the formula requires. This formula works with R, G and B components in the mathematically normal range of 0 (darkest) to 1 (brightest), not the usual computery range of 0 (darkest) to 255 (brightest).

    Divide RGB by 255.0 before running your formula.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大