【发布时间】:2019-03-25 06:15:09
【问题描述】:
我正在 Android Studio 中处理位图图像,并且我知道如何检测所有红色像素作为示例,但不仅仅是严格等于 Color.RED 的像素。我只是举一个红色的例子,但我想用所有不同的颜色来做。
I tried to do this:
...
int[] pixels = new int[width * height];
myBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < width * height; i++) {
if (pixels[i] == Color.RED) {
// color detected
}
...
但这不起作用,因为我的图像不包含 (255, 0, 0) 的红色像素,但包含可能是 (251, 30, 77) 或 (239, 23, 42) 的像素,即还有“红色”等……
那么我怎么能对这样的事情做呢?我也尝试过类似的东西:
int reference; // color as rgb
if ( (Color.red(pixels[i]) > Color.red(reference) - 20) &&
(Color.red(pixels[i]) < Color.red(reference) + 20 &&
...
{
// pixel detected
}
...
我认为 (r +- 20, g +- 20, b +-20) 是 (r, g, b) 的一部分(我的意思是,对于人眼)
知道我该怎么做吗?
【问题讨论】:
-
要获得两种颜色的相似度,您可以计算它们之间的欧几里得距离。
-
你可以在这里找到一些关于配色的讨论和简单的方法-stackoverflow.com/questions/27374550/…
-
考虑转换为 H1/HSV 颜色空间 en.wikipedia.org/wiki/HSL_and_HSV 并找到色相
标签: java android image-processing colors bitmap