gpt4 book ai didi

java - 创建直方图

转载 作者:行者123 更新时间:2023-11-30 08:07:14 25 4
gpt4 key购买 nike

对于一项作业,我得到了可怕的指示,我无法遵循,而且我的教授处理电子邮件的速度很慢,所以我想我会在这里得到更好的回复。

最初的目标是使用公式 {r,g} = {R,G}/(R+G+B) 将正常颜色 RGB 转换为色度。然后我们要创建一个以 r 和 g 为轴的直方图。 bin 的数量应等于 1 + log2(n),其中 n = 行数

这怎么可能?假设我们有一个 4x4 的数组,我们必须将其创建为 3x3 矩阵的直方图,这不会均匀划分,我们会遇到问题...

以下是项目规范:

It turns out that we also know that if we replace the colour, RGB, by the chromaticity {r, g} = {R, G}/(R + G + B) then the image is much more characteristic of the surfaces being imaged, rather than of the light illuminating those surfaces. So, instead of colour, {R, G, B}, let’s use chromaticity, {r, g}. [But watch out for black, i.e., {R, G, B}={0, 0, 0}, pixels.]

The nice thing about chromaticity is that it’s 2D. So our histogram is a 2D array, with r along one axis and g along another. The chromaticity is necessarily in the interval [0, 1]. But how many bins along each axis should we use? Applying (a cheap version of) a rule of thumb called Sturges’s Rule, the number of bins N = 1 + log2(n), where n=size of data, so a rough idea is to use n = number of rows, so e.g. N = 7 bins along each of the r and g directions. That makes our histogram, H, a small, 7 × 7 array of integer values. If we normalize to make the sum of H equal unity, then we have an array of floats.

要求任何人做这项工作,我只是要求澄清是否有人知道如何做到这一点。

目前我可以获得色度值:

       for(int i= 0; i < 1280; i++) {
for(int j = 0; j < 720; j++) {
rgb = resTemp.getRGB(i, j);

R = (rgb >> 16) & 0xFF;
G = (rgb >> 8) & 0xFF;
B = (rgb) & 0xFF;

r = R/(R+G+B);
g = G/(R+G+B);
b = B/(R+G+B);

}
}

最佳答案

你有一个 2D 色度值在 0..1, 0..1 范围内

r = R/(R+G+B);
g = G/(R+G+B);

这意味着对于每个像素,您都有一个 2d 值,您可以将其放置在这个连续空间的某处

^ R
|(1,0)
|
|(0,0) (0,1) G
|----------->

如果您以 2x2 的方式将其分箱,您会将每个分配到一个分箱,例如

R
^
|-------|------|
| bin | bin |
| | |
|-------|------|
| bin | bin |
| | |
|-------|------|>G

例如[0.3, 0.2] 的值进入左下角。 [0.9, 0.9] 进入右上角。您也可以将其制作成更精细的 7x7 网格。

现在您遍历所有 [r,g] 值并计算有多少值进入哪个 bin。结果可能是这样的

  30  |  12
------------
4 | 12

这是直方图H。

现在您可以通过将值转换为百分比来对其进行标准化。这是通过除以总数来完成的。例如。 30/(30+12+4+12) 第一个。最终结果是一个 float 数组。

  0.5 |  0.2
------------
0.0 | 0.2

关于java - 创建直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com